在我的ToDo列表中从fcgiwrap迁移到uWSGI(这也带来了我计划使用的其他许多好处)之后,我终于设法build立了一个以uWSGI v2.0为特色的debian-wheezytesting系统, nginx v1.4.4。
在第一步中,我想通过uWSGI的cgi-plugin可靠地运行.cgi-scripts,并以最小的开销(相当弱的硬件),同时可以轻松地增强我的configuration,同时也可以通过框架部署应用程序,例如bottle / flask / django作为第二步。
所以我select了使用uWSGI的皇帝模式 ,这个模式目前只能控制一个configuration来运行uWSGI-cgi-plugin的两个工作者,每个工作者有两个线程。
检查出各种function之后,设置或多或less都可以正常运行了,但我觉得有两种奇怪的行为,我认为这些行为是错误的 :
heartbeat = 20 ),如果.cgi没有在定义的心跳时间内运行,则皇帝将重复杀死/重新生成附属的主人。 configuration的工人数量似乎并不重要。 reload-mercy = 10这个选项,因为它仍然logging着your mercy for graceful operations on workers is 60 seconds (这是默认值)。 好吧,这只是一个小问题,与我无关。 使用心跳选项的原因是我想尽可能使用内置的uWSGI机制来保证我的cgis / apps的可用性。
任何提示我可能会误解或做错? 我看不出任何明显的原因,为什么不应该在我的configuration中将心跳选项与cgi-module结合使用,而是希望得到更进一步的了解! 我假设nginx与上述问题无关,另外我还仔细检查了文件和目录 – perms … uWSGI是通过init.d-script启动的,但是手动启动时的行为是一样的。
我的configuration如下:
在nginx.conf中的部分:
location ~ ^/cgi-bin/.*\..+$ { root /usr/local/nginx/vhosts/testdomain.com/cgi-bin; gzip off; include uwsgi_params; uwsgi_modifier1 9; uwsgi_pass unix:///var/run/nginx/testdomain_cgi-bin_uwsgi.sock; }
emperor.ini:
[uwsgi] uid = www-data gid = www-data emperor = /etc/uwsgi/vassals emperor-pidfile = /var/run/uwsgi/emperor.pid daemonize = /var/log/uwsgi_emperor.log
testdomain_cgi-bin.ini:
[uwsgi] uid = www-data gid = www-data chdir = /usr/local/nginx/vhosts/testdomain/cgi-bin plugins = cgi cgi = /cgi-bin=/usr/local/nginx/vhosts/testdomain/cgi-bin cgi-allowed-ext = .cgi socket = /var/run/nginx/testdomain_cgi-bin_uwsgi.sock master = true #heartbeat = 25 processes = 2 threads = 2 reload-mercy = 10 no-orphans = true post-buffering = 4096 max-requests = 2048 vacuum = true logto = /usr/local/nginx/logs/uwsgi_testdomain_cgi-bin.log
日志 (选项心跳启用时):
/var/log/uwsgi_emperor.log:
*** Starting uWSGI 2.0 (32bit) on [Wed Feb 5 11:35:36 2014] *** compiled with version: 4.7.2 on 31 January 2014 08:46:00 os: Linux-3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 nodename: testnode machine: i686 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: / *** running under screen session 1111.myscrn *** detected binary path: /usr/local/bin/uwsgi setgid() to 33 setuid() to 33 *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 3940 your memory page size is 4096 bytes detected max file descriptor number: 1024 writing pidfile to /var/run/uwsgi/emperor.pid *** starting uWSGI Emperor *** *** has_emperor mode detected (fd: 6) *** [uWSGI] getting INI configuration from testdomain_cgi-bin.ini Wed Feb 5 11:35:36 2014 - [emperor] vassal testdomain_cgi-bin.ini has been spawned Wed Feb 5 11:35:36 2014 - [emperor] vassal testdomain_cgi-bin.ini is ready to accept requests Wed Feb 5 11:35:43 2014 - [emperor] vassal testdomain_cgi-bin.ini is now loyal [emperor] vassal testdomain_cgi-bin.ini sent no heartbeat in last 30 seconds, brutally respawning it... Wed Feb 5 11:38:56 2014 - [emperor] removed uwsgi instance testdomain_cgi-bin.ini [emperor] unrecognized vassal event on fd 5 [emperor] unrecognized vassal event on fd 5 ... above lines repeaded for about another 50 times ... *** has_emperor mode detected (fd: 6) *** [uWSGI] getting INI configuration from testdomain_cgi-bin.ini Wed Feb 5 11:38:56 2014 - [emperor] vassal testdomain_cgi-bin.ini has been spawned Wed Feb 5 11:38:56 2014 - [emperor] vassal testdomain_cgi-bin.ini is ready to accept requests
/usr/local/nginx/logs/uwsgi_testdomain_cgi-bin.log:
*** Starting uWSGI 2.0 (32bit) on [Wed Feb 5 11:35:36 2014] *** compiled with version: 4.7.2 on 31 January 2014 08:46:00 os: Linux-3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 nodename: testnode machine: i686 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: /etc/uwsgi/vassals *** running under screen session 1111.myscrn *** detected binary path: /usr/local/bin/uwsgi your processes number limit is 3940 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to UNIX address /var/run/nginx/testdomain_cgi-bin_uwsgi.sock fd 3 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 175536 bytes (171 KB) for 2 cores *** Operational MODE: threaded *** initialized CGI mountpoint: /cgi-bin = /usr/local/nginx/vhosts/testdomain.com/cgi-bin *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 20825) spawned uWSGI worker 1 (pid: 20826, cores: 2) [pid: 20826|app: -1|req: -1/1] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:35:43 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 13 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) announcing my loyalty to the Emperor... [pid: 20826|app: -1|req: -1/2] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:35:54 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 2 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/3] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:36:04 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 5 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) [pid: 20826|app: -1|req: -1/4] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:36:16 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 3 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/5] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:36:28 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 3 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) [pid: 20826|app: -1|req: -1/6] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:36:39 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 3 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/7] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:36:51 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 5 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) [pid: 20826|app: -1|req: -1/8] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:37:03 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 2 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/9] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:37:15 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 3 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) [pid: 20826|app: -1|req: -1/10] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:37:27 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 6 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/11] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:37:39 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 12 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) [pid: 20826|app: -1|req: -1/12] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:37:51 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 4 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 1) [pid: 20826|app: -1|req: -1/13] XX.XX.XX.XXX () {42 vars in 678 bytes} [Wed Feb 5 11:38:03 2014] GET /cgi-bin/hellow.cgi => generated 282 bytes in 3 msecs (HTTP/1.1 200) 1 headers in 44 bytes (0 switches on core 0) Wed Feb 5 11:38:56 2014 - uWSGI worker 1 screams: UAAAAAAH my master disconnected: i will kill myself !!! *** Starting uWSGI 2.0 (32bit) on [Wed Feb 5 11:38:56 2014] *** compiled with version: 4.7.2 on 31 January 2014 08:46:00 os: Linux-3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 nodename: testnode machine: i686 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: /etc/uwsgi/vassals *** running under screen session 1111.myscrn *** detected binary path: /usr/local/bin/uwsgi your processes number limit is 3940 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to UNIX address /var/run/nginx/testdomain_cgi-bin_uwsgi.sock fd 3 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 175536 bytes (171 KB) for 2 cores *** Operational MODE: threaded *** initialized CGI mountpoint: /cgi-bin = /usr/local/nginx/vhosts/testdomain.com/cgi-bin *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 20881) spawned uWSGI worker 1 (pid: 20882, cores: 2)
用于vassal选项heartbeat uWSGI doc :
Argument: number (Vassal option) Announce vassal health to the emperor every N seconds.
uWSGI doc为皇帝selectemperor-required-heartbeat :
Argument: number Default: 30 Set the Emperor tolerance about heartbeats. When a vassal asks for 'heartbeat mode' the emperor will also expect a 'heartbeat' at least every <secs> seconds.
从github使用2.0.1,它有更好的心跳代码。 你的问题是皇帝宽容(30秒)和心跳频率(25)之间的小时间间隔。 对于2.0中的错误,工作者超时在每个请求都被重置。 除了2.0.1之外,一旦第一名工作者产卵,就会触发心跳,导致更好的结果(立即检测到破碎的应用程序)。 关于工人--reload-mercy怜悯,正确的select是--worker-reload-mercy工作者重新--worker-reload-mercy ( --worker-reload-mercy是非工作者进程)