Skip to content
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

Update to new recommended Apache/mod_wsgi config #29

Closed
qris opened this issue Mar 21, 2014 · 2 comments
Closed

Update to new recommended Apache/mod_wsgi config #29

qris opened this issue Mar 21, 2014 · 2 comments

Comments

@qris
Copy link
Collaborator

qris commented Mar 21, 2014

We are currently using this mod_wsgi configuration as the default for new projects:

WSGIDaemonProcess {{ cookiecutter.project_name }} processes=2 threads=10

I think we should be using this instead:

WSGIDaemonProcess {{ cookiecutter.project_name }} processes=1 threads=10 maximum-requests=400 display-name='%{GROUP}' deadlock-timeout=30
WSGIApplicationGroup %{GLOBAL}

Rationale for the changes:

  • processes=1: I can't see any reason to use multiple processes when we have threads enabled. Using two processes eats twice as much memory and ensures that some state is not shared between processes (e.g. cached Site objects) which requires a manual restart of Apache.
  • maximum-requests=400 ensures that the WSGI daemon process is recycled regularly, freeing up any memory that it may have leaked.
  • display-name='%{GROUP}' allows us to identify the WSGI process(es) in the process list, differentiating them from normal Apache processes. They will appear as (wsgi:<project_name>) instead of /usr/sbin/httpd.
  • deadlock-timeout=30 enables the detection and breaking of deadlocks caused by extensions starting a long-running operation in native C code without releasing the Python GIL lock. Otherwise these will hang the whole WSGI process for a long time, perhaps forever.
  • WSGIApplicationGroup %{GLOBAL} causes all Python code to run in the first Python interpreter instead of a sub-interpreter, avoiding a deadlock with native extensions.

References for these recommendations:

@foobacca
Copy link
Collaborator

I'd agree with all these apart from maximum-requests - I removed that after it started causing issues.

I forget the details, but the note I made in commit c23d988 linked to http://stackoverflow.com/a/8131650/3189 which is by the author of mod_wsgi and recommends against using maximum-requests unless you know you have an issue. He makes a similar point here: https://groups.google.com/d/msg/modwsgi/efXYx-1t5ck/M3GF9xLTMsEJ

foobacca added a commit that referenced this issue Apr 2, 2014
See #29 for discussion about these defaults.
@foobacca
Copy link
Collaborator

foobacca commented Apr 2, 2014

I've added all there apart from maximum-requests - so closing this issue.

@foobacca foobacca closed this as completed Apr 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants