Skip to content

Cheapening

Classes

AlgoBusyness

AlgoBusyness(*args, **kwargs)

Algo

Algorithm adds or removes workers based on average utilization for a given time period. It's goal is to keep more workers than the minimum needed available at any given time, so the app will always have capacity for new requests.

Note

Requires cheaper_busyness plugin.


set_basic_params

1
2
3
4
5
6
7
8
.set_basic_params(
    check_interval_busy: int | None = None,  # (1)!
    busy_max: int | None = None,  # (2)!
    busy_min: int | None = None,  # (3)!
    idle_cycles_max: int | None = None,  # (4)!
    idle_cycles_penalty: int | None = None,  # (5)!
    verbose: bool | None = None,  # (6)!
)
  1. Interval (sec) to check worker busyness.

  2. Maximum busyness (percents). Every time the calculated busyness is higher than this value, uWSGI will spawn new workers. Default: 50.

  3. Minimum busyness (percents). If busyness is below this value, the app is considered in an "idle cycle" and uWSGI will start counting them. Once we reach needed number of idle cycles uWSGI will kill one worker. Default: 25.

  4. This option tells uWSGI how many idle cycles are allowed before stopping a worker.

  5. Number of idle cycles to add to idle_cycles_max in case worker spawned too early. Default is 1.

  6. Enables debug logs for this algo.


set_emergency_params

1
2
3
4
5
6
.set_emergency_params(
    workers_step: int | None = None,  # (1)!
    idle_cycles_max: int | None = None,  # (2)!
    queue_size: int | None = None,  # (3)!
    queue_nonzero_delay: int | None = None,  # (4)!
)
  1. Number of emergency workers to spawn. Default: 1.

  2. Idle cycles to reach before stopping an emergency worker. Default: 3.

  3. Listen queue (backlog) max size to spawn an emergency worker. Default: 33.

  4. If the request listen queue is > 0 for more than given amount of seconds new emergency workers will be spawned. Default: 60.

Sets busyness algorithm emergency workers related params.

Emergency workers could be spawned depending upon uWSGI backlog state.

Note

These options are Linux only.


AlgoManual

AlgoManual(*args, **kwargs)

Algo

Algorithm allows to adjust number of workers using Master FIFO commands.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


AlgoQueue

AlgoQueue(*args, **kwargs)

Algo

If the socket's listen queue has more than cheaper_overload requests waiting to be processed, uWSGI will spawn new workers.

If the backlog is lower it will begin killing processes one at a time.

.. note: Only available on Linux and only on TCP sockets (not UNIX domain sockets).


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


set_basic_params

1
2
3
.set_basic_params(
    check_num_overload: int | None = None,  # (1)!
)
  1. Number of backlog items in queue.

AlgoSpare

AlgoSpare(*args, **kwargs)

Algo

The default algorithm.

If all workers are busy for a certain amount of time seconds then uWSGI will spawn new workers. When the load is gone it will begin stopping processes one at a time.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


set_basic_params

1
2
3
.set_basic_params(
    check_interval_overload: int | None = None,  # (1)!
)
  1. Interval (sec) to wait after all workers are busy before new worker spawn.

AlgoSpare2

AlgoSpare2(*args, **kwargs)

Algo

This algorithm is similar to spare, but suitable for large scale by increase workers faster (before overload) and decrease them slower.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


set_basic_params

1
2
3
.set_basic_params(
    check_interval_idle: int | None = None,  # (1)!
)
  1. Decrease workers after specified idle. Default: 10.

Cheapening

Cheapening(*args, **kwargs)

OptionsGroup

uWSGI provides the ability to dynamically scale the number of running workers (adaptive process spawning) via pluggable algorithms.

Note

This uses master process.


name

.name: str = ''

Name to represent the group.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


.print_algorithms()

Print out enabled cheaper algorithms.


set_basic_params

1
2
3
4
5
6
7
.set_basic_params(
    spawn_on_request: bool | None = None,  # (1)!
    cheaper_algo: Algo = None,  # (2)!
    workers_min: int | None = None,  # (3)!
    workers_startup: int | None = None,  # (4)!
    workers_step: int | None = None,  # (5)!
)
  1. Spawn workers only after the first request.

  2. The algorithm object to be used for adaptive process spawning. Default: spare. See .algorithms.

  3. Minimal workers count. Enables cheaper mode (adaptive process spawning).

    1
    .. note:: Must be lower than max workers count.
    
  4. The number of workers to be started when starting the application. After the app is started the algorithm can stop or start workers if needed.

  5. Number of additional processes to spawn at a time if they are needed,


set_memory_limits

1
2
3
4
.set_memory_limits(
    rss_soft: int | None = None,  # (1)!
    rss_hard: int | None = None,  # (2)!
)
  1. Don't spawn new workers if total resident memory usage of all workers is higher than this limit in bytes.

    Warning

    This option expects memory reporting enabled: .logging.set_basic_params(memory_report=1)

  2. Try to stop workers if total workers resident memory usage is higher that thi limit in bytes.

Sets worker memory limits for cheapening.


algorithms

.algorithms()

Algorithms available to use with cheaper_algorithm.