A big Django project (7 years old):
Benchmarking:
[lazy] startup = 13 s memory = 903 MB first_query = 3747 ms
How does it work, exactly?
Default uWSGI configuration:
lazy = true
help: Set lazy mode (load apps in workers instead of master)
Let's disable it:
lazy = false
[lazy] startup = 13 s memory = 903 MB first_query = 3747 ms [prefork] startup = 132 s memory = 769 MB first_query = 85 ms
Without lazy, each worker loads the whole codebase post-fork. But it's ready for the first request.
import os DJANGO_WARMUP_URL = os.environ.get('DJANGO_WARMUP_URL') app = None def get_wsgi_application(): from django.core import wsgi global app app = wsgi.get_wsgi_application() if DJANGO_WARMUP_URL: warmup_django() return app
def warmup_django(): # Setup the whole wsgi standard headers we do not care about. env = make_warmup_wsgi_env() wsgiref.util.setup_testing_defaults(env) # Boot the app def start_response(status, response_headers, exc_info=None): assert status == "200 OK" return io.BytesIO() # Fake socket global app app(env, start_response) # Close connections before forking from django.db import connections for conn in connections.all(): conn.close()
[lazy] startup = 13 s memory = 903 MB first_query = 3747 ms [prefork] startup = 132 s memory = 769 MB first_query = 85 ms [prewarm] startup = 9 s memory = 316 MB first_query = 121 ms
NB: only 25 MB per extra worker!
Details online:
https://gist.github.com/rbarrois/044b2d9f7052a6542f7a3d79695d64c6
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |