Apache Ab Testing



Apache Bench or ab for short, is a command-line tool to perform simple load tests on an HTTP server, be it a website or an API. By running the following command, you will get an overview of how the server is performing under load: ab -n 100 -c 10 So, in this post, I will try to explain how we can use Apache Bench. If you do not know what A/B testing is about, take a quick look at the Wikipedia page on that subject. Long story short, the idea is to serve two different version of a page to your visitors and check which one is getting the most success. When you found which version is better, you can definitely switch to it. I read about A/B testing a while ago, and I figured it was a good opportunity to test it out. If you do not know what A/B testing is about, take a quick look at the Wikipedia page on that subject. Long story short, the idea is to serve two different version of a page to your visitors and check which one is getting the most success.

Basic concepts

First, I will quote an official introduction,

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

AB is Apache’s HTTP service testing tool, which can test the performance of your HTTP server, especially the number of requests processed per second. AB can not only do stress tests on Apache servers, but also on other types of servers. For example, nginx, Tomcat, IIS, etc.

It should be noted that the test target of AB is URL based, so the service interface based on TCP cannot be tested with ab.

Environmental preparation

My running environment is Mac OS 10.14.6.

In fact, MAC itself broughtabTool, you can try it in the terminal window

You can see the version of ab.

But there are some problems with this version. For example, I found the following phenomena in the actual test,

After checking the Internet, I learned that the error was caused by the too low version of ab. So you need to install a newer version to replace this one.

Apache Ab Testing

To download AB tool first, we can go to the following address to find the latest version and then download it.

http://httpd.apache.org/download.cgi

What I download here ishttpd-2.4.41.tar.gzThis version. Just download the latest version of the document.

There are several dependencies that need to be installed,aprandapr-uitl, andpcre。 This can be found at the following address to download the latest version.

http://apr.apache.org/download.cgi

https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz

The installation process is as follows.

Install APR and enter the source directory

Install APR uitl and enter the source directory

Install PCRE and enter the source directory

Install httpd and enter the source directory

Then copy the AB execution file under the directory / usr / local / httpd to replace the one under / usr / SBIN.

In addition, according to your actual situation, you can also adjustulimit -nParameter, otherwise it may be reported during testtoo many open fiels

AB common commands

There are many commands of ab. here are some common ones, which will be used in the following examples.

-N. The total number of requests. The default is 1.

-C. number of concurrent requests at the same time.

-P if followed by a file, it indicates a post request. The file contains the request data. Set the – t parameter according to the data format.

-T sets the content type in the request header (for post / put), such as application / x-www-form-urlencoded. The default is text / plain.

-W print the test results to an HTML table.

More commands are available throughman abQuery.

Start testing

We don’t test our own services first. First, we use QQ’s website to see the test results, and then we can make a comparison.

Then I test my own blog site,

My blog

Apache Ab Testing

Apache Ab Windows Download

Let me first explain what the indicators of the test results mean.

Apache Ab Testing

  • Concurrency level is the concurrency number, equal to the value after – C
  • Time taken for tests
  • Complete requests number of successfully received returns
  • Failed requests number of failed requests
  • Non-2xx responses indicates that the returned HTTP status code is not the number of 2XX (for example, 404401500…). If both are 2XX, this indicator is not displayed in the result
  • Requests per second
  • Time per request the average time spent per request. The first time per request equals concurrency timetaken 1000 / done, the second time per request (mean, across all concurrency requests) is equal to timetoken * 1000 / done, the first can be understood as the average request waiting time of users, the second can be understood as the average request waiting time of servers

Based on these indicators, QQ website and my blog site which performance is good, it’s needless to say, ha ha!

Both of the above tests are based on get requests, and post requests are also very easy. I won’t talk about it here. If you are interested, you can test it yourself.

reference resources:

Apache Ab Install

https://www.cnblogs.com/cjsbl…