Represents a mule farm.
- name (str|unicode) – Farm alias.
- mule_numbers (int|list[int]) – Total mules on farm count, or a list of mule numbers.
Workers aka [working] processes.
set_basic_params(count=None, touch_reload=None, touch_chain_reload=None, zombie_reaper=None, limit_addr_space=None, limit_count=None, cpu_affinity=None)¶
- count (int) –
Spawn the specified number of workers (processes). Set the number of workers for preforking mode. This is the base for easy and safe concurrency in your app. More workers you add, more concurrent requests you can manage.
Each worker corresponds to a system process, so it consumes memory, choose carefully the right number. You can easily drop your system to its knees by setting a too high value.
workersto a ridiculously high number will not magically make your application web scale - quite the contrary.
- touch_reload (str|list) – Trigger reload of (and only) workers if the specified file is modified/touched.
- touch_chain_reload (str|list) –
Trigger chain workers reload on file touch. When in lazy/lazy_apps mode, you can simply destroy a worker to force it to reload the application code. A new reloading system named “chain reload”, allows you to reload one worker at time (opposed to the standard way where all of the workers are destroyed in bulk)
- zombie_reaper (bool) – Call waitpid(-1,…) after each request to get rid of zombies.
Enables reaper mode. After each request the server will call
waitpid(-1)to get rid of zombie processes. If you spawn subprocesses in your app and you happen to end up with zombie processes all over the place you can enable this option. (It really would be better if you could fix your application’s process spawning usage though.)
- limit_addr_space (int) – Limit process address space (vsz) (in megabytes)
Limits the address space usage of each uWSGI (worker) process using POSIX/UNIX
setrlimit(). For example,
limit-as 256will disallow uWSGI processes to grow over 256MB of address space. Address space is the virtual memory a process has access to. It does not correspond to physical memory. Read and understand this page before enabling this option: http://en.wikipedia.org/wiki/Virtual_memory
- limit_count (int) – Limit the number of spawnable processes.
- cpu_affinity (int) –
number of cores for each worker (Linux only) Set the number of cores (CPUs) to allocate to each worker process.
- 4 workers, 4 CPUs, affinity is 1,
- each worker is allocated one CPU.
- 4 workers, 2 CPUs, affinity is 1,
- workers get one CPU each (0; 1; 0; 1).
- 4 workers, 4 CPUs, affinity is 2,
- workers get two CPUs each in a round-robin fashion (0, 1; 2, 3; 0, 1; 2; 3).
- 8 workers, 4 CPUs, affinity is 3,
- workers get three CPUs each in a round-robin fashion (0, 1, 2; 3, 0, 1; 2, 3, 0; 1, 2, 3; 0, 1, 2; 3, 0, 1; 2, 3, 0; 1, 2, 3).
- count (int) –
Run the specified command as worker.
- command (str|unicode) –
- after_post_fork_hook (bool) – Whether to run it after post_fork hook.
Sets workers count.
By default sets it to detected number of available cores
Parameters: count (int) –
set_thread_params(enable=None, count=None, count_offload=None, stack_size=None, no_wait=None)¶
Sets threads related params.
- enable (bool) –
Enable threads in the embedded languages. This will allow to spawn threads in your app.
Threads will simply not work if this option is not enabled. There will likely be no error, just no execution of your thread code.
- count (int) –
Run each worker in prethreaded mode with the specified number of threads per worker.
Do not use with
Enables threads automatically.
- count_offload (int) –
Set the number of threads (per-worker) to spawn for offloading. Default: 0.
These threads run such tasks in a non-blocking/evented way allowing for a huge amount of concurrency. Various components of the uWSGI stack are offload-friendly.
Try to set it to the number of CPU cores to take advantage of SMP.
- stack_size (int) – Set threads stacksize.
- no_wait (bool) – Do not wait for threads cancellation on quit/reload.
- enable (bool) –
set_mules_params(mules=None, touch_reload=None, harakiri_timeout=None, farms=None, reload_mercy=None, msg_buffer=None, msg_buffer_recv=None)¶
Sets mules related params.
Mules are worker processes living in the uWSGI stack but not reachable via socket connections, that can be used as a generic subsystem to offload tasks.
- mules (int|list) – Add the specified mules or number of mules.
- touch_reload (str|list) – Reload mules if the specified file is modified/touched.
- harakiri_timeout (int) – Set harakiri timeout for mule tasks.
- farms (list[MuleFarm]) –
Mule farms list.
- cls_mule_farm(‘first’, 2)
- cls_mule_farm(‘first’, [4, 5])
- reload_mercy (int) – Set the maximum time (in seconds) a mule can take to reload/shutdown. Default: 60.
- msg_buffer (int) – Set mule message buffer size (bytes) given for mule message queue.
- msg_buffer – Set mule message recv buffer size (bytes).
set_reload_params(min_lifetime=None, max_lifetime=None, max_requests=None, max_requests_delta=None, max_addr_space=None, max_rss=None, max_uss=None, max_pss=None, max_addr_space_forced=None, max_rss_forced=None, watch_interval_forced=None, mercy=None)¶
Sets workers reload parameters.
- min_lifetime (int) – A worker cannot be destroyed/reloaded unless it has been alive for N seconds (default 60). This is an anti-fork-bomb measure. Since 1.9
- max_lifetime (int) – Reload workers after this many seconds. Disabled by default. Since 1.9
- max_requests (int) –
Reload workers after the specified amount of managed requests (avoid memory leaks). When a worker reaches this number of requests it will get recycled (killed and restarted). You can use this option to “dumb fight” memory leaks.
Also take a look at the
reload-on-rssoptions as they are more useful for memory leaks.
The default min-worker-lifetime 60 seconds takes priority over max-requests.
Do not use with benchmarking as you’ll get stalls such as worker respawning too fast !!! i have to sleep a bit (2 seconds)…
- max_requests_delta (int) – Add (worker_id * delta) to the max_requests value of each worker.
- max_addr_space (int) – Reload a worker if its address space usage is higher than the specified value in megabytes.
- max_rss (int) – Reload a worker if its physical unshared memory (resident set size) is higher than the specified value (in megabytes).
- max_uss (int) –
Reload a worker if Unique Set Size is higher than the specified value in megabytes.
- max_pss (int) –
Reload a worker if Proportional Set Size is higher than the specified value in megabytes.
- max_addr_space_forced (int) – Force the master to reload a worker if its address space is higher than specified megabytes (in megabytes).
- max_rss_forced (int) – Force the master to reload a worker if its resident set size memory is higher than specified in megabytes.
- watch_interval_forced (int) – The memory collector [per-worker] thread memeory watch interval (seconds) used for forced reloads. Default: 3.
- mercy (int) – Set the maximum time (in seconds) a worker can take before reload/shutdown. Default: 60.
set_reload_on_exception_params(do_reload=None, etype=None, evalue=None, erepr=None)¶
Sets workers reload on exceptions parameters.
- do_reload (bool) – Reload a worker when an exception is raised.
- etype (str) – Reload a worker when a specific exception type is raised.
- evalue (str) – Reload a worker when a specific exception value is raised.
- erepr (str) – Reload a worker when a specific exception type+value (language-specific) is raised.
set_harakiri_params(timeout=None, verbose=None, disable_for_arh=None)¶
Sets workers harakiri parameters.
- timeout (int) – Harakiri timeout in seconds. Every request that will take longer than the seconds specified in the harakiri timeout will be dropped and the corresponding worker is thereafter recycled.
- verbose (bool) – Harakiri verbose mode. When a request is killed by Harakiri you will get a message in the uWSGI log. Enabling this option will print additional info (for example, the current syscall will be reported on Linux platforms).
- disable_for_arh (bool) – Disallow Harakiri killings during after-request hook methods.
Zerg mode. Zerg server params.
When your site load is variable, it would be nice to be able to add workers dynamically. Enabling Zerg mode you can allow zerg clients to attach to your already running server and help it in the work.
- socket (str|unicode) –
Unix socket to bind server to.
- unix socket -
- Linux abstract namespace -
- unix socket -
- clients_socket_pool (str|unicode|list[str|unicode]) –
This enables Zerg Pools.
Expects master process.
Accepts sockets that will be mapped to Zerg socket.
- socket (str|unicode) –
Zerg mode. Zergs params.
- server_sockets (str|unicode|list[str|unicode]) – Attaches zerg to a zerg server.
- use_fallback_socket (bool) – Fallback to normal sockets if the zerg server is not available