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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
whitenoise's scantree slows down test suite performance #558
Comments
In my experience, it鈥檚 usual to not add whitenoise to middleware for unit test settings. |
Interesting, in that case, I little documentation would go a long way here. |
There鈥檚 an FAQ already on avoiding the full scan by enabling Any PRs to surface this information better are very welcome. But since this isn鈥檛 a new issue, I鈥檓 going to close it. |
I would not recommend this, the more drift you introduce between test and production environments, the greater the risk for uncaught errors in that gap. |
That鈥檚 not how I read / apply that principle 馃檪 Unit tests are for testing my code, as fast as possible. Test / prod environments are deployed servers. I validate waitress, whitenoise, dns, email sending, etc. thanks to this test environment, which is very close to prod. |
Hi @adamchainz, thanks for the prompt response. I am a bit puzzled, though. The docs day the feature defaults to the |
I鈥檓 not a huge expert, I just pattern-matched the problem to the one I鈥檝e seen before. New instances per test does sound like it will cause slowness, yes. Yes, Django forces If you have any ideas for improvements, please do open a PR. Perhaps we should reopen this issue too... |
Hi @adamchainz, I took a deep dive into the middleware life cycles in Django's test suite and pytest-django. I can confirm, each client will instantiate a new middleware. However, not on each call. See also: I opened a pull-request #562 with a test, that demonstrate the issue. The issue is resolved when the test doesn't fail. So, yes, @adamchainz, I think it's best to reopen the issue. I will see if I can't find the time to cook up a patch. Cheers! |
Great, thanks |
Python Version
3.12
Django Version
4.2
Package Version
5.3.0
Description
Hi there 馃憢 and happy 2024,
We are switching to service ESM, rather than bundling our dependencies. Mainly, because updating once dependency will invalidate the cache for a whole bundle.
While doing so, I noticed that our test suite drastically decreased in performance. The reason, whitenoise will scan the entire
STATIC_ROOT
directory on every single client request causing significant disk IO.That's bearable on a MacBook Pro with 1聽GB/s disk speed and a large disk cache. On an Ubuntu worker on GitHub actions, we saw a 10x performance decrease. Taking our 8 min. test suite to a crisp 80 minutes.
I would propose moving the
files
dictionary from the middleware instance to the module or the thread.The current implementation does not affect regular request service, since Middleware instances are not recycled. However, they are when you use a test client.
Until this is addressed, the only way I see to mitigate this behavior is to remove the middleware in your test suite:
Love your thoughts!
Cheers, Joe
The text was updated successfully, but these errors were encountered: