Recommended settings for uwsgi
Asked Answered
T

1

6

I have a mysql + django + uwsgi + nginx application and I recently had some issues with uwsgi's default configuration so I want to reconfigure it but I have no idea what the recommended values are.

Another problem is that I couldn't find the default settings that uwsgi uses and that makes debugging really hard.

Using the default configuration, the site was too slow under real traffic (too many requests stuck waiting for the uwsgi socket). So I used a configuration from some tutorial and it had cpu-affinity=1 and processes=4 which fixed the issue. The configuration also had limit-as=512 and now the app gets MemoryErrors so I guess 512MB is not enough.

My questions are:

  1. How can I tell what the recommended settings are? I don't need it to be super perfect, just to handle the traffic in a descent way and to not crash from memory errors etc. Specifically the recommended value for limit-as is what I need most right now.

  2. What are the default values of uwsgi's settings?

Thanks!

Towhee answered 16/6, 2017 at 13:56 Comment(2)
It's at times like these that you realise how awesome nginx documentation is. uWSGI server is not part of nginx, and for the other QA, I couldn't find the default values, either!Fugue
uwsgi --help|grep default gives a good clue. But honestly, uwsgi's defaults are quite sane. Focus on what is generating a problem and adjust that, like @renzop is saying.Illiterate
S
9

We run usually quite small applications... Rarely more than 2000 requests per minute. But anyway its is hard to compare different applications. Thats what we use on production:

Recommendation by the documentation

Haharakiri = 20 # respawn processes taking more than 20 seconds
limit-as = 256 # limit the project to 256 MB
max-requests = 5000 # respawn processes after serving 5000 requests
daemonize = /var/log/uwsgi/yourproject.log # background the process & log

uwsgi_conf.yml

processes: 4
threads: 4


# This part might be important too, that way you limit the log file to 200 MB and 
# rotate it once
log-maxsize : 200000000
log-backupname : /var/log/uwsgi/yourproject_backup.log

We use the following project for deployment and configuration of our django apps. (No documentation here sorry... Just used it internally)

https://github.com/iterativ/deployit/blob/ubuntu1604/deployit/fabrichelper/fabric_templates/uwsgi.yaml

How can you tell if you configured it correctly... ? Since it depends much on your application I would recommend to use some monitoring tools such as newrelic.com and analyse it.

Sydelle answered 19/6, 2017 at 22:50 Comment(3)
Thank you! Why limit-as=256? How do you know it's good for your app?Towhee
Honastly, i just took the default value to start with and then checked if it works. Monitor and measure what your app consumes. As with ever optimization start with default, measure, and then optimize if needed. Also found this. uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html If your process uses toomuch memory you should probably consider to perform the task in another process... (celery etc,)Sydelle
Or trim down the information you want. There's a strong relation between Django's memory usage and the use of select_related with field-heavy models. There certainly are cases where it's needed, and then you gotta bring your wallet for extra memory. But there's also plenty examples of "information cram", where we try to stick everything on a single page, that no human is going to read/use all.Illiterate

© 2022 - 2024 — McMap. All rights reserved.