Five things to know before learning JMeter
Tags: testing, performance, webperf, tooling
Published: 2021-09-20 16:27:13

<!-- wp:paragraph -->
<p>If you are reading this blog post, most probably you are planning or already planned or just getting started with Apache JMeter. Learning any performance testing tool could be challenging. Sometimes the technical documentation looks abstract, and the learning curve could be steep. In this blog post, I am going to list out five things to know before learning JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>1. JMeter is not a browser</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you consider almost any performance testing tool, it will not execute JavaScript. HTML, CSS, and JavaScript are the essential components for any web page/app. If your application has JavaScript functions embedded in the page, JMeter will not execute that.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>e.g. <a href="https://www.perftractor.xyz/calc.html" target="_blank" rel="noreferrer noopener">PerfTractor calculator</a> app built using pure JavaScript on the web page doesn't send any network calls to the backend server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>On the other hand, Random.org will send the inputs to the backend, then it will display the results.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Here is the HTTP request for random number generation between 33 and 100: https://www.random.org/integers/?num=1&amp;min=33&amp;max=100&amp;col=1&amp;base=10&amp;format=plain&amp;rnd=new</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you are not able to record a few actions using JMeter, it could probably be a JavaScript snippet. Hit Developer tools and debug to confirm.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtube.com/playlist?list=PLJ9A48W0kpRIjLkZ32Do9yDZXnnm7_uj_","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtube.com/playlist?list=PLJ9A48W0kpRIjLkZ32Do9yDZXnnm7_uj_
</div></figure>
<!-- /wp:embed -->

<!-- wp:heading -->
<h2>2. Use CLI mode for testing</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>JMeter has two modes: CLI and Non-CLI. CLI stands for Command Line Interface, alternatively you could call it <em>headless</em>. CLI mode doesn't have any user interface. But Non-CLI mode has a user interface where you can point-and-click and interact with the JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Non-CLI mode should be used for recording, scripting, and smoke testing. This mode utilizes more resources (CPU and memory).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>CLI mode must be used for load testing, stress testing, and other forms of performance testing as well as for CI/CD pipelines. This mode doesn't eat up more resources as there is no user interface to load and render. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But if you have designed your test plan poorly, pretty soon you may end up in Out of Memory error. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Listeners, Assertions, and unnecessary elements in your plan are resource hungry. You must optimize the test plan before starting your test.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://raw.githubusercontent.com/QAInsights/Testing-Jokes-Memes/master/memes/JMeter-Waiting.jpeg" alt="Five things to know before learning JMeter"/><figcaption>Five things to know before learning JMeter</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"38558048"} -->
<h2 class="gb-headline gb-headline-38558048 gb-headline-text">3. Power up using JMeter Plugins</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>The core elements of JMeter help you to build the test plan effectively. But in a few instances, you may need to go beyond the core elements.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Suppose, if you want to design a custom workload model for stress testing, then you can achieve it using JMeter Plugins.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There are 100+ plugins are available via Plugin Manager. Choose wisely and install the relevant plugins which are essential for your test plan.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>JMeter Plugins saves time, and expedites the process of designing, execution, debuggin, and result analysis.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>4. Learn Groovy</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>JMeter core features help us to record, enhance, and execute the test plan. What if you have custom business requirements to accomplish? Well, you could try JMeter plugins or functions. But, what if the plugins or functions do not meet your requirements. Enter JSR223 elements.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The JSR223 element helps you to write custom requirements in Java, JavaScript, Beansheel, Groovy and more. Out of all the languages, I recommend to implement your custom code using the Groovy language.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Groovy is easy to learn, simple to write. If you are stuck, search engine is your friend. Using log.info statement, you can debug, or you could use the IntelliJ IDE.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you have a Java code, you can easily execute it in Groovy. Better performance than the Beanshell sampler. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>5. Distribute your load</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>I often get this question: <em>How many JMeter threads I can run on my laptop?</em> The answer is <em>I don't know</em>. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It depends on too many variables: Operating System specification, system configuration, Java version, JVM settings, JMeter test plan design, number of requests, and so on.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Running the test from one machine induces a bottleneck eventually. Meaning, you cannot increase the resources of your system such as memory, CPU, disk, network after reaching the max limits. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Enter <em>scaling</em>. If you want to inject more load, you need a 'n' number of smaller instances, or one huge instance. I would go with the smaller instances. Because, there is no limit to scale. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Even pricing wise, sometimes smaller instances could save you the budget. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>JMeter comes with a remote distributed load testing framework where you can set a master-worker model to run high volume tests.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/WSDMLAEksz4","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/WSDMLAEksz4
</div></figure>
<!-- /wp:embed -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>There could be many things to know before you get started with JMeter. I have listed what I feel is important to know for beginners. If you think, I missed any important note, please add them in the comment.</p>
<!-- /wp:paragraph -->