Performance drop when using Channels 2 with WhitenoiseMiddleware
See original GitHub issueI’ve just upgraded my Django project’s Channels from 1.x to 2.x (there seems to be an issue with 1.x that it creates new session for every connection), replacing my wsgi application with an asgi one + all other changes required by docs.
After that, my response time for pure-html pages dropped from ~20ms to about 400ms. (I’ve tested on a real simple one, next to no db involved, no javascript evaluated)
I’ve fiddled with settings and found out that when I disable whitenoise.middleware.WhiteNoiseMiddleware , response times are back to normal. (both whitenoise==4.0 and whitenoise==3.3.1)
In Channels 1.x, inclusion / exclusion did not seem to make an impact (not measurable anyways).
I run the project using simple python manage.py runserver, but using daphne produces same results.
When I tried to add some logging to the middleware itself, it seems like the __call__ itself is not performing bad (around 10ms), but the performance drop is roughly dependent on number of static files.
I’m still in process of stripping my project to some bare version that I’m able to send (it’s rather big now).
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)

Top Related StackOverflow Question
Yeah, that’s not the right approach - instead, the BaseHandler’s load_middleware method needs overloading so that it caches the loaded middleware on the class rather than the instance.
@majgaard Hi, unfortunately I do not have the branch at the ready now to test, but it did behave according to what you say – the the response rate was slowed down proportionately to number of static resources. Eg. if whitenoise check those on
__init__it is most likely the cause.