How can you limit memory in Django WSGI applications?

I want my application to MemoryError when its use exceeds 1 GB. I work in the WSGI daemon mode.

I see 3 places where there may be a memory limit:

  • apache.conf
  • wsgi somewhere
  • Django configuration

but I can not find the correct configuration options. In PHP, you can do this with:

php_value memory_limit 1GB

in apache.conf

+6
memory-management django memory apache mod-wsgi
source share
2 answers

Resource memory limits are not implemented on most platforms, although API C definitions exist. Therefore, mod_wsgi does not attempt to implement such restrictions. If PHP does this, it can do this because it is a more limited and controlled environment than Python.

The only portable way is to start a separate daemon process that runs β€œps” or uses β€œ/ proc” to monitor the memory usage of processes, and then sends a SIGINT signal to those that pass some predefined value.


UPDATE

Version 3.4 of mod_wsgi supports daemon mode options that can limit memory usage. Cm:

Do they work depending on the operating system used.

+3
source share
+2
source share

All Articles