Open Model Thread Group in JMeter
Tags: testing, webperf, performance, tutorial
Published: 2022-01-03 17:39:54

<!-- wp:paragraph -->
<p>The Apache JMeter community has been swift in releasing the major security patches for the Log4j fiasco. I have already covered multiple posts about <a href="https://qainsights.com/what-to-do-if-you-cannot-upgrade-to-jmeter-5-4-2-for-log4j-vulnerability/" target="_blank" rel="noreferrer noopener">Log4j vulnerability</a>, <a href="https://qainsights.com/whats-new-in-apache-jmeter-5-4-2/" target="_blank" rel="noreferrer noopener">JMeter 5.4.2</a> and <a href="https://qainsights.com/apache-jmeter-5-4-3/" target="_blank" rel="noreferrer noopener">JMeter 5.4.3</a>. JMeter 5.5 was supposed to be released in the last quarter of 2021. I have already covered <a href="https://qainsights.com/whats-new-in-jmeter-5-5/" target="_blank" rel="noreferrer noopener">what's new in JMeter 5.5</a>. JMeter 5.5 will be released in early January 2022. In this blog post, let us deep-dive into one of the important features, which is the Open Model Thread Group in JMeter 5.5. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>About Open Model Thread Group</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Open Model Thread Group is available starting from JMeter 5.5 under Threads menu when you right click on the Test Plan as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8986,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/01/image.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image.png" alt="Open Model Thread Group in JMeter 5.5" class="wp-image-8986"/></a><figcaption>Open Model Thread Group in JMeter 5.5</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>This is an experimental feature since 5.5 and might change in the future.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Typically, we define the number of threads/users in a Thread Group. There is no thumb rule to follow to utilize the optimum number of threads for a test plan. There are numerous factors that influence the number of threads that a system can spin. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Open Model Thread Group allows a defined pool of threads (users) to run without explicitly mentioning the number of threads.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How to design Open Model Thread Group in JMeter?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Open Model Thread Group </strong>in JMeter accepts a Schedule and an optional Random Seed. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By using the following expressions, we can define the schedule:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>rate</li><li>random arrivals</li><li>pause</li><li>comments</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>rate is nothing but a target load rate in ms, sec, min, hour, and day. e.g. <code>rate(1/min)</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>random_arrivals helps to define the random arrival pattern with the given duration, e.g. <code>random_arrivals(10 min)</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To define a increaing load pattern, first define the starting load rate using rate(), then the random_arrivals(), and at last the ending load rate using rate(). e.g. <code>rate(0/min) random_arrivals(10 min) rate(100/min)</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8988,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-1.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-1-1024x422.png" alt="Increasing Load Pattern" class="wp-image-8988"/></a><figcaption>Increasing Load Pattern</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To define a steady state, use the following expression:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>rate(0/min) random_arrivals(5 min) rate(100/min)
random_arrivals(100 min)
rate(100/min) random_arrivals(5 min) rate(0/min)</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":8989,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-2.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-2-1024x325.png" alt="Steady State" class="wp-image-8989"/></a><figcaption>Steady State</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>For a step by step pattern, use:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>${__groovy((1..10).collect { "rate(" + it*10 + "/sec) random_arrivals(10 sec) pause(1 sec)" }.join(" "))}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">or</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>${__groovy((1..3).collect { "rate(" + it.multiply(10) + "/sec) random_arrivals(10 sec) pause(1 sec)" }.join(" "))}</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":8990,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-3.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-3-1024x292.png" alt="Groovy expression" class="wp-image-8990"/></a><figcaption>Groovy expression</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>JMeter functions are also accepted in the expression. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>pause(2 min) 
rate(${__Random(10,100,)}/min) random_arrivals(${__Random(10,100,)} min) rate(${__Random(10,100,)}/min)
pause(2 min) 
rate(${__Random(10,100,)}/min) random_arrivals(${__Random(10,100,)} min) rate(${__Random(10,100,)}/min)
pause(2 min) 
rate(${__Random(10,100,)}/min) random_arrivals(${__Random(10,100,)} min) rate(${__Random(10,100,)}/min)</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":8991,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-4.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-4-1024x285.png" alt="Random pattern" class="wp-image-8991"/></a><figcaption>Random pattern</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Apart from the above parameters, the expression allows single and multi-line comments.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>/* multi-line comment */
// single line comment
rate(1/min) random_arrivals(10 min) pause(1 min)</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><strong>even_arrivals()</strong> has not implemented feature in Open Model Thread Group. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Open Model Thread Group is executed at the beginning of the test, meaning any functions inside Open Model Thread Group are executed only once; their first result will be used for the execution.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How to use this feature now?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can leverage nightly build to utilize this feature right now. Night build is not reliable for production purpose. To download, head to https://ci-builds.apache.org/job/JMeter/job/JMeter-trunk/lastSuccessfulBuild/artifact/src/dist/build/distributions/</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Sample Workload Model</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Let us design a below workload pattern using the below expressions.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>rate(0/s) random_arrivals(10 s) rate(10/s)
random_arrivals(1 m) rate(10/s)</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The total duration of this test will be 1 min 10 secs. For the first 10 seconds, the rate is 10. Then, for 1 minute, the throughput will be maintained at 10/s.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The maximum throughput is 600/minute. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below is the dummy sampler in the test plan which has random response time of <code>${__Random(2000,2000)}</code> and <code>${__Random(50,500)}</code> respectively.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8993,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-5.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-5.png" alt="Sample Test Plan" class="wp-image-8993"/></a><figcaption>Sample Test Plan</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Since the throughput is 600, this test plan will try to maintain the rate for the two samplers individually, i.e. <code>600+600 = 1200 requests</code>. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Since the first dummy sampler response time is 2000 ms, the test plan will create more threads to maintain the throughput. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below is the aggregate report. Each dummy sampler throughput is 9.4/sec, reaching <code>1280 requests in total</code>. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8994,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/01/image-6.png"><img src="https://qainsights.com/wp-content/uploads/2022/01/image-6-1024x181.png" alt="Sample Report" class="wp-image-8994"/></a><figcaption>Sample Report</figcaption></figure></div>
<!-- /wp:image -->

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

<!-- wp:paragraph -->
<p>Open Model Thread Group will be very helpful in designing a custom load pattern without calculating the number of threads. Functions inside the expression help to generate a dynamic workload model. Using this thread group, no need to calculate the exact number of threads you need for the test as long as the load generators are powerful enough to generate the load pattern. Since it is a new feature, it may have issues. I am still testing this. If you face any problems, please let me know. </p>
<!-- /wp:paragraph -->