The primary reason for running a load test from Command-line (CLI) mode and not through the GUI mode is that the later can decrease JMeter's capabilities. Using the GUI to run the test can consume additional CPU and memory that can negatively impact the test results. The CLI mode environment is the optimal choice for the test execution and is the recommended methodology by the Apache JMeter team.
Running a test through a command windows might be slightly old school, but it is still very effective.
It is a good testing practice to utilize a pre-test checklist to help get the most effective use of your test time.
Recommended checklist items include:
Since the command-line is utilized for running the Apache JMeter load test, it is advantageous to assemble the actions and environment prep into a batch script (e.g. *.bat file in Windows). This favors repeatability and maintenance.
Using variables are handy ways to improve the maintenance of a script. While hard-coding values is technically fine, it can hinder readability if paths for certain items are very long. The following sections are the primary components our batch will utilize variables.
By default, Apache JMeter (version 5.4.1) runs with a minimum and maximum of 1GB of memory. This is adequate for simple tests running on older machine hardware, but some tests require more complex logic or multiple data files and more memory might be needed to ensure the tests results are not impacted
Note: Many load tests focus on the resource utilization of the server hardware. However, the test client capabilities can also be a bottleneck that limits the ability of accomplish the test goals.
Increasing the default memory can be easily with the following
We want to tell the batch script where to find Apache JMeter and our Test Plan.
Setting the path to the JMeter bin folder is straightforward
As it the (manually created) project folder where the jmx file (e.g. the Test Plan) will reside
For some extendibility, a variable is created for the name of the jmx file separate from the project folder (without the jmx extension and even if they utilize the same name)
For more convenience, a variable is created that will be appended to each run. For multiple reasons, a typical load test can be run several times, with each having a slightly different option enabled within the Test Plan. This can help keep track of different runs of the same test.
Thanks to the utilization of the variables mentioned above, the execution of JMeter with a passed in Test Plan as a command-line switch can easily be reviewed in just a few lines:
%jmeterbin%\jmeter -n -f -t "%projectdir%\%testname%.jmx" ^
-l "%projectdir%\results\results_%testname%_%runname%.jtl" ^
-j "%projectdir%\logs\debug_%testname%_%runname%.log" ^
-e -o "%projectdir%\reports\%testname%_%runname%" ^
The complete batch script is as follows:
echo off
rem Scripted JMeter Test Plan execution
rem Utilizing jmeter.bat for invocation
rem
rem 2021/06/07.1
rem
rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rem *** Variables ***
rem Set JMeter memory to min/max of 4GB (adjust based on your test client resources)
set heap=-Xms4g -Xmx4g -XX:MaxMetaspaceSize=256m
rem Location of %JAVA_HOME%\bin (currently not used)
rem set javadir=C:\jdk-16.0.1\bin
rem Location of Apache JMeter bin
set jmeterbin=C:\apache-jmeter-5.4.1\bin
rem Location of JMeter Test Plan root folder (e.g. the folder where the Test Plan resides)
set projectdir=C:\JMeter Tests\sampleworldcities3
rem Name of the JMeter Test Plan (without the JMX file extension)
set testname=sampleworldcities3
rem String appended to results file of each test run
set runname=run1
rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo on
rem *** Test started ***
%jmeterbin%\jmeter -n -f -t "%projectdir%\%testname%.jmx" ^
-l "%projectdir%\results\results_%testname%_%runname%.jtl" ^
-j "%projectdir%\logs\debug_%testname%_%runname%.log" ^
-e -o "%projectdir%\reports\%testname%_%runname%" ^
rem *** Test completed ***
echo off
For the first first runs of your test, it is recommend to execute it from command window that is already open. This way, if there are immediate issues invoking any the commands in the batch script, they will persist on the screen so they can be corrected more easily (e.g. a typo).
Running from command-line mode does not provide the console with real-time statistics of the test execution. Such functionality can be obtained but is not covered in this Article.
Test artifacts are items created from the load test that can be used for analysis. Items like report and the JMeter Text Logs (JTL) files which contain the raw test results are typically the most important to retain. The run log can also be useful as its listing can be used to confirm the configured memory of the environment for the test run as well as updates to which step was being executed and when. After multiple runs of the same test, where a different runname in the script was used, it is easy to wind up with many jtl files and report folders. This is where following the testing strategy of utilizing a project folder for management is key.
Note: The report generated by JMeter is HTML and JavaScript based. If some components of the report are blank or do not appear to render, try adjusting the security settings of the browser or open in another browser, if available.
To download the Apache JMeter Test Plan used in this Article see: sampleworldcities3.zip
This test requires the Custom Thread Groups plugin to be installed in JMeter.
The generated report is one of the best places to start for conducting analysis in order to determine if the test goals were achieved. Since this analysis of a load test can be an involved process that is worth discussing in detail, it is a procedure that deserves its own Article.
For a set of additional testing tutorials (of increasing complexity), see: Performance Engineering: Load Testing ArcGIS Enterprise
Apache JMeter released under the Apache License 2.0. Apache, Apache JMeter, JMeter, the Apache feather, and the Apache JMeter logo are trademarks of the Apache Software Foundation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.