Programming Languages in JMeter
Table of Contents
Beginner - This article is part of a series.
I recently published an article at the company where I work Flood.io about JMeter native functions, however, there are other extended functions that can be obtained by installing JMeter plugins, these functions, like the native ones, are written in Java programming language, and here you can see the source code for both:
In theory, any of us with the appropriate knowledge could program our own functions in Java, compile the code, and obtain the output jar file. Once we have the jar file, we could repeat the same process described to install the JMeter plugins and copy the jar to the /lib/ext/ folder. In this handy way, we would have our function available in the tool. Wonderful, right?
The main idea wasn’t all bad, I even made some changes to the first Maciej Zaleski’s Websocket plugin many years ago, this unorthodox method isn’t the only way to get code into the core logic. JMeter natively supports 4 programming languages:
Beanshell #
Since its inception, JMeter integrated its contemporary Beanshell as part of its attributes. At that time, it was a fast and flexible language with a Java-like syntax. In 2003, the project began to lose momentum until it stagnated at its stable version 1.3. It’s been 16 years since its last release, and although there were some efforts to revive and rescue it, minimal improvements were achieved in beta versions. I wouldn’t recommend using Beanshell unless you have a legacy JMeter script that couldn’t be migrated to a more current version. Although I believe the reasons for not using it center on its obsolescence, we can still see people who have a certain appreciation for it and continue to generate utilities for Beanshell.
JavaScript #
JavaScript or ECMAScript is another interpreted programming language, it is not very popular because Beanshell captured most of the attention for many years, but it is quite complete. Some JMeter components use it by definition, such as IF Controller and WHILE Controller for their evaluation statement, contrary to what we might think, this language is not one of the favorites, it is even rare to find examples of JavaScript with JMeter in the cloud.
JEXL #
JEXL is a simple expression language that is based on the Apache Velocity project, in addition to the JSTL 1.1 and JSP 2 definitions. It is basically a small and powerful engine that evaluates statements, personally I use it a lot to evaluate thresholds and divide the workloads of critical flows in scripts, I prefer to use JEXL in conjunction with IF Controllers instead of using Throughput Controller, because in large load volumes many resources can be consumed to maintain the designated load proportions, in short, on a large scale the first solution is more efficient.
Groovy #
It’s easy to understand the popularity of Groovy just by looking at the large number of companies that use it. Ironically, the first release was in 2003, when Beanshell released its latest stable version. Since then, Groovy has grown and established itself as a reliable solution. It’s enough to point out some of its main attributes:
- It’s an object-oriented programming language
- It compiles directly to bytecode, as fast as Java code
- You can use the “caching” feature
- It has periodic improvements and updates
We couldn’t compare Groovy with Javascript or Beanshell, simply because there’s no point in comparing them. Groovy’s features, speed, and community are truly overwhelming. I wouldn’t recommend using any other programming language in JMeter other than Groovy. I plan to do a comparison of efficiency and speed in a future post, so that the advantages of Groovy when it comes to optimizing resources are clearer.