1

I have a Django application for which I want to limit the resources used by uWSGI to 12288MB and processes (workers) to 6.

With 3 separate apps, I can limit each to 2 workers, and each worker to 2048MB of memory (limit-as), but I'd rather allow all 3 apps to share the same amount of resources (they're all related, and 1 is not more important than the other - they're only separate apps because they each use Python configurations). I don't want one app to get pounded, while the other 2 are sipping Mai Tais on the beach with 1.5GB of RAM sitting around and processor to take up.

My uWSGI conf looks like this:

--emperor /etc/uwsgi/apps-enabled
--disable-logging
--die-on-term
--master
--uid www-data
--gid www-data
--logto /var/log/uwsgi/emperor.log

Each app is akin to:

[uwsgi]
socket = /tmp/app-1.uwsgi.sock
workers = 2
threads = 40
limit-as = 2048
harakiri = 20
max-requests = 1600
plugins = python
module = myapp.wsgi
callable = application
venv = /var/www/myapp/deps/current/venv
chdir = /var/www/myapp/deps/current/repo/src
touch-reload = /var/www/myapp/uwsgi/reload
auto-procname = true
procname-prefix-spaced = myapp
vacuum = true
reload-mercy = 8

BTW (side-question), are all of those settings interchangeable? Like, can I add settings from an app to the main uWSGI conf (ones that are the same for all 3 apps), and likewise add things like log-to to specific apps - I wasn't sure if every setting was interchangeable like that.

orokusaki
  • 2,763
  • 4
  • 32
  • 43

1 Answers1

1

I strongly suggest you to use cgroups (linux-only) to manage that kind of isolation.

remove limit-as

and add

cgroup = /cgroup/app1

cgroup-opt = memory.limit_in_bytes=1067459584

More infos are here:

http://projects.unbit.it/uwsgi/wiki/UseCgroups

the only "downside" is that you need to run the emperor as root, and set uid and gid in each vassal

roberto
  • 1,827
  • 12
  • 8
  • Thanks roberto. Do you think Cgroups fit well in a situation where I have 16GB on the server (vs cheap cloud hosting with limited ram / CPU, which is what it seems Cgroups was designed for)? – orokusaki Dec 07 '12 at 19:47
  • generally giving a limit to each process on a server is always a good think (for both security and reliability), so the amount of memory on a server is irrelevant compared to the advantages of cgroups – roberto Dec 08 '12 at 08:37