Extra Meal Recommend Several Commonly Used Performance Testing Tools

Extra meal Recommend several commonly used performance testing tools #

Hello, I’m Liu Chao. Many classmates have left me messages asking me to talk about tools, so here comes my first extra meal at the speed of light πŸ˜„

Mastering a performance testing tool is a necessary skill for us. It can not only help us simulate testing scenarios (including concurrency and complex combination scenarios), but also convert test results into data or graphics, helping us understand system performance more intuitively.

Common Performance Testing Tools #

There are many commonly used performance testing tools, and here I will list a few practical ones.

For developers, the preferred tools are open-source and free performance (stress) testing software, such as ab (ApacheBench) and JMeter; for professional testing teams, the preferred choice is the paid version of LoadRunner. Of course, there are also many companies that have developed their own customized performance testing software, which has the advantage of strong customization but the disadvantage of poor universality.

Next, I will focus on introducing the features and usage of ab and JMeter, two popular testing tools.

1. ab #

ab is a testing tool provided by Apache, which is simple and easy to use, making it very practical for testing web services.

ab can be used in both Windows and Linux systems. Here I will explain the installation method in Linux, which is very simple. Just enter the command yum -y install httpd-tools in the Linux system.

After successful installation, enter the command ab and you can see the following prompt:

img

ab is used to test POST and GET interface requests conveniently, and you can specify request count, concurrency, request parameters, etc. through parameters. For example, a test with 10 concurrent users and 100 request counts for a POST request would be:

ab -n 100 -c 10 -p 'post.txt' -T 'application/x-www-form-urlencoded' 'http://test.api.com/test/register'

post.txt is a document that stores POST parameters, with the following format:

username=test&password=test&sex=1

Here are the meanings of several commonly used parameters:

  • -n: total number of requests (default minimum is 1);
  • -c: concurrency level (default minimum is 1 and cannot be greater than the total number of requests, for example, if there are 10 requests and 10 concurrency, it means 1 person makes 1 request);
  • -p: path to the file containing POST parameters (-p and -T parameters should be used together);
  • -T: content type of the header (note that the letter “T” is capitalized).

When we test a GET request interface, we can directly append the request parameters to the URL:

ab -c 10 -n 100 http://www.test.api.com/test/login?userName=test&password=test

The output result is as follows:

img

In the above output, there are several performance indicators that can be referenced:

  • Requests per second: throughput, which represents the number of requests processed per unit of time at a certain concurrency level;
  • Time per request: the average waiting time for users to complete the requests, which is the time spent to complete all requests divided by (total requests divided by concurrency level);
  • Time per request: the average request processing time of the server, which is the time spent to complete all requests divided by the total number of requests;
  • Percentage of the requests served within a certain time: time distribution of requests per second, which shows the distribution of the lengths of each request response in the entire request, for example, 50% of the requests respond within 8ms, 66% of the requests respond within 10ms, indicating that 16% of the requests fall between 8ms and 10ms.

2. JMeter #

JMeter is a powerful performance testing tool provided by Apache, which can be installed and used in both Windows and Linux environments.

In the Windows environment, JMeter has a graphical user interface, so you can write test cases through the graphical interface, which is easy to learn and operate.

JMeter can not only perform simple concurrent performance tests but also perform complex macro benchmark tests. We can test the entire business process in JMeter by recording the script. JMeter also supports importing parameter variables through CSV files to achieve system performance testing with diversified parameters.

The installation of JMeter in Windows is very simple. Download the installation package from the official website and unzip it. If you need to open the graphical interface, go to the bin directory and find the jmeter.bat file, double-click to run it.

img

JMeter has comprehensive functions. Here I will briefly introduce how to record test scripts and test the performance of business using JMeter.

There are many methods to record JMeter scripts. One way is to use JMeter’s built-in proxy for recording. Another way is to use software like Badboy for recording. There is also a method I will explain below, which is recording scripts through a browser plugin. This method is very simple and requires no additional settings.

First, install a plugin called BlazeMeter Recorder to record test scripts. You can find it in the Chrome Web Store and click to install, as shown in the figure below:

img

Then use your Google account to log in to this plugin. Without logging in, we will not be able to generate JMeter files. After successful installation and login, the interface will appear as shown in the following figure:

img

Finally, click “Start” to start recording the script. After a successful recording, click “Save as JMX” to generate a JMeter file. We can open this file through JMeter and see the recorded script, as shown in the figure below:

img

At this point, we also need to create a “View Results Tree” to visualize and view the performance results:

img

After setting up the result tree, we can set the concurrency level and loop count for the thread group:

img

After successfully setting up, click “Run” and we can see the running result:

img

The test results of JMeter have similar performance indicator parameters to those of ab, so I will not repeat the explanation here.

3. LoadRunner #

LoadRunner is a commercial testing tool, and the price of its license is not low.

As a professional performance testing tool, LoadRunner performs very stably and efficiently in performance testing. Compared with JMeter, LoadRunner can simulate different internal IP addresses to simulate users in a real environment by assigning different IP addresses to the users being tested. I will not go into details here.

Summary #

That’s all for introducing the three commonly used performance testing tools. Finally, I have summarized today’s main content for you in a chart.

img

Nowadays, there are a lot of testing tools available, including Alibaba Cloud’s PTS testing tool, which is also very useful. However, each testing tool has its own advantages and disadvantages. Personally, I suggest that it would be better to explore the usage of other testing tools after becoming proficient in one of them.