Summary of common knowledge of Apache stress test and web performance optimization

  • 2020-05-15 02:33:54
  • OfStack

What is bandwidth?

Misunderstanding: "data moving speed in the line", "data transmission speed"

The bandwidth we are talking about is the sending speed of the data, such as the 100 megabit network card, which means the maximum sending speed of the network card is 100Mbps, that is to say, the network card can send 100Mb data at most in one second; Related factors:

The ability of the data sending device to transmit the base 2 signal to the line, also known as the signal transmission frequency, and the ability of the data receiving device at the other end to receive the base 2 signal, including the support degree of the line to the transmission frequency;
The degree of parallelism of data transmission medium is equivalent to the concept of computer system bus width.

Habits and conventions

b: bit unit bit;

B: byte unit Byte;

1 B KB = 1024;

1 b kb = 1000;

The conversion of M and K is the same as above;

What is throughput rate?

Throughput rate (Throughput) refers to the number of requests processed by the web server per unit of time. Unit: reqs/s;

1 is more concerned with the upper limit of the concurrent processing capacity of the server, that is, the maximum throughput;

About stress testing

Several premises of pressure test based on throughput rate:

Concurrent users; (the number of users sending requests to the server at any one time)
Total number of requests;
Request resource description;

Several important indicators:

Request wait time

Average user request waiting time (mainly measures the server's quality of service to a single user in the case of 1 fixed number of concurrent users)
Average server requester care time (measures overall server service quality)
Stress test tools: Apache comes with ab, LoadRunner, Jmeter

Server system load


$ cat /proc/loadavg 

0.58 1.19 0.64 1/92 8306

Here, the three Numbers of 0.58, 1.19 and 0.64 represent the system load calculated in the last 1 minute, 5 minute and 15 minute respectively.

1 represents the number of processes in the current run queue; 92 represents the total number of processes at this time; 8306 represents the last process created up to this point, ID;

Introduction to the use of Apache ab

In building a high-performance web site, the performance test of Server was conducted by ab, the pressure test tool provided by apache, and 1 relevant knowledge was searched as follows:

The full name of ab is ApacheBench, which is a small tool attached to Apache. It is specially used for benchmark testing of HTTP Server and can simulate multiple concurrent requests at the same time. Here is a practical example to introduce the use of ab:


[xiekeli@localhost ~]$ ab -n 1000 -c 50 http://www.abc.com/a.php        

 // produce 1000 time http Request, the number of concurrent users at a time :50


This is ApacheBench, Version 2.0.40-dev <;$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
 
Benchmarking www.abc.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests
 
 
Server Software: Apache                     // Under test platform Apache 

Server Hostname: www.abc.com                   // Server hostname 
Server Port: 80
 
Document Path: /a.php
Document Length: 231 bytes                   // Document size 
 
Concurrency Level: 50                       // concurrency 
Time taken for tests: 12.818547 seconds
Complete requests: 1000                      // Number of completed requests 
Failed requests: 0                       // Number of failed requests 
Write errors: 0
Non-2xx responses: 1001
Total transferred: 438438 bytes                  // The amount of network traffic in the entire scenario 
HTML transferred: 231231 bytes                  // In the whole scene HTML Content transfer volume 
Requests per second: 78.01 [#/sec] (mean)       // Throughput rate, the number of requests processed per second ( In the back bracket  mean  It is said 1 An average )
Time per request: 640.927 [ms] (mean)          // Response time per request (in parentheses)  mean  It is said 1 An average 

Time per request: 12.819 [ms] (mean, across all concurrent requests)    // Response time per request (as explained in parentheses below, is the average of all concurrent Numbers) 

Transfer rate: 33.39 [Kbytes/sec] received  // The average traffic per second on the network can help eliminate the problem of extended response times due to excessive network traffic  
Connection Times (ms)           // The breakdown of time consumed on the network, the specific algorithm of the data is not very clear  

min mean[+/-sd] median max
Connect: 186 307 598.1 212 9188
Processing: 188 271 289.6 214 1923
Waiting: 188 245 219.9 213 1416
Total: 376 579 660.2 427 9380
 // The response of all requests in the entire scenario. Each request is in the scenario 1 Response time, where 50 User response time is less than % 1093  Ms, 60 %   The user response time is less than 1247  Milliseconds, the maximum response time is less than 7785  Milliseconds, because for concurrent requests, cpu It's not actually processed at the same time, it's processed on a piece-by-piece basis per request, so it's basically the same 1 a Time per request Time is approximately equal to time 2 a Time per request Time times the number of concurrent requests 

Percentage of the requests served within a certain time (ms) 
50% 427
66% 430
75% 431
80% 433
90% 451
95% 1630
98% 3382
99% 3429
100% 9380 (longest request)

-n: represents the number of tests. In many places, it is translated as "the number of requests sent". This is 1000 http requests;
-c: represents the number of requests per time. -c 50 indicates that 50 http requests are initiated at the same time. After receiving the responses for all 50 requests, another 50 http requests are sent until 1000 requests are sent.

Some other related knowledge of web optimization:
The difference between caching (cache) and caching (buffer) :

Caching (cache) : the purpose of caching is to save the results of expensive computations and then retrieve them directly when needed to avoid repeated computations.

Buffering (buffer) : the purpose is to improve the problems caused by different speeds between components. Play the role of smooth connection between fast equipment and slow equipment.

Page caching (Page Cache)

Page caching is to cache the results of dynamic calculation to avoid unnecessary double calculation of dynamic content. It is mainly aimed at dynamically generated html pages, dynamic pictures or dynamic XML data.

Cache persistence and search

If there are too many cache files, the cache directory will be crowded with a large number of files. If the read and write frequency of the cached files is relatively high, the impact on CPU will be very large.

Solutions:

1. Ease this by using file systems that support hash for accelerated directory traversal, such as XFS and reiserfs;

2. Cache directory classification

Expired inspection

Cache expiration time Cache expiration length

Put the cache in memory

If you put the cached data in a disk file, each cache load and expiration check is at the expense of I/O. If the disk is also running an I/O intensive application such as a database, then the I/O operation of the cache file will have a definite delay.

The authors mention two of PHP's caching frameworks here: APC and XCache.

Cache server

Cache HTML in a separate cache server. With memcached, you can easily store the cache in other servers through TCP. memcached also USES memory space to store the cache data, which can reduce unnecessary I/O. memcached maintains an expiration date for each key. Once the expiration date is reached, the key will be automatically deleted.

Local absence of cache

Locally cache-free allows you to specify a block of HTML code that contains dynamic data that needs to be evaluated in real time each time and then combined with the rest of the cache to produce the final page.

Static content

In a dynamic content cache, each user's request is sent to a dynamic program, which determines whether to output the cache based on the expiration date of the cache. So this control is expensive.

Take the dynamic page ×××.php cache out of the cache directory and put it into the same directory: ×××.html, directly access the corresponding static page through the browser.

Of course, static pages also need dynamic procedures to achieve, 1 general static page management is through CMS (content management system) to manage.

Update strategy of static page:

1. When data is updated, static content is regenerated;

2. Generate static content at a fixed time;

Local staticization

Static pages can be updated independently of each local page by SSI (server side included) technology.

The SSI technology can be found in any of the major web servers, such as Apache's mod_include and Lighttpd's mod_ssi.

Explanation: PV

PV (page view) is the number of page views, or clicks, that is usually used to measure a network news channel or website or even a news story.

Definition: how many pages of your site does a visitor see in 24 hours (0 to 24). Note: no double counting of pv when the same person visits the same page on your website. pv is a visitor who opens several pages of your website.

Calculation of pv: when a visitor visits, record the page he visits and the corresponding IP, and then determine whether the IP visited the page today or not. If your site is at 23:00 and IP alone has 600, 000 entries, and each visitor visits an average of 3 pages, then the pv table will have 1.8 million entries.


Related articles: