`

nginx限流 以及ab测试验证

 
阅读更多

1,nginx的http配置 

proxy_intercept_errors on;

 limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;

limit_conn_status 503;  #超出限制时,返回状态码

location 模块配置:

limit_req zone=mylimit nodelay;

http模块错误页面重定向

error_page  503              /408.html; 

2,ab测试验证

ab测试参数:

ab -n 800 -c 800  http://192.168.1.10/ 
(-n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url)

ab -t 60 -c 100 http://192.168.1.10/ 
在60秒内发请求,一次100个请求。 
  
//如果需要在url中带参数,这样做 
ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello.html 
p.txt 是和ab.exe在一个目录 
p.txt 中可以写参数,如  p=wdp&fq=78 

-----------------------------------------------------------------------------------------------

ab测试具体例子:

ab -t 1 -c 20 http://192.169.0.1/base

模拟1秒钟 20个请求

[root@web-01 sbin]# ab -t 1 -c 20 http://192.168.0.1/base

This is ApacheBench, Version 2.3 <$Revision: 655654 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

 

Benchmarking dev.cbs.bacic5i5j.com (be patient)

Completed 5000 requests

Finished 7457 requests

 

 

Server Software:        nginx/1.4.4

Server Hostname:        dev.cbs.bacic5i5j.com

Server Port:            80

 

Document Path:          /base

Document Length:        0 bytes  HTTP响应数据的正文长度

 

Concurrency Level:      20

Time taken for tests:   1.000 seconds  所有这些请求处理完成所花费的时间 

Complete requests:      7457  完成请求数 

Failed requests:        7447   --失败请求数   就是由于限流10r/s 每秒钟10个请求

   (Connect: 0, Receive: 0, Length: 7447, Exceptions: 0)

Write errors:           0

Non-2xx responses:      7474

Total transferred:      1233810914 bytes    ---网络总传输量 

HTML transferred:       1232331592 bytes   --HTML内容传输量 

Requests per second:    7455.60 [#/sec] (mean)   ---吞吐量-每秒请求数

Time per request:       2.683 [ms] (mean)   --服务器收到请求,响应页面要花费的时间 

Time per request:       0.134 [ms] (mean, across all concurrent requests)  --并发的每个请求平均消耗时间 

Transfer rate:          1204666.99 [Kbytes/sec] received   ---received 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

网络上消耗的时间的分解: 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.0      0       1

Processing:     1    2   0.2      2       5

Waiting:        0    0   0.1      0       2

Total:          1    3   0.3      3       6

 

整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间 
其中 50% 的用户响应时间小于 3毫秒 
80 % 的用户响应时间小于 3毫秒 
最大的响应时间小于 6 毫秒 
Percentage of the requests served within a certain time (ms) 

Percentage of the requests served within a certain time (ms)

  50%      3

  66%      3

  75%      3

  80%      3

  90%      3

  95%      3

  98%      4

  99%      4

 100%      6 (longest request)

欢迎关注我的微信公众号,里面会分享技术和投资的一些想法,欢迎交流讨论

 

 

 


 

 

  • 大小: 92.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics