Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does uWSGI start all processes at boot time?

Tags:

python

uwsgi

I have several apps running on uWSGI. Most of them grow in memory usage over time. I've always attributed this to a memory leak that I hadn't tracked down. But lately I've noticed that the growth is quite chunky. I'm wondering if each chunk correlates with a process being started.

Does uWSGI start all processes at boot time, or does it only start up a new one when there are enough requests coming in to make it necessary?

Here's an example config:

[uwsgi]
strict = true

wsgi-file = foo.py
callable = app

die-on-term = true

http-socket = :2345

master = true
enable-threads = true
thunder-lock = true
processes = 6
threads = 1

memory-report = true

update: this looks relevant: http://uwsgi-docs.readthedocs.org/en/latest/Cheaper.html

Does "worker" mean the same thing as "process" (answer seems to be yes)? If so then it seems like if I want the number to remain constant always, I should do:

cheaper = 6
cheaper-initial = 6
processes = 6
like image 808
John Bachir Avatar asked Apr 26 '16 15:04

John Bachir


1 Answers

Yes, uWSGI will start all processes (or workers - worker is an alias for process in uWSGI config) at boot time but it will depend on your application what will go from then. If application imports all modules at boot time, it should be fully loaded before first request, but if some modules are loaded on request time, each worker will be fully loaded only after first requests (assuming that any request will load all modules. If not, it will be fully loaded only after doing combination of requests that will load all of it).

But even after loading all modules, application memory usage won't be constant. There may be some logging, global variables, debug information etc accumulating on every request. If you're using any framework it is possible that it will save some data for debugging, statistics etc.

By default, cheaper is not enabled - that means uWSGI will spawn all workers at startup. If you want to use cheaper mode, you need to define at least cheaper parameter. More about usage of cheaper system you can find in documentation

There are many other systems built in uWSGI to control load based on requests amount. For example

  • uWSGI Legion subsystem
  • On demand vassals
  • Socket activation (with inetd/xinetd, with upstart, with systemd, with circus or mentioned above on demand vassals when running emperor mode)
  • Bloodlord mode
  • Zerg mode

If you're worried that uWSGI will take up too much resources, there are solutions for that too:

  • Running uWSGI in a Linux CGroup
  • Linux Namespaces
  • Or even running docker instances
like image 181
GwynBleidD Avatar answered Oct 18 '22 20:10

GwynBleidD