JMeter load testing
Load Testing can be used for testing a fixed-load service over HTTPS using the JMeter load generator.
To perform load testing:
- Prepare your cloud.
- Prepare a test target.
- Prepare your infrastructure.
- Create an agent.
- Prepare a file with test data.
- Run a test.
If you no longer need the resources you created, delete them.
Prepare your cloud
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Required paid resources
If the agent is hosted on Yandex Cloud, you pay for computing resources (see Yandex Compute Cloud pricing).
At the Preview stage, Load Testing is free of charge.
Prepare a test target
In this example, we will test a service with the 172.17.0.10
internal IP address in the same subnet as the agent.
Make sure the service is accessed over HTTPS using the default port: 443
.
You can also use Load Testing for load testing of a service that is public or located in a subnet and security group other than those of the agent.
For a public service, allow incoming HTTPS traffic on port 443
.
For a service whose subnet and security group differ from the agent's ones, create a rule for incoming HTTPS traffic on port 443
in the security group where the test target is located.
Prepare the infrastructure
Create a service account
- Create a service account named
sa-loadtest
in the folder to host the agent that will generate the load. - Assign the following roles to the service account:
loadtesting.generatorClient
: Allows running the agent, performing tests on the agent, and uploading the results to storage.compute.admin
: Allows managing VMs in Compute Cloud.vpc.user
: Allows connecting to Virtual Private Cloud network resources and using them.
Configure a network
Create and configure a NAT gateway in the subnet where your test target is and where the agent will reside. This will enable the agent to access Load Testing.
Configure security groups
-
Set up the test agent's security group:
- Create an agent security group named
agent-sg
. - Add rules:
-
Rule for outgoing HTTPS traffic to the Load Testing public API:
- Port range:
443
- Protocol:
TCP
- Destination name:
CIDR
- CIDR blocks:
0.0.0.0/0
This will allow connecting the agent to Load Testing to manage tests from the interface and get test results.
- Port range:
-
Rule for incoming SSH traffic:
- Port range:
22
- Protocol:
TCP
- Destination name:
CIDR
- CIDR blocks:
0.0.0.0/0
This will allow you to connect to the agent over SSH and manage tests from the console or collect debugging information.
- Port range:
-
Rule for outgoing traffic when generating load to the test target:
- Port range:
0-65535
- Protocol:
Any
- Destination name:
Security group
SelectFrom list
. Specify the security group where the test target is located.
Create this rule for each test target with a unique security group.
- Port range:
-
- Create an agent security group named
-
Set up the test target's security group:
-
Create the test target's security group named
load-target-sg
. -
Add a rule for incoming traffic when generating load to the test target:
- Port range:
0-65535
. - Protocol:
Any
. - Select
From list
. Specify the security group where the test target is located.
This rule allows agents to generate load to this target or enable additional monitoring tools.
- Port range:
-
Create a test agent
-
If you do not have an SSH key pair yet, create one.
-
Create an agent.
Management console-
In the management console
, select the folder where you want to create the agent. -
In the list of services, select Load Testing.
-
In the Agents tab, click Create agent.
-
Enter a name for the agent, e.g.,
agent-008
. -
Specify the same availability zone where the test target is located.
-
Under Agent:
- Select the appropriate agent type. For more information, see Agent performance.
- Specify the subnet where the test target is located. Make sure you created and set up a NAT gateway in the subnet.
- If security groups are available to you, select a security group preset for the agent.
-
Under Access, specify the information required to access the agent:
-
Select the
sa-loadtest
service account. -
Under Login, enter the username.
Alert
Do not use
root
or other usernames reserved by the operating system. To perform operations requiring superuser permissions, use thesudo
command. -
In the SSH key field, paste the contents of the public key file.
-
-
Click Create.
-
Wait for the VM instance to create. Make sure the agent status has changed to
Ready for test
.Note
If the agent creation process has stopped at
Initializing connection
, make sure the following conditions are met:- The agent has a public IP address and access to
loadtesting.api.cloud.yandex.net:443
. - A NAT gateway is set up in the target subnet.
- The service account assigned to the agent has the required roles.
- The agent has a public IP address and access to
-
-
Assign a public IP to the agent to enable access over SSH:
Management console- In the management console
, select the folder where the agent is located. - Select Compute Cloud.
- Select the VM named
agent-008
. - Under Network interface, in the top-right corner, click
and select Add public IP address. - In the window that opens:
- In the Public address field, select obtaining a Auto address.
- Click Add.
- In the management console
Prepare your load testing scenario
Create a load testing scenario in the JMeter UI and save it to a .JMX
file. You can learn more in the JMeter documentation
JMeter scenario example
Create a file named test.jmx
and insert the following code into it, specifying the actual IP address of your testing target in the HTTPSampler.domain
field:
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.2">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<stringProp name="LoopController.loops">600</stringProp>
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.delayedStart">false</boolProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
<boolProp name="HTTPSampler.postBodyRaw">false</boolProp>
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">172.17.0.10</stringProp>
<stringProp name="HTTPSampler.path">/test?sleep=100</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.BROWSER_COMPATIBLE_MULTIPART">false</boolProp>
<boolProp name="HTTPSampler.image_parser">false</boolProp>
<boolProp name="HTTPSampler.concurrentDwn">false</boolProp>
<stringProp name="HTTPSampler.concurrentPool">6</stringProp>
<boolProp name="HTTPSampler.md5">false</boolProp>
<intProp name="HTTPSampler.ipSourceType">0</intProp>
</HTTPSamplerProxy>
<hashTree/>
<ConstantThroughputTimer guiclass="TestBeanGUI" testclass="ConstantThroughputTimer" testname="Constant Throughput Timer" enabled="true">
<intProp name="calcMode">1</intProp>
<doubleProp>
<name>throughput</name>
<value>600.0</value>
<savedValue>0.0</savedValue>
</doubleProp>
</ConstantThroughputTimer>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
This example creates a single thread group with one HTTP request (a sleep
request for 100 milliseconds) and sets the IP address of the tested resource. Requests are sent at a rate of 600 requests per minute, and the test duration is 600 requests.
Run a test
-
In the management console
, select Load Testing. -
In the left-hand panel, select
Tests. Click Create test. -
In the Agents field, select
agent-008
. -
Under Attached files, click Choose files and select the scenario file you created earlier.
-
Under Test settings:
-
In the Load generator field, select
JMETER
. -
In the jmx scenario field, select
Attached file
.If you have uploaded multiple files under Attached files, select
Specify file
and in the Attached file name or download URL field, enter the scenario file name. If your scenario is not locally available, specify its download URL here.
-
-
(Optional) In the Override jmx scenario variables menu, you can add variables in the
var=value
format. In this case, custom variables will be passed to the scenario. You can access them as${var}
. -
(Optional) In the JMeter launch parameters menu:
- If you are using a custom JMeter version which you manually copied to the agent, specify the JMeter executable path in the Path to jmeter executable file field.
- In the Additional jmeter launch arguments field, specify the additional arguments: they allow you to use Non-GUI mode launch commands. You can learn more in the JMeter documentation
.
-
In the Autostop menu, click
Autostop and enter the following description:- Autostop type 1:
QUANTILE
- Quantile:
75
- Response time limit:
100ms
- Window duration:
10s
This criterion stops the test if the 75th percentile exceeds 100 milliseconds for 10 seconds (for 10 seconds, the processing time of 25% of queries exceeds 100 milliseconds).
- Autostop type 1:
-
Under Forced test termination time, specify the time to autostop the test unless it is stopped for other reasons. The parameter value should be slightly greater than the expected duration of the test.
-
Under Test information, specify the name, description, and number of the test version. This will make the report easier to read.
-
Click Create.
Once you do that, the configuration will pass checks, and the agent will start loading the service you are testing.
To see the testing progress, select the new test and go to the Test results tab.
How to delete the resources you created
Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need: