In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how nginx uses the built-in module to configure speed limit and current limit". The editor shows you the operation process through an actual case, the operation method is simple and fast, and it is practical. I hope this article "how to configure speed limit and current limit with built-in module in nginx" can help you solve the problem.
Sometimes, when NGINX is faced with some special scenarios, it needs to be configured with a certain speed limit and current limit, such as an official website, where the front-end static files may be very small, but there are also some apk packages configured at the same time. If these packages are not restricted, they may cause a relatively large load or bandwidth pressure. I have encountered it here. I will deal with this problem today.
Before there is no limit, the corresponding package download speed is as follows:
Add the following configuration to make certain restrictions:
Http {... # omit limit_conn_zone $binary_remote_addr zone=addr:10m;... # omit} server {listen 80 default; server_name localhost; location ~ "^ / test/app/" {limit_conn addr 6; limit_rate_after 10m; limit_rate 1200k; limit_conn_status 499; limit_conn_log_level warn; root / app;}}
Description:
In the http area, I use version 1.15 here, and the corresponding module ngx_http_limit_conn_module has been installed by default.
Limit_conn_zone: is a fixed name and corresponds to it when called below. $binary_remote_addr: indicates yes
The remote_addr flag is used to limit. The purpose of "binary_" is to abbreviate memory usage and to limit the same client ip address.
Zone=addr:10m: generates a 10m memory area named addr, which is used to store access frequency information.
The server region can be written directly in the server area to indicate all restrictions, or it can be written to the corresponding location to indicate individual region restrictions.
Limit_conn: indicates that a single IP limits the maximum number of connections to 6. Limit_rate_after: indicates that there is no speed limit when the size is 10m before the request.
Limit_rate: indicates that the maximum bandwidth of a single connection is limited to 1200k. Limit_conn_status: sets the return value of the reject request. Values can only be set between 400 and 599 (the default is 503). Limit_conn_log_level: defines the log level. Default is error.
Now do a simple test to see the download speed:
You can see that the corresponding speed has been limited, and the speed begins to slow down after 10m until the limited position is reached. Now you can simply take a pressure test to see what happens:
$ab-n 10-c 10 http://www.test.com/res/app/app-xiaomi-release.apk
This command indicates that the corresponding resource is requested 10 times, and it is issued as 10. Monitor the corresponding log and see the following result. Because the maximum concurrency we defined is 6, there will be four failures and a 499 status code will be returned, and then there will be six successes.
$tailf-n 100a | awk-F ","'{print $6}'"response": "499"response": "499"response": "response": "499"response": "response": "200"response": "200"response": "response": "200"response": "200"
In addition, after the stress test command, there are some outputs to refer to:
Total transferred: 403483116 bytesHTML transferred: 403481400 bytesRequests per second: 0.18 [# / sec] (mean) Time per request: 56865.501 [ms] (mean) Time per request: 5686.550 [ms] (mean, across all concurrent requests) Transfer rate: 6929.10 [Kbytes/sec] received
If you don't say anything else, just look at the last one, you can see that the total output is about 7M/s, which is exactly in line with the value of a single limit 1.2M/s times 6.
This is the end of the content about "how to configure speed limit and current limit with built-in module in nginx". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.