Whatever you write as a programmer, will never be valid until you ‘test’ it. Performance and Load Testing is a key part of any testing procedure.
This article is all about Jmeter, a handy tool to do performance and load testing on your Web Applications. With the assumption that you already have some experience using this tool, I’m gonna start off.
JMeter is a 100% pure Java application and obviously, it runs on a JVM. So it is really important that you know how to fine-tune the JVM before doing anything. Since it is out of the scope of this article, I’m not going to talk about it now. You can find a variety of articles and tutorials on JVM Performance Optimisation. Below are a few of them I’ve found useful.
- Tuning Java Virtual Machines (JVMs) – First things first! Never forget the Official Documentation.
- The Principles of Java Application Performance Tuning – This is a bit old but will be a great help to understand processes of the JVM.
- Everything I Ever Learned About JVM Performance Tuning @Twitter – A wonderful presentation by Attila Szegedi, a Software Engineer at Twitter.
One thing to keep in mind is that the performance of any sort of an application always depends on the running environment. Things I’m gonna talk about here are a set of general tips which can improve the performance of any JMeter Test regardless of the running environment.
ALWAYS USE THE NON-GUI MODE
This is sort of an obvious situation which is common for any Java application. GUIs consume more memory and affect heavily on the performance. Running JMeter from a command shell is not hard. Below is a really good article on running JMeter without the GUI.
CONFIGURE JMETER HEAP SIZE
The default heap size allocated to JMeter is 512MB. It’s always good to have 1024MBor more to avoid the java ‘Out of Memory‘ error which is usually thrown when test plans are running at higher concurrency levels.
USAGE OF LISTENERS AND GRAPHS
Try to use as few listeners as possible in your test plan. Never add graphs since they consume a moderately large amount of memory and they do dramatically decrease the performance. Never use “View Results Tree” or “View Results in Table” listeners in your test plan.
USE A DISTRIBUTED SETUP FOR HIGH LOADS
When it comes to tests with very large loads, it is recommended to use a distributed setup to keep the performance at a higher level. As a good practice, it’s always good to have 300-400 threads per JMeter instance, but always remember these numbers profoundly depend on the running environment.
TRY TO USE CSV FILES FOR IO OPERATIONS
Rather than using XML or any other format for input/output file operations, try to use CSV files. CSV uses less CPU and memory compared to other formats. However, minimizing the number of saving and reading operations in your script will definitely improve the performance.
USAGE OF ASSERTIONS AND POST-PROCESSORS
It is always a good practice to use Assertions and Post-Processors only if they’re really needed. This might not affect the performance much, but as a good practice, it’s always better to use a fewer number of these types of components.
Other than these performance-related tips, there are a few good practices to follow when writing and running JMeter test scripts.
- Always use the JMeter latest version.
- Don’t use functional mode.
- Use the most suitable scripting language (JSR223).
- Follow a naming convention when writing scripts. It’s important to maintain the readability of your script.
- Try to write well-parameterized scripts. It will help especially when you’re running scripts in Non-GUI mode.
- Use JMeter logs.