Hacker News

Subscribe to our RSS here.

JMeter Variables

JMeter

Where are we?

On the last post we created the foundation for investigating the performance of the orderbook service of Mercado Bitcoin, a Brazilian cryptocurrency exchange.

You can download the JMeter suite here.

For this post we will start from a more developed suite.

New suite

In a summary we have:

  • Two Thread Groups: One for the cryptocurrency Litecoin (LTC) and one for Bitcoin (BTC);

  • For each Thread Group we will hit two endpoints:

    • Orderbook: the list of asks and the list of bids
    • Trades: A list of all completed trades, with information such as price, amount, and date.

You can download the updated suite here.

What is the problem?

If you exam closely the new suite we will see that many strings are duplicated in each HTTP Request and Thead Group:

  • The Thread Group configuration values

Thread Group LTC

Thread Group BTC

  • The server name and the HTTP protocol

Server name

Server name

  • The cryptocurrency name

LTC

LTC

  • The path (endpoint) we want to hit

Path

Path

As with any software, duplication is always a code smell: It leads to more effort to implement changes, increases the chance of error, and makes things harder to understand.

Let’s solve this using JMeter Variables!

Variables

JMeter allows creation of variables at the Test Plan level.

In the Test Plan tab we can see an area for the definition of variables

Variables

After the definition we can use the variables through the ${variable_name} notation.

On the Thread Groups:

Variables Usage

Variables Usage 2

And on the HTTP requests:

Variables Usage

Variables Usage 2

Variables Usage

Variables Usage 2

And on run-time, JMeter will translate the placeholder notation with the proper value:

Variables Usage 2

There you have it! The basic configuration values are defined only once, making our suite easy to understand and change.

You can see all posts of this JMeter series here

Leave a comment