nginx性能优化及测试

服务器平台:dell r720
处理器: Intel Xeon E5-2609 v2 @ 2.50GHz        *2
内存:128G
硬盘:3T raid5
操作系统:CentOS7.2 x64

配置修改:/etc/sysctl.conf
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_fin_timeout=30

net.core.netdev_max_backlog=20000
net.core.somaxconn=20000
net.ipv4.tcp_max_orphans=20000
net.ipv4.tcp_max_syn_backlog=20000
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_synack_retries=1
net.ipv4.tcp_syn_retries=1

配置修改:/etc/security/limits.conf
*       soft    nofile  10000
*       hard    nofile  10000

nginx.conf主要配置:
worker_processes  8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

events {
    worker_connections  65535;
    use epoll;
    epoll_events 10000;
}

server {
。。。
location /tmp/ {
        alias /tmp/;
        autoindex on;
    }
}

测试样本:
[root@localhost tmp]# ll /tmp/
total 36
-rw-r--r--. 1 root root 10240 Aug  9 03:04 10k.txt
-rw-r--r--. 1 root root  1024 Aug  9 03:03 1k.txt
-rw-r--r--. 1 root root  2048 Aug  9 03:11 2k.txt
-rw-r--r--. 1 root root  3072 Aug  9 03:13 3k.txt
-rw-r--r--. 1 root root  4096 Aug  9 03:16 4k.txt
-rw-r--r--. 1 root root  5120 Aug  9 03:07 5k.txt



客户端与服务器用一个千兆交换机互联,处理器:Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz,内存16G
操作系统:Fedora 22 x64
测试工具:Apache bench
工具安装:sudo dnf install httpd-tools -y

测试命令:
ab -n 1000000 -c 100 http://172.16.1.140/tmp/1k.txt

Document Path:          /tmp/1k.txt
Document Length:        1024 bytes

Concurrency Level:      100
Time taken for tests:   25.521 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      1274000000 bytes
HTML transferred:       1024000000 bytes
Requests per second:    39183.77 [#/sec] (mean)
Time per request:       2.552 [ms] (mean)
Time per request:       0.026 [ms] (mean, across all concurrent requests)
Transfer rate:          48750.12 [Kbytes/sec] received
服务器网卡目测平均:230Mbit/s

Document Path:          /tmp/2k.txt
Document Length:        2048 bytes

Concurrency Level:      100
Time taken for tests:   25.245 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      2298000000 bytes
HTML transferred:       2048000000 bytes
Requests per second:    39611.50 [#/sec] (mean)
Time per request:       2.525 [ms] (mean)
Time per request:       0.025 [ms] (mean, across all concurrent requests)
Transfer rate:          88893.78 [Kbytes/sec] received
服务器网卡目测平均:330Mbit/s

Server Software:        nginx/1.11.6
Server Hostname:        172.16.1.140
Server Port:            80

Document Path:          /tmp/3k.txt
Document Length:        3072 bytes

Concurrency Level:      100
Time taken for tests:   31.855 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      3322000000 bytes
HTML transferred:       3072000000 bytes
Requests per second:    31392.34 [#/sec] (mean)
Time per request:       3.185 [ms] (mean)
Time per request:       0.032 [ms] (mean, across all concurrent requests)
Transfer rate:          101841.16 [Kbytes/sec] received
服务器网卡目测平均:491Mbit/s


Document Path:          /tmp/4k.txt
Document Length:        4096 bytes

Concurrency Level:      100
Time taken for tests:   39.808 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      4347000000 bytes
HTML transferred:       4096000000 bytes
Requests per second:    25120.48 [#/sec] (mean)
Time per request:       3.981 [ms] (mean)
Time per request:       0.040 [ms] (mean, across all concurrent requests)
Transfer rate:          106639.38 [Kbytes/sec] received
服务器网卡目测平均:920Mbit/s

Document Path:          /tmp/5k.txt
Document Length:        5120 bytes

Concurrency Level:      100
Time taken for tests:   48.670 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      5371000000 bytes
HTML transferred:       5120000000 bytes
Requests per second:    20546.67 [#/sec] (mean)
Time per request:       4.867 [ms] (mean)
Time per request:       0.049 [ms] (mean, across all concurrent requests)
Transfer rate:          107769.70 [Kbytes/sec] received

服务器网卡目测平均:940Mbit/s


Document Path:          /tmp/10k.txt
Document Length:        10240 bytes

Concurrency Level:      100
Time taken for tests:   92.317 seconds
Complete requests:      1000000
Failed requests:        0
Total transferred:      10492000000 bytes
HTML transferred:       10240000000 bytes
Requests per second:    10832.30 [#/sec] (mean)
Time per request:       9.232 [ms] (mean)
Time per request:       0.092 [ms] (mean, across all concurrent requests)
Transfer rate:          110988.73 [Kbytes/sec] received

服务器网卡目测平均:955Mbit/s


静态资源放在/tmp(内存文件系统上)
关掉access log 对性能没有影响

服务器有4个网口,由于CPU还有很大余量,预计4个网口同时使用(公网dns负载均衡),10k测试样本能达到接近3.6Gbit/s吞吐量且CPU接近饱和
由于测试样本位于/tmp,因此磁盘io对本次测试无明显影响

你可能感兴趣的:(nginx性能优化及测试)