Django, python, mod_wsgi and Apache worker

I just switched from an apache routine to a worker and started running mod_wsgi in daemon mode. So far, so good. I have not experienced the maximum load yet, but the server seems more consistent, and we do not see that random requests take 2min, waiting for mod_wsgi response. The amount of memory decreased from 3.5G to 1G. That's cool. We work on the same VPS with 6G RAM. In this north there is one Django application, as well as a memcache instance to which we allocated 1G RAM. We have a separate MySql server.

Our application is cumbersome and, of course, can be optimized. We use NewRelic to troubleshoot some of the slower pages. I read a lot about mod_wsgi / apache optimization, but, like everyone else, I still have a few questions.

Our average application page load time is 650-750 ms. Many of our pages are in the 200 ms range, but we have several dogs that take 2-5 seconds. We get about 15-20 requests per second under normal loads and 30-40 requests per second during peaks, which can last 30-60 minutes.

Here is my apache config, working working mpm.

StartServers 10 MaxClients 400 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 

I started working with default values ​​(StatServers = 2 and MaxClients = 150), but our site slowed down with a minimal load. I guess it took a long time to deploy the servers as requests arrive. We serve 90% of our media with s3. The remaining 10% is served through Apache on our https pages or someone lazily points to our local server. At rated load, 15 workflows end up being created, so I think I should probably just set StartServers = 15? In this configuration, I assume that I have 15 workflows (which I can confirm with NewRelic) with 25 threads each (which I don’t know how to confirm, guessing 400/15).

My apache / mod_wsgi directives look like this:

 <VirtualHost *:80> # Some stuff WSGIDaemonProcess app1 user=http group=http processes=10 threads=20 WSGIProcessGroup app1 WSGIApplicationGroup app1 WSGIScriptAlias / /path/to/django.wsgi WSGIImportScript /path/to/django.wsgi process-group=app1 application-group=app1 # Some more stuff </VirtualHost> <VirtualHost *:443> # Some stuff WSGIDaemonProcess app1-ssl user=http group=http processes=2 threads=20 WSGIProcessGroup app1-ssl WSGIApplicationGroup app1-ssl WSGIScriptAlias / /path/to/django.wsgi WSGIImportScript /path/to/django.wsgi process-group=app1-ssl application-group=app1-ssl # Some more stuff </VirtualHost> 

Having another WSGIDaemonProcess / WSGIProcessGroup for the ssl side of my site, well, it's just not quite right. I am 100% sure that I’ve dropped something here. However, I allocated 200 + 40 threads for mod_wsgi to handle requests from Apache, leaving 160 threads to handle any media that should be delivered (via ssl or laziness that does not point to s3).

So, if we download the application above, can anyone suggest ways to improve the performance of my site? Do I have the correct ssl / mod_wsgi instructions? Where is Graham ?;)

+6
source share

Source: https://habr.com/ru/post/926325/


All Articles