JMeter

How to simulate network bandwidth in JMeter?

The rise of the smartphone and easy connectivity to the internet has made access to information easier with most of them accessing websites and web applications from their smartphones.

As a performance engineer, I would like to run my load test on different network speeds like 1 mbps, 4 mpbs, 16 mbps and so on to ensure the app performance.

Why it is needed?

Day by day, mobile traffic over desktop traffic is growing, there is a need to focus on mobile users for performance testing. hence, it is very important to watch how good we are at mobile else it could be lose to business.

Mobile web traffic comprises users with different connection speeds. So, it is very important to perform load testing on mobile apps with different connection speeds.

So it’s time to Throttle Outgoing Bandwidth to Simulate Different Network Speeds.

By default, Jmeter will send the requests to the target server as fast as it can.

Throttling Outgoing Bandwidth to Simulate Different Network Speeds

JMeter has capability to throttle the outgoing bandwidth in order to have different network speed and to achieve that follow the below mentioned steps:

1. Open jmeter.properties file located in /bin folder of JMeter

Simulate Network Speed in JMeter
‘jmeter.properties’ file

2. Search for keyword “cps”

Simulate Network Speed in JMeter
Figure 02: Search with ‘cps’ keyword

3. If you search using “cps” then you will get two properties:

  • httpclient.socket.http.cps=0
  • httpclient.socket.https.cps=0

Remove “#” to enable the properties

Simulate Network Speed in JMeter
Remove ‘#’

The first property simulates the speed when you use HTTP method (protocol) and the second property is used to simulate the speed for HTTPS method.

4. Calculate the value using below formula

CPS = RB * 128

where:
CPS = Characters per second
RB = Required Bandwidth that you need to set for the load test. The input value of required bandwidth should be in kbps.

Simulate Network Speed in JMeter
Calculate and insert the value for CPS (say 64000)

5. Save and close the file. Restart JMeter

Calculating cps value
  • Example if you want to simulate 1000 kbps speed for the test then
    cps = 10000 * 128
    cps = 128000

Note: You need to use the HTTPClient3.1 or HTTPClient4 implementation to be able to adjust the JMeter bandwidth.HTTP Request Defaults is the fastest and easiest way to implement all HTTP Request samplers

If you want to set a bandwidth while executing in non GUI mode, below command can be useful .

jmeter -httpclient.socket.http.cps=<cps value> -n -t <path of .jmx>

Points to remember: 

  • Check the testing environment network bandwidth (where the test to be conducted) before simulating the speed. Because JMeter can only simulate the bandwidth equal to or less than the testing environment network bandwidth.
  • Use RB (Required Bandwidth) value in kbps for CPS calculation.  
  • In a distributed mode, you can set a different bandwidth for each remote engine by specifying your desired ‘cps’ value in the user.properties file to run the test cases.

References:

https://blog.e-zest.com/how-to-simulate-network-bandwidth-in-jmeter

https://medium.com/@priyank.it/jmeter-different-network-speeds-41e7f3d4b7ab

Categories: JMeter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s