JMeter load testing
You can use Load Testing to run fixed-load tests of a service over HTTPS using the JMeter load generator.
To run a load test:
- Get your cloud ready.
- Prepare a test target.
- Set up your infrastructure.
- Create an agent.
- Prepare a file with test data.
- Run the test.
If you no longer need the resources you created, delete them.
Get your cloud ready
Sign up in Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or register a new account. - 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 and link a cloud to it.
If you have an active billing account, you can navigate 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 where the agent will reside.
Make sure the service is accessed over HTTPS using the default port: 443
.
You can also use Load Testing for 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 is different 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.
Set up your infrastructure
Create a service account
- Create a service account named
sa-loadtest
in the folder that will host the agent to generate the load. - Assign the
loadtesting.generatorClient
role to the service account.
Configure your network
Create and configure a NAT gateway in the subnet hosting your test target and where the agent will reside. This will enable the agent to access Load Testing.
Configure security groups
-
Configure the test agent security group:
- Create an agent security group named
agent-sg
. - Add rules:
-
Rule for outbound 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 you to connect the agent to Load Testing to manage tests from the interface and get test results.
- Port range:
-
Inbound SSH traffic rule:
- 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 outbound traffic when generating load to the test target:
- Port range:
0-65535
. - Protocol:
Any
. - Destination name:
Security group
.
SelectFrom list
. Specify the security group comprising the test target.
Create this rule for each test target with a unique security group.
- Port range:
-
- Create an agent security group named
-
Configure the test target security group:
-
Create a test target security group named
load-target-sg
. -
Add a rule for inbound traffic when generating load to the test target:
- Port range:
0-65535
. - Protocol:
Any
. - Destination name:
Security group
.
SelectFrom list
. Specify the security group comprising the test target.
This rule allows agents to generate load to the test target or use 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 consoleCLI-
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 as the one hosting your test target.
-
Under Agent:
- Select the appropriate agent type. For more information, see Agent performance.
- Specify the subnet hosting your test target. Make sure you created and set up a NAT gateway in that subnet.
- If you have access to security groups, select a preset agent security group.
-
Under Access, specify the agent access credentials:
-
Select the
sa-loadtest
service account. -
Under Login, enter the username.
Alert
Do not use
root
or other reserved usernames. To perform operations requiring root privileges, use thesudo
command. -
In the SSH key field, paste the contents of the public key file.
-
-
Click Create.
-
Wait for the VM 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
. - The target subnet has a configured NAT gateway.
- The service account assigned to the agent has the required roles.
- The agent has a public IP address and access to
If you do not have the Yandex Cloud CLI yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the
yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the--folder-name
or--folder-id
parameter.-
See the description of the CLI command for creating an agent:
yc loadtesting agent create --help
-
Select the same availability zone as the one hosting your test target.
-
Select the subnet hosting your test target. Make sure you created and set up a NAT gateway in that subnet.
To get a list of available subnets using the CLI, run this command:
yc vpc subnet list
Result:
+----------------------+---------------------------+----------------------+----------------+-------------------+-----------------+ | ID | NAME | NETWORK ID | ROUTE TABLE ID | ZONE | RANGE | +----------------------+---------------------------+----------------------+----------------+-------------------+-----------------+ | e2lfkhps7bol******** | default-ru-central1-b | enpnf7hajqmd******** | | ru-central1-b | [10.129.0.0/24] | | e9bgnq1bggfa******** | default-ru-central1-a | enpnf7hajqmd******** | | ru-central1-a | [10.128.0.0/24] | | fl841n5ilklr******** | default-ru-central1-d | enpnf7hajqmd******** | | ru-central1-d | [10.130.0.0/24] | +----------------------+---------------------------+----------------------+----------------+-------------------+-----------------+
-
Select the security group. Make sure to configure the security group in advance.
To get a list of available security groups using the CLI, run this command:
yc vpc security-group list
Result:
+----------------------+---------------------------------+--------------------------------+----------------------+ | ID | NAME | DESCRIPTION | NETWORK-ID | +----------------------+---------------------------------+--------------------------------+----------------------+ | enp414a2tnnp******** | default-sg-enpnf7hajqmd******** | Default security group for | enpnf7hajqmd******** | | | | network | | | enpctpve7951******** | sg-load-testing-agents | | enpnf7hajqmd******** | | enpufo9ms0gi******** | sg-load-testing-targets | | enpnf7hajqmd******** | +----------------------+---------------------------------+--------------------------------+----------------------+
-
Get the ID of
sa-loadtest
service account, specifying its name:yc iam service-account get sa-loadtest
Result:
id: ajespasg04oc******** folder_id: b1g85uk96h3f******** created_at: "2024-12-04T17:38:57Z" name: sa-loadtest last_authenticated_at: "2024-12-12T19:10:00Z"
-
Create an agent in the default folder:
yc loadtesting agent create \ --name agent-008 \ --labels origin=default,label-key=label-value \ --zone default-ru-central1-a \ --network-interface subnet-id=e9bgnq1bggfa********,security-group-ids=enpctpve7951******** \ --cores 2 \ --memory 2G \ --service-account-id ajespasg04oc******** --metadata-from-file user-data=metadata.yaml
Where:
--name
: Agent name.--labels
: Agent labels.--zone
: Availability zone to host the agent.--network-interface
: Agent network interface settings:subnet-name
: ID of the selected subnet.security-group-ids
: Security group IDs.
--cores
: Number of CPU cores the agent can use.--memory
: Amount of RAM allocated to the agent.--service-account-id
: Service account ID.--metadata-from-file
:<key>=<value>
pair with the name of the file containing the public SSH key path. For an example of themetadata.yaml
configuration file, see VM metadata.
For more information on how to create an agent with the CLI, see the Yandex Cloud Examples repository
.
-
-
Assign a public IP address to your agent to enable access over SSH:
Management consoleCLI- In the management console
, select the folder with the agent. - Select Compute Cloud.
- Select the
agent-008
VM. - 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 Auto.
- Click Add.
To assign a public IP address to an agent, run the following CLI command:
yc compute instance add-one-to-one-nat \ --id=<VM_ID> \ --network-interface-index=<VM_network_interface_number> \ --nat-address=<IP_address>
Where:
-
--id
: VM ID. You can get a list of available VM IDs in the folder using theyc compute instance list
CLI command. -
--network-interface-index
: VM network interface number. The default value is0
. To get a list of VM network interfaces and their numbers, runyc compute instance get <VM_ID>
. -
--nat-address
: Public IP address to assign to the VM. This is an optional setting. If you skip it, the VM will get a public IP address automatically.You can get a list of reserved public IP addresses available in the folder using the
yc vpc address list
CLI command. The IP address and the VM must be in the same availability zone.
Here is a possible use case:
yc compute instance add-one-to-one-nat \ --id=fhmsbag62taf******** \ --network-interface-index=0 \ --nat-address=51.250.*.***
Result:
id: fhmsbag62taf******** folder_id: b1gv87ssvu49******** created_at: "2022-05-06T10:41:56Z" ... network_settings: type: STANDARD placement_policy: {}
For more information about the
yc compute instance add-one-to-one-nat
command, see the CLI reference. - 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. Learn more in the JMeter documentation
JMeter scenario example
Create a file named test.jmx
and paste the following code into it, specifying the actual IP address of your test 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>
In this example, we are creating a single thread group with one HTTP request (a sleep
request for 100 milliseconds) and setting the IP address of the resource to test. The request rate is 600 requests per minute, and the test duration is 600 requests.
Run the 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.
-
-
Optionally, in the Override jmx scenario variables menu, you can add variables in
var=value
format. In this case, custom variables will be provided to the scenario. You can access them as${var}
. -
Optionally, 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. 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 time to process 25% of requests exceeds 100 milliseconds).
- Autostop type 1:
-
Under Forced test termination time, specify the time after which the test will autostop, unless it is stopped for other reasons. Set it to be slightly greater than the expected test duration.
-
Under Test information, specify the name, description, and number of the test version. This will make the report easier to read.
-
Click Create.
Next, the configuration will be checked, and the agent will start loading the service.
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: