metwork-framework / mfext

metwork/mfext module
http://metwork-framework.org/mfext
BSD 3-Clause "New" or "Revised" License
4 stars 5 forks source link

rlimit infinity #1824

Open matthieumarrast opened 5 months ago

matthieumarrast commented 5 months ago

Problem

In plugin's config.ini file we have:

# resource limit for each app worker
# rlimit_as => maximum area (in bytes) of address space which may be taken
#              by the worker.
# rlimit_nofile => maximum number of open file descriptors for the current
#                  worker.
# rlimit_stack => maximum size (in bytes) of the call stack for the current
#                 worker. This only affects the stack of the main thread
#                 in a multi-threaded worker.
# rlimit_fsize =>  maximum size of a file which the worker may create.
#   (empty value means no limit)
rlimit_as = 1000000000
rlimit_nofile = 1000
rlimit_stack = 10000000
rlimit_fsize = 100000000

So it results to the below circus configuration in tghe circus conf gile (~/tmp/config_auto/circus.ini`):

[watcher:app.<plugin>.main]
...
rlimit_as = 1000000000
rlimit_nofile = 1000
rlimit_stack = 10000000
rlimit_fsize = 100000000

But if we want to disable the limits by seizing empty values in the plugin's config.ini (as written in the comment)

#   (empty value means no limit)
rlimit_as = 
rlimit_nofile =  
rlimit_stack = 
rlimit_fsize = 

it results to missing rlimit options in ~/tmp/config_auto/circus.ini !!

In its documentation, circus indicates that To set a limit value to RLIM_INFINITY, do not set a value, like this config line: ‘rlimit_nofile = ‘.

IMPORTANT: this is applied in https://github.com/metwork-framework/circus/blob/master/circus/process.py, preexec function, check here if indeed infinity rlimits are not taken into accounts

Solution

We should have:

rlimit_as = 
rlimit_nofile =  
rlimit_stack = 
rlimit_fsize = 

in the circus.ini config file.

Update

{% if APP.rlimit_as > 0 %}rlimit_as = {{APP.rlimit_as}}{% endif %}
{% if APP.rlimit_nofile > 0 %}rlimit_nofile = {{APP.rlimit_nofile}}{% endif %}
{% if APP.rlimit_stack > 0 %}rlimit_stack = {{APP.rlimit_stack}}{% endif %}
{% if APP.rlimit_fsize > 0 %}rlimit_fsize = {{APP.rlimit_fsize}}{% endif %}

in file https://github.com/metwork-framework/mfext/blob/master/adm/templates/circus.ini

matthieumarrast commented 5 months ago

If I try to get the rlimits for my process: mfserv 1503310 1503228 1 14:04 ? 00:00:00 python /opt/metwork-mfserv-2.2/bin/signal_wrapper.py --timeout=60 --signal=15 --timeout-after-signal=3 --socket-up-after=3 /home/mfserv/var/app_foo_main_1.socket -- uvicorn --uds /home/mfserv/var/app_foo_main_1.socket --workers 1 main.application:app

prlimit -p 1503310
RESOURCE   DESCRIPTION                               SOFT        HARD UNITS
AS         address space limit                sans limite sans limite octets
CORE       max core file size                           0           0 octets
CPU        CPU time                           sans limite sans limite secondes
DATA       max data size                      sans limite sans limite octets
FSIZE      max file size                      sans limite sans limite octets
LOCKS      max number of file locks held      sans limite sans limite verrous
MEMLOCK    max locked-in-memory address space       65536       65536 octets
MSGQUEUE   max bytes in POSIX mqueues              819200      819200 octets
NICE       max nice prio allowed to raise               0           0
NOFILE     max number of open files                 65536       65536 fichiers
NPROC      max number of processes                 100000      100000 processus
RSS        max resident set size              sans limite sans limite octets
RTPRIO     max real-time priority                       0           0
RTTIME     timeout for real-time tasks        sans limite sans limite microsecondes
SIGPENDING max number of pending signals            31612       31612 signaux
STACK      max stack size                         8388608 sans limite octets

resources as, nofile, stack and fsize doesn't have hard limits. So probably by default the limit is "no limit"... no need of code modification.

(stack has a soft limit, I don't know why)