question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance drop when using Channels 2 with WhitenoiseMiddleware

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
andrewgodwincommented, Aug 28, 2018

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.

1reaction
OndrejSkalickacommented, Aug 27, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Channels render MiddlewareNotUsed unusable #1099 - GitHub
But I think that channels renders middleware - that should be r. ... Performance drop when using Channels 2 with WhitenoiseMiddleware #1121.
Read more >
Using WhiteNoise with Django
This guide walks you through setting up a Django project with WhiteNoise. In most cases it shouldn't take more than a couple of...
Read more >
Django Channels 2 poor performance and high CPU usage
I'm using Channels 2 to build a shared 3D model viewing tool, but I'm running into performance issues where Channels can't keep up...
Read more >
Static files serving issue using Django channels - Stack Overflow
Try upgrading your Django channels to 1.0.3 and whitenoise 3.3.0 the example you mentioned Is using an outdated version and some bug fixes ......
Read more >
WhiteNoise Documentation - Read the Docs
Radically simplified static file serving for Python web apps. With a couple of lines of config WhiteNoise allows your web app to serve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found