-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: position of white noise middleware #25857
Conversation
posthog/settings/web.py
Outdated
@@ -96,6 +96,7 @@ | |||
"django_structlog.middlewares.RequestMiddleware", | |||
"django_structlog.middlewares.CeleryMiddleware", | |||
"django.middleware.security.SecurityMiddleware", | |||
"whitenoise.middleware.WhiteNoiseMiddleware", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely put this behind ShortCircuitMiddleware, as otherwise you're loading this for every capture/decide endpoint hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropping it below the AllowIPMiddleware didn't seem to have an impact on response time (in my super scientific refreshing locally testing) so went below those two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more context than anyone else to know if this is a good call or not but in principle - sure?
see see https://posthoghelp.zendesk.com/agent/tickets/19227 where user is reporting slow asset load times through the managed reverse proxy
(i believe that) for some routes assets are loaded through a CDN. For others - including the managed reverse proxy - they are loaded by hitting the django web instances. in these cases we see consistently slow time to first byte (TTFB).
The whitenoise middleware docs (https://whitenoise.readthedocs.io/en/stable/django.html#enable-whitenoise) say its middleware should be high up in the list of middleware
we had a lot of middleware ahead of it, so we're running those middleware on requests for static assets
locally this change makes the request 60-100ms TTFB instead of 120-169ms TTFB
switching on whitenoise's build time compression makes that 30-60ms per request since we're not gzipping the assets on the fly but it is super slow to run the offline compression, so i'm not doing that here