Jmeter running under linux

 
 
The method in this article is to add components under the graphical interface, generate a jmx script file, and then put the jmx file in the linux environment to run the script with the command line for performance testing.
 
1. Use Jmeter for stress test
If you can open the graphical interface, you can refer to the tutorial on using the graphical interface;
Also, test with command line under Linux.
 
1.1 Editing the Suppression Test Script in the Graphical Interface
Refer to "Jmeter Tutorial Simple Stress Test": http://www.cnblogs.com/TankXiao/p/4059378.html
 
In fact, the so-called script file is the jmx file saved after configuring the information with the graphical interface. jmx is a text in xml format, which can be used as a parameter to execute on the command line.
 
The following process is supplemented and modified on the basis of "Jmeter Tutorial Simple Stress Test" according to the testing habits of Y Company:
 
What is a stress test 
As the name implies: stress test is the system to be tested, under a certain access pressure, to see whether the program runs stably/server runs stably (resource occupancy)

For example: 2000 users go to a shopping website to shop at the same time, will the speed of these users open the page slow down, or whether the website will crash

 

Common tools for stress testing

To do a stress test, you generally need to use tools, which cannot be done manually. The most commonly used tool is LoadRunner, but LoadRunner is a paid software after all, and it is more complicated to use. Now more and more people are using Jmeter for stress testing. It's free and very easy to use.

 

 The steps to do a stress test are as follows:

1. Write a script or record a script

2. Using user-defined parameters

3. Scene Design

4. Use the controller to control how many users to simulate.

5. Use the listener to view the test results

 

 An example of stress testing in this article

The example given in this article is: Use Jmeter to simulate 200 users on a computer, and use bing to search for different keywords at the same time, and check whether the time returned by the page is within the normal range.

 

 Step 1: Parameterize using CSV Data Set Config

First, we put the 2 parameters needed for the test in the txt file,

Create a new data.txt file, enter some data, there are two data in one line, separated by commas.

1. Start Jmeter, the following interface will appear, the system automatically adds a Test Plan (test plan), you can change the name of the test plan in the name position, for example: Bing interface test sample

2. First add a Thread Group (right-click Test Plan -> Add -> Thread (Users) -> Thread Group);

Thread groups can also be renamed, for example: Bing 200 Concurrency

3. Then add a CSV Data Set Config under "Thread Group" (right click on the thread group -> Add -> Config Element -> CSV Data Set Config);

Configure the file content information used in the test in CSV Data Set Config,

 

Step 2: Add HTTP Request.

We add http request, send get to  http://cn.bing.com/search?q= ${param1}+${param2} ()

1. Right-click on Thread Group (Add -> Sampler -> HTTP Request), 

2. The data to be filled in are as follows:

A. Using variables in paths

 

B. Add variables in the variable column

C. Add variables to variables, and the path also contains variables

This article follows the second method

 

Step 3: Use Thread Group to control how many users to simulate

Check Thread Group

Number of Threads (users thread number): One user occupies one thread, 200 threads is to simulate 200 users

Ramp-Up Period(in seconds): Sets how long it takes for the thread to start up completely. If the number of threads is 200 and the preparation time is 10, it will take 1 second to start 20 threads. That is, 20 threads are started every second.

Loop Count: The number of times each thread sends a request. If the number of threads is 200 and the number of loops is 100, then each thread sends 100 requests. The total number of requests is 200*100=20000. If "Forever" is checked, all threads will keep sending requests until you choose to stop running the script.

Note: If you want to ensure that the threads in the number of threads can execute at the same time, the execution time of all threads must be greater than the time of the Ramp-up Period. The maximum number of running threads that Jmeter suppresses will not exceed the number of threads we set.

For an explanation of the relationship between Number of Threads, Ramp-Up Period and Loop Count, please refer to: http://blog.csdn.net/hsd412237463/article/details/49929173

Mainly for the understanding of Ramp-Up Period parameters ( http://www.knowsky.com/367353.html ).

(Each thread runs the test plan independently. Therefore, thread groups are often used to simulate concurrent user access. If the client does not have enough power to simulate a heavy load, Jmeter's distributed testing capabilities can be used to test through a Jmeter console. Remotely control multiple Jmeter engines to complete tests. 

       The parameter ramp-up period is used to tell JMeter how long to set up all threads. The default value is 0. If the ramp-up period is not specified, that is to say, the ramp-up period is zero, JMeter will create all threads immediately. Assuming that the ramp-up period is set to T seconds and the number of all threads is set to N, JMeter will set up every T/N seconds to create a thread. 

  Most of the parameters of the thread group are self-explanatory, only the ramp-up period is somewhat difficult to understand, because how to set the appropriate value is not easy. First, ramp-up period should generally not be set to zero if a large number of threads are to be used. Because if it is set to zero, Jmeter will create all threads at the beginning of the test and send access requests immediately, so it is easy to saturate the server, and more importantly, it will increase the load implicitly, which means that the server Will be overloaded, not because of high average access rate but because of abnormal initial access spikes caused by the first concurrent access of all threads, which can be seen through Jmeter's aggregate report listener. 

       This kind of anomaly is not what we need, so the rule for determining a reasonable ramp-up period is to have the initial CTR close to the average CTR. Of course, some tests may need to be run to determine reasonable traffic. 

  For the same reason, an excessively large ramp-up period is also inappropriate, because it will reduce the load of the access peak. In other words, some threads that were started at the beginning may have ended when some threads have not yet started. )

 

In addition, for the setting of the number of loops of the Thread Group, the scheduler can be used to specify:

 

 Step 4: Add a listener to view the test results

There are two commonly used listeners, one is to view the result tree (View Result Tree), right-click the thread group -> Add -> Listener (listener) -> View Result Tree (view the result tree)

One is the Aggregate Report, right-click the thread group -> Add -> Listener (listener) -> Aggregate Report (aggregate report)

After the following operation is completed, I will briefly explain the role of these two listeners

 

Step 5: Run it

So far, the script is all written, let's run it, how to see the test results

After clicking Start, the script will be executed, and you will see the specific information and response data of the request we sent in the "View Results" interface.

In practical applications, it is recommended to check "Only log errors", because when there are too many running requests, if all of them are displayed, the system is prone to crash, and we are more concerned about the wrong results.

Aggregated reports show many details, number of requests, 99 response times, error rates, and throughput. For a detailed explanation, please refer to "JMeter Aggregation Report" (  http://www.cnblogs.com/jackei/archive/2007/01/17/623166.html ).

 

1.2 Running the script on the command line
 
Save the script in 1.1. You can save it at any time during editing. After saving, it is a file in jmx format (as shown in the figure). This is the script to be run on the command line (run as a parameter).
This script file may not contain the fourth and fifth steps in 1.1, that is, you do not need to add a listener, and the operation is executed on the command line.
     
 
Go to the path to decompress apache-jmeter-2.13,
The command to execute the Jmeter script is:
./bin/jmeter -n -t .jmx file (script) -l .jtl file (test run result file)
example:
./bin/jmeter -n -t /home/test/Bing interface test sample.jmx -l /home/test/Bing interface test sample.jtl

Parameter Description:

-n means run the test plan in nogui mode

-t means test plan followed by the test plan name

-l indicates the test result, followed by the test result file name


After running, the following interface is displayed, that is, the script is successfully run:
 
  
After running, it will display:
  
Display... end of run That is, the script is finished, and the jtl file entered in the command will appear under the path of the input test run result file.
  
 
2. View test results
Transfer the jtl file generated after the previous step to the path that can be opened by the visual graphical interface, and open the jmeter of the visual graphical interface
 
Just create a new project, you can also use the previous project, add a listener, on the listener interface, click Browse, select the result file .jtl file of the test run, and you can view the results.
  
  
  
After opening the file, the results in the file will be displayed, but only the sampler results in the jtl file obtained by the command given above under linux, the request and corresponding data are empty
  
  
 
Similarly, you can open the jtl file in the aggregate report to view the results:
  
 
Remarks: In addition, under Linux, we sometimes hope that the thread can run in the background, so that after we close the current connection, the thread can still run. Here is a method to set the jmeter command as a background thread.
Use the setsid command: 
 setsid bin/jmeter -n -t .jmx file -l .jtl file
 setsid ./bin/jmeter -n -t .jmx file -l .jtl file
With or without the ./ current directory symbol
 
 
After running, it will display:
Article label:  test development jmeter

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326154110&siteId=291194637
Recommended