阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nginx服务器10000 并发 优化测试(ab测试工具)

161次阅读
没有评论

共计 2549 个字符,预计需要花费 7 分钟才能阅读完成。

1.nginx 监控模块

1)编译 nginx, 加上参数 –with-http_stub_status_module  

#/usr/local/nginx/sbin/nginx -V
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 配置指令
  ./configure --prefix=/usr/local
    --user=nginx 
    --group=nginx
    --with-http_ssl_module
    --with-http_realip_module
    --http-client-body-temp-path=/usr/local/var/tmp/nginx/client 
    --http-proxy-temp-path=/usr/local/var/tmp/nginx/proxy 
    --http-fastcgi-temp-path=/usr/local/var/tmp/nginx/fcgi 
    --http-scgi-temp-path=/usr/local/var/tmp/nginx/scgi 
    --http-uwsgi-temp-path=/usr/local/var/tmp/nginx/uwsgi 
    --with-http_geoip_module 
    --with-http_stub_status_module

2)修改 nginx 配置文件,添加监控状态配置

在 nginx.conf 的 server 块中添加如下代码

location /nginx_status {# Turn on nginx stats
    stub_status on;
    # I do not need logs for stats
    access_log   off;
    # Security: Only allow access from 192.168.1.100 IP #
    #allow 192.168.1.100;
    # Send rest of the world to /dev/null #
    #deny all;
}
Nginx 服务器 10000 并发 优化测试 (ab 测试工具)
解释:
Active connections:对后端发起的活动连接数。
Server accepts handled requests:Nginx 总共处理了 655 个连接,成功创建 655 次握手(证明中间没有失败的),总共处理了 1985 个请求。
Reading:Nginx 读取到客户端的 Header 信息数。
Writing:Nginx 返回给客户端的 Header 信息数。
Waiting:开启 keep-alive 的情况下,这个值等于 active – (reading + writing),意思就是 Nginx 已经处理完成,正在等候下一次请求指令的驻留连接。
/usr/local/nginx/sbin/nginx -t  // 测试配置是否正确
/usr/local/nginx/sbin/nginx -s reload

2. 设置最大连接数(50000)/ 加快 tcp 连接数的回收 / 让空的 tcp 允许回收利用 / 关闭洪水攻击抵御

echo 50000 > /proc/sys/net/core/somaxconn

echo 1 > /proc/sys/net/ipv4/tcp_tw/recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 0 > /proc/sys/net/ipv4/tcp_syncookies 

3. 设置打开更多文件数
ulimit -n 50000

vim /etc/nginx/nginx.conf
worker_rlimit_nofile 10000;    //nginx 允许打开最大文件数 10000--> 写在全局 不是在 events
events{

worker_connections 10240;
}

/usr/sbin/nginx -t
/usr/sbin/nginx -s reload

4.ab -c 5000 -n 100000 http://192.168.63.129/index.html // 压力测试
测试结果:

Server Software: nginx/1.4.6
Server Hostname: 192.168.63.129
Server Port: 80

Document Path: /index.html
Document Length: 65 bytes

Concurrency Level: 5000
Time taken for tests: 46.416 seconds
Complete requests: 100000
Failed requests: 90202
(Connect: 0, Receive: 0, Length: 90202, Exceptions: 0)
Write errors: 0
Non-2xx responses: 90282
Total transferred: 36624606 bytes
HTML transferred: 18815922 bytes
Requests per second: 2154.42 [#/sec] (mean)
Time per request: 2320.813 [ms] (mean)
Time per request: 0.464 [ms] (mean, across all concurrent requests)
Transfer rate: 770.55 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 18 1251 2273.8 824 31950
Processing: 298 839 299.1 855 6307
Waiting: 1 648 298.8 651 6194
Total: 408 2090 2323.2 1697 36083

Percentage of the requests served within a certain time (ms)
50% 1697
66% 1758
75% 1802
80% 1843
90% 2583
95% 4601
98% 8399
99% 8807
100% 36083 (longest request)

5000 并发 100000 连接数 失败请求 90202  幸好这个是测试服务器

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-07/145939.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2549字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中