supervisor中的minfds及minprocs參數用途

使用supervisor遇到的一個坑,爲此還撕逼了一下午,先填了再說

先來看看minfds及minprocs這兩個參數在supervisor官方文檔中的說明(官方文檔地址http://www.supervisord.org/configuration.html#supervisord-section-values):

minfds
The minimum number of file descriptors that must be available before supervisord will start successfully. A call to setrlimit will be made to attempt to raise the soft and hard limits of the supervisord process to satisfy minfds. The hard limit may only be raised if supervisord is run as root. supervisord uses file descriptors liberally, and will enter a failure mode when one cannot be obtained from the OS, so it’s useful to be able to specify a minimum value to ensure it doesn’t run out of them during execution. This option is particularly useful on Solaris, which has a low per-process fd limit by default.

Default: 1024

Required: No.

Introduced: 3.0

大致意思:在supervisord成功啓動前,最小的文件描述符數字必須是可以使用的。setrlimit參數會試圖提高軟硬限制來滿足supervisord進程的minfds參數值。如果supervisord的運行用戶爲root,硬限制會被提高。supervisord可以自由地使用文件描述符,當無法從系統獲取時將進入錯誤模式,所以它能夠指定一個最小值,用於確保它不會在執行過程中用光文件描述符。這個參數在Solaris中特別有用,Solaris默認情況下具有較低的進程文件描述符限制。(默認值1024,參數爲數值,在3.0版本加入)

minprocs
The minimum number of process descriptors that must be available before supervisord will start successfully. A call to setrlimit will be made to attempt to raise the soft and hard limits of the supervisord process to satisfy minprocs. The hard limit may only be raised if supervisord is run as root. supervisord will enter a failure mode when the OS runs out of process descriptors, so it’s useful to ensure that enough process descriptors are available upon supervisord startup.

Default: 200

Required: No.

Introduced: 3.0

大致意思:在supervisord成功啓動前,最小的進程描述符數字必須是可以使用的。setrlimit參數會試圖提高軟硬限制來滿足supervisord進程的minprocs參數值。如果supervisord的運行用戶爲root,硬限制會被提高。當進程描述符超出系統運行的進程描述符時,supervisord會進入錯誤模式,因此,在啓動supervisord時,需要確保有足夠的進程描述符可用。(默認值200,參數爲數值,在3.0版本加入)

(突然覺得我的英語水平提高了好多,這是錯覺麼- -//)

個人猜想:minfds配置和Max open files有關,minprocs配置和max user processes有關

接下來用一個例子對這兩個參數做一次深入解析:

環境說明:

supervisor版本:3.1.3(epel源安裝)

操作系統版本:CentOS 7.3.1611

系統ulimit配置(紅色部分爲調整配置):

$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15060
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

supervisor配置參數:

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)

爲了更好的演示,使用supervisor來做nginx的進程守護,nginx配置(截取部分):

daemon off;
user nobody nobody;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 65535;

events {
use epoll;
worker_connections 65535;
}

supervisor的nginx守護配置:

[program:nginx]
command=/usr/local/nginx/sbin/nginx

接下來啓動supervisord

$ systemctl start supervisord

獲取supervisord及nginx的pid

$ ps aux |grep -E “supervisord|nginx: master” |grep -v grep
root 2118 0.0 0.3 220852 11968 ? Ss 02:09 0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root 2119 0.1 0.2 54932 10608 ? S 02:09 0:00 nginx: master process /usr/local/nginx/sbin/nginx

用pstree來看下更加直觀的進程,可以看到nginx是supervisord的子進程


現在來看下supervisord及nginx進程的limit限制情況

可以看到nginx進程的limit和其父進程supervisord是一致的(Max Processes及Max open files),但與系統的ulimit限制不一致,說明其不受系統ulimit限制所影響。

 

爲了驗證我的猜想,我將supervisord中的minfds和minprocs參數值都改爲50000

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=50000 ; (min. avail startup file descriptors;default 1024)
minprocs=50000 ; (min. avail process descriptors;default 200)

修改完成後重啓supervisord

$ systemctl restart supervisord

重新獲取supervisord及nginx的pid

$ ps aux |grep -E “supervisord|nginx: master” |grep -v grep
root 2175 0.0 0.3 220856 11972 ? Ss 02:31 0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root 2176 6.4 0.2 54932 10608 ? S 02:31 0:00 nginx: master process /usr/local/nginx/sbin/nginx

再來看下supervisord及nginx進程的limit限制情況

此時nginx進程的limit和其父進程supervisord仍然是一致的(Max Processes及Max open files),但是其數值全變爲50000。

結論:
這個例子很好得說明了我的猜想是正確的,supervisord中參數minfds和minprocs決定了supervisord進程及其守護的子進程的Max Processes及Max open files,並且這個limit限制不受系統ulimit所影響。
經過測試驗證,supervisord守護的子進程無法在supervisord配置文件中單獨修改minfds和minprocs這兩個參數。下面紅色部分的配置是無效的
[program:nginx]
command=/usr/local/nginx/sbin/nginx
minfds=65535
minprocs=65535

需要在[supervisord]後面加上配置參數
[supervisord]
minfds=81920
minprocs=81920


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章