MuleFarm(name: str, mule_numbers: Union[int, List[int]])¶
Represents a mule farm.
- name – Farm alias.
- mule_numbers – Total mules on farm count, or a list of mule numbers.
Workers aka [working] processes.
set_basic_params(*, count: int = None, touch_reload: Union[str, List[str]] = None, touch_chain_reload: Union[str, List[str]] = None, zombie_reaper: bool = None, limit_addr_space: int = None, limit_count: int = None, cpu_affinity: int = None)¶
- count –
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 – Trigger reload of (and only) workers if the specified file is modified/touched.
- touch_chain_reload –
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 – 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 – 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 – Limit the number of spawnable processes.
- cpu_affinity –
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 –
run_command_as_worker(command: str, *, after_post_fork_hook: bool = False)¶
Run the specified command as worker.
- command –
- after_post_fork_hook – Whether to run it after post_fork hook.
set_count_auto(count: int = None)¶
Sets workers count.
By default sets it to detected number of available cores
Parameters: count –
set_thread_params(enable: bool = None, *, count: int = None, count_offload: int = None, stack_size: int = None, no_wait: bool = None)¶
Sets threads related params.
- enable –
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 –
Run each worker in prethreaded mode with the specified number of threads per worker.
Do not use with
Enables threads automatically.
- count_offload –
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 – Set threads stacksize.
- no_wait – Do not wait for threads cancellation on quit/reload.
- enable –
set_mules_params(mules: Union[int, List[int]] = None, *, touch_reload: Union[str, List[str]] = None, harakiri_timeout: int = None, farms: List[uwsgiconf.options.workers.MuleFarm] = None, reload_mercy: int = None, msg_buffer: int = None, msg_buffer_recv: int = 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 – Add the specified mules or number of mules.
- touch_reload – Reload mules if the specified file is modified/touched.
- harakiri_timeout – Set harakiri timeout for mule tasks.
- farms –
Mule farms list.
- cls_mule_farm(‘first’, 2)
- cls_mule_farm(‘first’, [4, 5])
- reload_mercy – Set the maximum time (in seconds) a mule can take to reload/shutdown. Default: 60.
- msg_buffer – 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: int = None, max_lifetime: int = None, max_requests: int = None, max_requests_delta: int = None, max_addr_space: int = None, max_rss: int = None, max_uss: int = None, max_pss: int = None, max_addr_space_forced: int = None, max_rss_forced: int = None, watch_interval_forced: int = None, mercy: int = None)¶
Sets workers reload parameters.
- min_lifetime – 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 – Reload workers after this many seconds. Disabled by default. Since 1.9
- max_requests –
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 – Add (worker_id * delta) to the max_requests value of each worker.
- max_addr_space – Reload a worker if its address space usage is higher than the specified value in megabytes.
- max_rss – Reload a worker if its physical unshared memory (resident set size) is higher than the specified value (in megabytes).
- max_uss –
Reload a worker if Unique Set Size is higher than the specified value in megabytes.
- max_pss –
Reload a worker if Proportional Set Size is higher than the specified value in megabytes.
- max_addr_space_forced – Force the master to reload a worker if its address space is higher than specified megabytes (in megabytes).
- max_rss_forced – Force the master to reload a worker if its resident set size memory is higher than specified in megabytes.
- watch_interval_forced – The memory collector [per-worker] thread memeory watch interval (seconds) used for forced reloads. Default: 3.
- mercy – Set the maximum time (in seconds) a worker can take before reload/shutdown. Default: 60.
set_reload_on_exception_params(*, do_reload: bool = None, etype: str = None, evalue: str = None, erepr: str = None)¶
Sets workers reload on exceptions parameters.
- do_reload – Reload a worker when an exception is raised.
- etype – Reload a worker when a specific exception type is raised.
- evalue – Reload a worker when a specific exception value is raised.
- erepr – Reload a worker when a specific exception type+value (language-specific) is raised.
set_harakiri_params(*, timeout: int = None, verbose: bool = None, disable_for_arh: bool = None)¶
Sets workers harakiri parameters.
- timeout – 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 – 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 – Disallow Harakiri killings during after-request hook methods.
set_zerg_server_params(socket: str, *, clients_socket_pool: Union[str, List[str]] = None)¶
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 –
Unix socket to bind server to.
- unix socket -
- Linux abstract namespace -
- unix socket -
- clients_socket_pool –
This enables Zerg Pools.
Expects master process.
Accepts sockets that will be mapped to Zerg socket.
- socket –
set_zerg_client_params(server_sockets: Union[str, List[str]], *, use_fallback_socket: bool = None)¶
Zerg mode. Zergs params.
- server_sockets – Attaches zerg to a zerg server.
- use_fallback_socket – Fallback to normal sockets if the zerg server is not available