Why is runserver/daphne so slow?

Published on Jan. 3, 2017, 10:59 a.m.

channels daphne django node node_modules react

(tl;dr) I installed django-channels and now my runserver command is very very slow. django-debug-toolbar was sort of the culprit (not really, because it was my own fault)

The problem

I've just started a new project using django-channels. Websockets + channels is incredibly powerful, but I noticed something strange: While running django in debug mode, the development server was incredibly slow (on the average of 60s-90s per response).

After a bit of digging, it seemed that django-debug-toolbar was to blame, so I started turning off different panels to see what was the problem. Long story short: the StaticFilesPanel was taking a long time to generate it's data?

Here's why

  1. I'm building a chat app using react, and it's in a django app named chat.
  2. I've organized my react app so that it's inside my django app's static directory, e.g. my_project/chat/static/my_react_chat
  3. As part of my front end development, I end up with a node_modules directory with lots and lots of stuff.
  4. In development, I'm using the default staticfiles finders which will happily search through all of your django app's directories looking for static files. This takes some time when you a billion gigs worth of node modules.
  5. Daphne's default timeout is 60s, and those static files finders take longer than that.

So, for the moment, I'll either disable the StaticFilesPanel while I'm working on my react app, or I'll just try to remember to blow away my node_modules directory when I don't need it.

I've probably not got my react development organized quite right when integrating with a django app, but I'm doing what makes sense to me. Perhaps I should see what everyone else is doing. ¯\_(ツ)_/¯

comments powered by Disqus