นี่คือของฉันnginx.conf(ฉันได้อัปเดตการกำหนดค่าเพื่อให้แน่ใจว่าไม่มี PHP ที่เกี่ยวข้องหรือคอขวดอื่น ๆ ):
user                nginx;
worker_processes    4;
worker_rlimit_nofile 10240;
pid                 /var/run/nginx.pid;
events
{
    worker_connections  1024;
}
http
{
    include             /etc/nginx/mime.types;
    error_log           /var/www/log/nginx_errors.log warn;
    port_in_redirect    off;
    server_tokens       off;
    sendfile            on;
    gzip                on;
    client_max_body_size 200M;
    map $scheme $php_https { default off; https on; }
    index index.php;
    client_body_timeout   60;
    client_header_timeout 60;
    keepalive_timeout     60 60;
    send_timeout          60;
    server
    {
        server_name dev.anuary.com;
        root        "/var/www/virtualhosts/dev.anuary.com";
    }
}
ฉันใช้http://blitz.io/playเพื่อทดสอบเซิร์ฟเวอร์ของฉัน (ฉันซื้อแผนการเชื่อมต่อพร้อมกัน 10 000 รายการ) ใน 30 วินาทีเรียกฉันได้รับความนิยมและ964 5,587 timeoutsการหมดเวลาครั้งแรกเกิดขึ้นที่ 40.77 วินาทีในการทดสอบเมื่อจำนวนผู้ใช้พร้อมกันอยู่ที่ 200
ในระหว่างการทดสอบโหลดเซิร์ฟเวอร์คือ ( topเอาต์พุต):
 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                               20225 nginx     20   0 48140 6248 1672 S 16.0  0.0   0:21.68 nginx                                                                  
    1 root      20   0 19112 1444 1180 S  0.0  0.0   0:02.37 init                                                                   
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                               
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.03 migration/0      
ดังนั้นจึงไม่ใช่ปัญหาทรัพยากรเซิร์ฟเวอร์ ถ้าเช่นนั้นจะเป็นอะไร
อัพเดท 2011 12 09 GMT 17:36
จนถึงตอนนี้ฉันได้ทำการเปลี่ยนแปลงต่อไปนี้เพื่อให้แน่ใจว่าคอขวดไม่ใช่ TCP / IP เพิ่มไปที่/etc/sysctl.conf:
# These ensure that TIME_WAIT ports either get reused or closed fast.
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1
# TCP memory
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
ข้อมูลการแก้ปัญหาเพิ่มเติมบางส่วน:
[root@server node]# 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) 126767
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
NB ที่worker_rlimit_nofileตั้งค่าเป็น10240nginx config
อัพเดท 2011 12 09 GMT 19:02
ดูเหมือนว่าฉันจะทำการเปลี่ยนแปลงมากกว่านี้ยิ่งแย่ลงเท่าไหร่ แต่ที่นี่ไฟล์ปรับแต่งใหม่
user                nginx;
worker_processes    4;
worker_rlimit_nofile 10240;
pid                 /var/run/nginx.pid;
events
{
    worker_connections  2048;
    #1,353 hits, 2,751 timeouts, 72 errors - Bummer. Try again?
    #1,408 hits, 2,727 timeouts - Maybe you should increase the timeout?
}
http
{
    include             /etc/nginx/mime.types;
    error_log           /var/www/log/nginx_errors.log warn; 
    # http://blog.martinfjordvald.com/2011/04/optimizing-nginx-for-high-traffic-loads/
    access_log              off;
    open_file_cache         max=1000;
    open_file_cache_valid   30s;
    client_body_buffer_size 10M;
    client_max_body_size    200M;
    proxy_buffers           256 4k;
    fastcgi_buffers         256 4k;
    keepalive_timeout       15 15;
    client_body_timeout     60;
    client_header_timeout   60;
    send_timeout            60;
    port_in_redirect        off;
    server_tokens           off;
    sendfile                on;
    gzip                    on;
    gzip_buffers            256 4k;
    gzip_comp_level         5;
    gzip_disable            "msie6";
    map $scheme $php_https { default off; https on; }
    index index.php;
    server
    {
        server_name ~^www\.(?P<domain>.+);
        rewrite     ^ $scheme://$domain$request_uri? permanent;
    }
    include /etc/nginx/conf.d/virtual.conf;
}
อัพเดท 2011 12 11 GMT 20:11
นี่คือผลลัพธ์ของnetstat -ntlaในระหว่างการทดสอบ
https://gist.github.com/d74750cceba4d08668ea
อัพเดท 2011 12 12 GMT 10:54
เพียงเพื่อชี้แจงiptables(ไฟร์วอลล์) ปิดในขณะทดสอบ
อัพเดท 2011 12 12 GMT 22:47
นี่คือการsysctl -p | grep memถ่ายโอนข้อมูล
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 8388608 8388608 8388608
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 65536 8388608
net.ipv4.route.flush = 1
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.wmem_max = 8388608
net.core.wmem_default = 65536
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
อัพเดท 2011 12 12 GMT 22:49
ฉันใช้blitz.ioเพื่อเรียกใช้การทดสอบทั้งหมด URL ที่ฉันกำลังทดสอบคือhttp://dev.anuary.com/test.txtโดยใช้คำสั่งต่อไปนี้:--region ireland --pattern 200-250:30 -T 1000 http://dev.anuary.com/test.txt
อัพเดท 2011 12 13 GMT 13:33
nginxขีด จำกัด ของผู้ใช้ (ตั้งค่า/etc/security/limits.conf)
nginx       hard nofile 40000
nginx       soft nofile 40000
          worker_processes 4