The environment of Java necessary skills (linux ab stress test Nginx) (combat)

1. Test ordinary current limit

1) Configure nginx to limit the flow rate to 1qps, and limit the current to the client IP address (the return status code is 503 by default), as follows:

http{
 limit_req_zone $binary_remote_addr zone=test:10m rate=1r/s;
 
 server {
  listen  80;
  server_name localhost;
  location / {
   limit_req zone=test;
   root html;
   index index.html index.htm;
  }
}

 

2) Initiate several requests continuously and concurrently; 3) Check the server access log,

Expand it a bit:

Windows:

【1】. Open the nginx installation directory.

【2】. Enter the logs directory.

【3】. Double-click to view the log file.

Linux

【1】. Execute vi /usr/local/nginx/logs/error.log command 

Can also use 

[root@localhost logs]# tail -f access.log

 

It can be seen that 4 requests were reached continuously in 09 seconds, and only 1 request was processed; the first request was processed, and the other 3 requests were rejected

2. Test burst

 1) When the speed limit is 1qps, requests exceeding the rate will be directly rejected. In order to cope with burst traffic, requests should be allowed to be queued for processing; therefore, burst=5 is configured, that is, a maximum of 5 requests are allowed to be queued for processing;

http{
 limit_req_zone $binary_remote_addr zone=test:10m rate=1r/s;
 
 server {
  listen  80;
  server_name localhost;
  location / {
   limit_req zone=test burst=5;
   root html;
   index index.html index.htm;
  }
}

2) Use ab to initiate 10 requests concurrently, ab -n 10 -c 10 http://127.0.0.1/index.html

3) Check the server access log; according to the log, the first request was processed, four requests from 2 to 5 were rejected, and five requests from 6 to 10 were processed; why is this result?

Check the ngx_http_log_module module of the nginx source code, each request will register the handler to the NGX_HTTP_LOG_PHASE stage (the last stage of HTTP request processing prints the log [includes normal processing and exception processing]);

The abnormal processing will be output earlier than the normal processing log.

Therefore, the actual situation should be like this: 10 requests arrive at the same time, the first request arrives and is processed directly, the second to sixth requests arrive, and the processing is delayed in queue (one processing per second); the seventh to 10th requests are directly rejected , So print the access log first;

The second to sixth requests (queuing delay processing) are processed every second, and the access log is printed after the processing is completed, that is, one request is processed every second in 18-22 seconds;

4) The response time of ab statistics is as follows, the minimum response time is 1ms, the maximum response time is 5002ms, and the average response time is 1502ms:

3 test nodelay

1) 2 shows that after configuring burst, although burst requests will be queued for processing, the response time is too long, and the client may have timed out; therefore, add the configuration nodelay to make nginx urgently process waiting requests to reduce response time:

 

2) Use ab to initiate 10 requests concurrently, ab -n 10 -c 10 http://127.0.0.1/index.html

3) Check the server access log; the first request is processed directly, the second to sixth five requests are queued for processing (configure nodelay, nginx emergency processing), the seventh to tenth four requests are rejected

4) The response time of ab statistics is as follows, the minimum response time is 1ms, the maximum response time is 2ms, and the average response time is 1ms:

 

 

Here we mainly introduce some basic use of high concurrency ab stress test. You can use it to test the performance of your own code.

 

 

Guess you like

Origin blog.csdn.net/Coder_Boy_/article/details/110427496