limit_conn 压测无效

来源:2-26 Nginx的请求限制_请求限制配置语法

qq_天下无敌_3

2018-09-19

配置文件:

# nginx request
limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s;
# nginx conn
limit_conn_zone $binary_remote_addr zone=conn_zone:1m;
server {
    listen       80;
    server_name  localhost;
    location / {
        # use request
        # 1r/s 表示一秒只接受一个请求 其余的请求拒绝处理并且返回错误码给客户端
        #limit_req zone=req_zone;
        # 请求超过一秒以后 剩下的请求将被延迟处理  请求数超过burst定义的数量 多余的请求返回503错误
        #limit_req zone=req_zone burst=3 nodelay;
        #limit_req zone=req_zone burst=3;
        # use conn
        # 同一时刻只能有一个客户端IP的链接
        limit_conn conn_zone 1;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

ab -n 500 -c 20 http://118.89.229.117/index.html 【ip为腾讯云的外网ip】
注:压测127.0.0.1以及 域名 都不好使

下面是压测结果:

[root@VM_7_27_centos conf.d]# ab -n 500 -c 20 http://118.89.229.117/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 118.89.229.117 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        nginx/1.14.0
Server Hostname:        118.89.229.117
Server Port:            80

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

Concurrency Level:      20
Time taken for tests:   5.768 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Total transferred:      422500 bytes
HTML transferred:       306000 bytes
Requests per second:    86.69 [#/sec] (mean)
Time per request:       230.717 [ms] (mean)
Time per request:       11.536 [ms] (mean, across all concurrent requests)
Transfer rate:          71.53 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   97 303.3      0    2098
Processing:     0  118 424.8      1    4869
Waiting:        0   88 400.9      1    4869
Total:          1  215 535.5      3    4870

Percentage of the requests served within a certain time (ms)
  50%      3
  66%     13
  75%    201
  80%    203
  90%   1001
  95%   1004
  98%   1404
  99%   2364
 100%   4870 (longest request)

然后错误日志中没有任何输出。

写回答

2回答

qq_天下无敌_3

提问者

2018-09-20

这个是不是和//img.mukewang.com/szimg/5ba30ea200019e8615011501.jpg
这个链接有关系

0
0

Jeson

2018-09-20

ab和服务端的机器是在一台上吗?
如果是,拿一台不同的机器压测。
或者,改成压测动态的接口。
Nginx处理静态元素的效率挺高的,如果请求的网络延时也小的话,不一定能出来效果

0
3
Jeson
回复
qq_天下无敌_3
那你把你登陆信息发我邮箱jeson@imoocc.com
2018-09-22
共3条回复

Nginx入门到实践-Nginx中间件应用+搭建Webserver架构

中间件、负载均衡、应用层安全防护、动静分离、Nginx+LUA开发等

4183 学习 · 908 问题

查看课程