2015-12-10 23 views
0

我試圖通過使用Tornado(4進程),Supervisor和Nginx來提高我的服務性能。一旦我配置了設置,我使用Siege來測試該服務。使用Tornado和Nginx的性能與僅使用Tornado類似

但是,結果並未顯示使用多個進程的任何競爭。我認爲這個組合可以處理比單個流程更多的請求,但是它沒有。我仍然無法弄清楚原因,因爲Nginx似乎成功地將請求分派到不同的Tornado進程。

supervisord.conf:

[group:a] 
programs=a-server, a-db 

[program:a-server] 
command=python2.7 /my/path/to/app/server.py --port=80%(process_num)02d 
directory=/my/path/to/app 
numprocs=4 
process_name=%(program_name)s%(process_num)d 
autorestart=true 
loglevel=info 
redirect_stderr=true 
stdout_logfile=/my/path/to/app/server.log 
stdout_logfile_maxbytes=50MB 
stdout_logfile_backups=10 

[program:a-db] 
command=mongod --dbpath /path/to/db 
numprocs=1 
process_name=db 
autorestart=true 
redirect_stderr=true 
stdout_logfile=/my/path/to/app/db.log 
stdout_logfile_maxbytes=30MB 
stdout_logfile_backups=10 

[inet_http_server] 
port=127.0.0.1:9001 

[supervisord] 
logfile=/my/path/to/app/supervisord.log 
logfile_maxbytes=50MB 
logfile_backups=10 
pidfile=/my/path/to/app/supervisord.pid 


[supervisorctl] 
serverurl=http://127.0.0.1:9001 


[rpcinterface:supervisor] 
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 

Nginx.conf:

worker_processes 1; 

error_log /my/path/to/app/nginx.log; 
pid /my/path/to/app/nginx.pid; 

events { 
    worker_connections 1024; 
    # Using Mac 
    use kqueue; 
} 

http { 
    upstream a { 
     server 127.0.0.1:8000; 
     server 127.0.0.1:8001; 
     server 127.0.0.1:8002; 
     server 127.0.0.1:8003; 
    } 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    access_log /my/path/to/app/access.log; 

    gzip on; 
    gzip_min_length 20; 
    gzip_proxied any; 
    gzip_types text/plain text/css text/xml application/javascript 
       application/x-javascript application/xml 
       application/atom+xml text/javascript; 

    server { 
     listen 80; 
     server_name localhost; 

     location /nginx_status { 
      stub_status on; 
      access_log off; 
      allow 127.0.0.1; 
      deny all; 
     } 

     location/{ 
      proxy_pass_header Server; 
      proxy_set_header Host $http_host; 
      proxy_redirect off; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Scheme $scheme; 
      proxy_pass http://a; 
     } 
    } 
} 

請幫我找出問題,或請告訴我如何分析並找到瓶頸!非常感謝你!

ENV:mac book pro,CPU:2.4 GHz Intel Core 2 Duo。

+0

1 nginx worker。 – kwarunek

回答

1

一些提示:

# calculated sometimes as 2 * Number of CPUs, sometimes like number of backends + spare e.g. 
# 1 is not enough, is like a Tornado itself 
worker_processes 4; 

events { 
    worker_connections 19000; # It's the key to high performance - have a lot of connections available 
} 

worker_rlimit_nofile 20000; # Each connection needs a filehandle (or 2 if you are proxying) 

tcp_nopush on; 
tcp_nodelay on; 
sendfile on; 

# allow the server to close the connection after a client stops responding. 
reset_timedout_connection on; 

# Accept as many connections as possible, after nginx gets notification about a new connection. 
# May flood worker_connections, if that option is set too low. 
multi_accept on; 

可以爲用戶提供服務的總金額= worker_processes * worker_connections。

檢查一些nginx進程限制,如nofile,ulimit。

也退房Tuning nginx worker_process to obtain 100k hits per min(我抄了一大部分)

+0

基本上,你是對的。 – zeck