Martkos IT Ltd

View Original

JMeter & Redis

Apache JMeter typically uses CSV files for the management of test data. There are numerous other plugins that enable additional methods. One such plugin is the Redis Data Set.

REDIS

Redis is a in-memory data structure store, used as a database, cache and message broker. One of the benefit of using Redis is the ability to amend the data set used in a JMeter test plan while a test is in-flight.

Installation

JMeter Plugin

Download plugins-manager.jar and put it into lib/ext directory, then restart JMeter.

The Redis Data Set plugin within JMeter can be installed using the plugin manager. Click on Options > Plugins Manager and then click on “Available Plugins”. Click in the search box and type “Redis”. Click on the checkbox at the side of the “Redis Data Set” and then click Apply Changes and Restart JMeter.

Redis

Download Redis for your operating system from the redis.io website and install.

Usage

Once installed the Redis Data Set can be found under the Config Element menu named “jp@gc - Redis Data Set”.

In this example we have created a redis key of martkosit and added in a number of cities with the following commands:

localhost> redis-cli

localhost:6379> LPUSH martkosit Sheffield

localhost:6379> LPUSH martkosit Leeds

localhost:6379> LPUSH martkosit Cardiff

localhost:6379> LPUSH martkosit Manchester

localhost:6379> LPUSH martkosit London

Next create a JMeter Test Plan add a Thread Group, jp@gc - Redis Data Set, Dummy Sampler and View Results Tree.

Now navigate to the jp@gc - Redis Data Set and set the following values :-

Redis Key: martkosit

Variable Names: city

Redis server host: localhost

Then navigate to the Dummy Sampler and set the Response Data to ${city}. This is a JMeter variable which we defined in the jp@gc - Redis Data Set and will query redis and return a city value.

When you execute the test you will see that the city value is returned. In this case “Cardiff” but it will also return “Sheffield”, “Leeds”, “London” and “Manchester” in subsequent iterations.

If we leave the test executing you will continue to see the same cities returned. Now if we return to the redis-cli we can add more values while the test is executing. Let’s add “New York”, “L.A” and “Boston”.

localhost> redis-cli

localhost:6379> LPUSH martkosit “New York”

localhost:6379> LPUSH martkosit “L.A”

localhost:6379> LPUSH martkosit “Boston”

As you can see here “Boston” has now been returned. You would also see “L.A” and “New York” as the threads iterate.

What we have shown is the ability to introduce dynamic data sets to a live test. You could extend your data set, remove problem data values and many other scenarios.

FURTHER READING

Blazemeter Redis Introduction

Redis Documentation

Redis Cheatsheet