High-performance PHP learning-Benchmark Technology
First, Benchmark testing tools
The benchmark tool provides statistical information about the response of a Web server when a variety of different impersonated user requests occur. They allow us to simulate any number of users requesting a particular Web document on a Web server, and more importantly, it allows us to simulate any number of users accessing documents on the Web server simultaneously (concurrent requests).
For example, the information provided by each tool is related to the following:
1. Total time spent responding to a request
2. Total response size from the server
3. Total number of requests that the Web server can process per second
Second, Apache Benchmark
Here I will introduce you to the Apache Benchmark (AB/AB2) tool.
This is one of the most well-known benchmark tools, which is part of the default Apache installation and is able to load test the Web server by simulating any number of requests for a specific URL. The AB tool provides the following information:
1. Total data size (in bytes) of the transfer
2. The total number of requests that the Web server can support per second under simulated traffic
3. The maximum time (in milliseconds) that a request takes to complete
4. The shortest time (in milliseconds) spent completing a request
Note: The operation of the Ubuntu operating system is the AB command, and the author is using openSUSE, the command used in this system is ab2. So the author in the operation of the use of the AB2 command, but for convenience, write all the time to write AB command.
many different load simulations can also be run using the AB tool, such as:
1. Mock requests for Web documents
2, the request within the specified time
3. Request when opening keep-alive
Most importantly, Apache Benchmark is independent of the Apache Web server, so that it can run AB while running the tool's
the Web server on the computer is inactive.
third, install Apache Benchmark
under the Linux/unix system, you can use the AB command once you have installed Apache.
under Windows, users can open http://httpd.apache.org/. After loading this page, click the Download from a mirror (download from image) link on the left side of the page to find the appropriate download package for your system, the Windows binary version, and then download.
once the package has been downloaded, you can run the Setup Wizard to install the software anywhere on the system. I will install Apache to the default location C:\Program Files\apache software Foundation, but can also be installed anywhere in the system. The location you select here is where the Apache_home reference points.
now, open \apache2.2\bin. You should see a collection of files and directories as shown.
Iv. use of the AB command
now, let's use the AB tool. (benchmark test takes www.example.com as an example)
the composition of all AB commands follows this structure:
AB [options] [Full path to Web document]
Example:
ab-n 1 http://www.example.com/
n Indicates the number of requests executed on the specified URL. In this example, AB only requests a Web document once, but the value of n can be any number less than 50000. By default, n is set to 1.
The next part of the command is the URL section. For the command you just executed, the URL is http://www.example.com/. If you choose to test a document in this field, such as test.php (does not exist), the URL is: http://www.example.com/test.php
the result of executing the above command is as follows:
AB response of Urlhttp://www.example.com
The data is divided into 4 parts
1. Server Information
contains the software, host name, and port number that the server listens on for the Web server to run.
2. Script Information
contains information about the Web document that runs the simulation. Document path contains the requested documents, and document length contains the sum of all the bytes of HTML, images, CSS, JS, and any content in the response.
3. Connection Information
the body that contains the information. It answers such as "How long does it take to receive a request response?" How much data did the "," return? "And, most importantly, it answers," How many users can the Web server support when processing a document? ”。
The following table provides a complete list and description of this part of the data.
AB Response Description
4, the connection index breakdown classification
The last section contains a table that contains the Connect, processing, waiting, and total fields. These fields tell us how long it takes to request in each process state. We are most interested in the total field and its maximum and minimum value columns.
AB option Tag
Here are some tests combined with the above markup
1. Concurrent Testing
simulates a concurrent test and makes 10 concurrent requests to the Web server until it has reached 100 request locations. A warning when using the C tag is that the value used is less than or equal to the total number of requests to make N.
Example: Ab-n 100-c http://www.example.com
The AB command responds as
Concurrent simulation results for www.example.com
by simulating concurrent requests, we can see the request per second field, and notice that the Web server can support a request (user) per second. Analyzing the total min and max columns of the connection metrics, we noticed that under the specified traffic load of 10 concurrent requests, the fastest response was 371 milliseconds, and the slowest request took 575 milliseconds.
However, we know that traffic doesn't just last 1, 2, or 3 seconds, and high traffic can last for a few minutes, hours, or even days. Let's run a simulation to test it.
2. Time Test
The t tag can check the behavior of the Web server at any time.
below we use the following command to simulate 10 users accessing the site at the same time in 20 seconds:
ab-c 10-t http://www.example.com/
Note: The command does not contain an n tag, but the tag is included by default and when the T option is used, AB sets its value to 50000. In some cases, when the T option is used, the maximum number of requests may reach 50000, at which point the simulation ends.
The AB command responds as
benchmark results for www.example.com/(10 concurrent users in 20 seconds)
the results of this simulation indicate that performance degrades when 10 concurrent users request a Web document in a 20-second period. The fastest satisfaction request took 464 milliseconds, and the slowest request took 1890 milliseconds.
V, AB traps
There are a few caveats when using AB.
1, then look at the above command, you will notice that at the end of the domain name there is a backslash. This backslash is required if you do not request a specific document in the domain.
2, AB may also be blocked by some Web servers because of the user agent values it passes to the Web server, so in these cases, you may not receive any data. To resolve this issue, use one of the available option tags-h to provide custom browser header information in your request.