How to Simulate Different Network Speeds in Your JMeter Load Test
Mobile has finally overtaken desktop traffic - and this trend just looks set to rise. But what does this mean for us?
For starters, it means that now, more than ever, we need to focus on mobile users when running performance tests. If our mobile site or application doesn’t perform well - we stand to lose a lot of business.
How to Load Test Mobile Apps and Sites with Different Connection Speeds
In most cases, mobile device users access the internet via their cellular operator network. The coverage will vary depending on their location, meaning the connection speed will vary. It is vital to ensure that your website or application can fully handle mobile and tablets - even when they have different internet connection speeds.
In today’s article, I’ll show you how to do this by controlling the bandwidth of simulated virtual users in a JMeter load test.
By default, JMeter will send the requests defined by its Samplers as fast as it can. This is great for producing the load - but not very realistic as real users don’t hammer the server non-stop, they need some time to think between operations. On top of that, mobile users are limited by network bandwidth, which can slow them down even more.
Throttling Outgoing Bandwidth to Simulate Different Network Speeds
JMeter does give you the option to throttle outgoing bandwidth in order to simulate different network speeds. The bandwidth can be controlled through these two properties:
These are for the HTTP and HTTPS protocols respectively. The properties default to zero, which means no limitations. The acronym “cps” stands for “characters per second”. When you set the properties to something above zero, the bandwidth will be throttled in accordance with your setting.
Here’s the formula of calculating “cps”:
cps = (target bandwidth in kbps * 1024) / 8
For example: to emulate the GPRS cellular network speed (which is 171 Kbits/second downstream), the relevant CPS value would be: 21888 (171 * 1024/8)
So here’s how you can limit the bandwidth through these properties:
1. Add these two lines to the user.properties file (you’ll find this in the bin folder of your JMeter installation)
You’ll need to restart JMeter to pick these properties up
2. Alternatively, you can pass the properties’ values via the -J command line argument, like this:
jmeter -Jhttpclient.socket.http.cps=21888 -Jhttpclient.socket.https.cps=21888 -t /path/to/your/testplan.jmx
Note: if you’re not familiar with JMeter Properties, it’s really worth reading the Apache JMeter Properties Customization Guide for more information.
Now let’s see it in action! I created a very simple test plan, consisting of a:
Thread Group with 100 virtual users and 100 iterations
HTTP Request which sends the GET method to a static HTML page
Aggregate Report listener to allow us to see throughput
As you can see from the above image:
The upper-right JMeter instance works at full LAN speed and throughput is ~1,000 requests per second
The bottom-left JMeter instance has a bandwidth limitation in place, which means that throughput doesn’t go above 180 requests per second
Here are some popular bandwidth presets:
|100 Mb LAN||12800000|
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 run your test in the distributed mode you can set a different bandwidth for each remote engine by specifying your desired “cps” value in the user.properties file
BlazeMeter.com users can either use the above approach (it’s enough to upload your version of the user.properties file along with the test script) or just use the “Network Emulation” settings to set download limit and emulated latency value
I hope that you found this useful! Please share your questions or comments below.
Want to Learn More About JMeter & Load Testing?
If you are new to JMeter, and you’d like to learn more, please sign up for our free online JMeter training course.
For more experienced JMeter users, you'll want to view the on-demand webcast, How to Create Advanced Load Testing Scenarios with JMeter.