nginx限制文件访问速率

需求: 一个文件下载功能需要限制文件同时访问的并发数和当个连接的访问速率;

配置:

在http context内增加:

limit_conn_zone $binary_remote_addr zone=limitbyaddr:10m;
limit_conn_status 429;

 

在location内增加:

limit_conn limitbyaddr 40;
limit_rate 1m;

 

用ab测试生效; ab -n 50 -c 41 http://*******zip

 

Server Software: nginx/1.12.0
Server Hostname: *****
Server Port: 8080

Document Path: *******.zip
Document Length: 185 bytes

Concurrency Level: 41
Time taken for tests: 454.580 seconds
Complete requests: 50
Failed requests: 40
(Connect: 0, Receive: 0, Length: 40, Exceptions: 0)
Write errors: 0
Non-2xx responses: 10
Total transferred: 19072201700 bytes
HTML transferred: 19072187090 bytes
Requests per second: 0.11 [#/sec] (mean)
Time per request: 372755.829 [ms] (mean)
Time per request: 9091.606 [ms] (mean, across all concurrent requests)
Transfer rate: 40972.29 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 21 141.4 1 1001
Processing: 1 363336 183511.5 454150 454577
Waiting: 1 7 28.3 3 203
Total: 2 363357 183471.0 454151 454578

Percentage of the requests served within a certain time (ms)
50% 454151
66% 454163
75% 454171
80% 454189
90% 454224
95% 454311
98% 454578
99% 454578
100% 454578 (longest request)

 

参考资料:

https://www.nginx.com/resources/library/complete-nginx-cookbook/?utm_source=nginxorg&utm_medium=homepagebanner&utm_campaign=complete_cookbook&_ga=2.155941947.1811327257.1521102376-2057340437.1501655649

 

转载于:https://www.cnblogs.com/bluecarrife/p/8575076.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值