<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amber Race</title>
    <description>The latest articles on DEV Community by Amber Race (@ambertests).</description>
    <link>https://dev.to/ambertests</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F35030%2Fddbf5681-e26a-42a7-bf0f-3d9f3738b99f.jpeg</url>
      <title>DEV Community: Amber Race</title>
      <link>https://dev.to/ambertests</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ambertests"/>
    <language>en</language>
    <item>
      <title>Creating Weighted Flows in JMeter</title>
      <dc:creator>Amber Race</dc:creator>
      <pubDate>Mon, 15 Apr 2019 01:42:07 +0000</pubDate>
      <link>https://dev.to/ambertests/creating-weighted-flows-in-jmeter-354d</link>
      <guid>https://dev.to/ambertests/creating-weighted-flows-in-jmeter-354d</guid>
      <description>&lt;p&gt;It is pretty common for applications to have multiple flow paths. For example, it is common in mobile games to have one call flow for players that have authenticated with Facebook and a very different one for anonymous players. When trying to replicate a realistic server load in JMeter, it is important to be able to handle these different paths that users take through the client application.&lt;/p&gt;

&lt;p&gt;JMeter actually has this capability right out of the box, no Groovy scripting or secondary plugins needed. With a &lt;strong&gt;Random Variable&lt;/strong&gt; and a few &lt;strong&gt;If Controllers&lt;/strong&gt;, you can enable any number of different flow paths in your load testing script.&lt;/p&gt;

&lt;h2&gt;Flip a Coin&lt;/h2&gt;

&lt;p&gt;Let's start with the simplest scenario: two paths which you want evenly split in your test. To do this, first add Random Variable element that will generate a number between 1 and 2 Be sure to set the Per Thread option to True so the coin gets flipped on each of your user threads.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kTiIuWLg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4dvnqt7vce2qwgpllbu5.png" class="article-body-image-wrapper"&gt;&lt;img class="alignnone  wp-image-255" src="https://res.cloudinary.com/practicaldev/image/fetch/s--kTiIuWLg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4dvnqt7vce2qwgpllbu5.png" alt="JMeter Coin Flip" width="298" height="249"&gt;&lt;/a&gt;&lt;/p&gt;
JMeter Coin Flip



&lt;p&gt;Next add two If Controllers to hold your two paths.&lt;/p&gt;

&lt;h5&gt;Condition A:&lt;/h5&gt;

&lt;pre&gt;${COIN_FLIP} == 1&lt;/pre&gt;

&lt;h5&gt;Condition B:&lt;/h5&gt;

&lt;pre&gt;${COIN_FLIP} == 2&lt;/pre&gt;

&lt;p&gt;And that is all you need to do - simple! You can use this same strategy to split your test up evenly among any number of paths; just increase the Maximum Value of your Random Variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8WBFKy5F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qgwbnbbibbxthlcypl62.png" class="article-body-image-wrapper"&gt;&lt;img class="alignnone  wp-image-267" src="https://res.cloudinary.com/practicaldev/image/fetch/s--8WBFKy5F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qgwbnbbibbxthlcypl62.png" alt="JMeter Straws" width="503" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Percentage A/B&lt;/h2&gt;

&lt;p&gt;What about when you have two different paths, but one is more common than the other? And what if you want to test different ratios of the A and B paths? In that situation, I've used the following technique:&lt;/p&gt;

&lt;p&gt;First, add a User Defined Variable element to your script to track what percentage of iterations should go through the A flow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E2-sNeeD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5ydfzf25ke06y2p0kqt8.png" class="article-body-image-wrapper"&gt;&lt;img class="alignnone  wp-image-287" src="https://res.cloudinary.com/practicaldev/image/fetch/s--E2-sNeeD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5ydfzf25ke06y2p0kqt8.png" alt="PCT_A" width="283" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then set your Random Variable to have a max value of 100.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jVeNWoEw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0gvfrzm879b0lxn42z95.png" class="article-body-image-wrapper"&gt;&lt;img class="alignnone  wp-image-322" src="https://res.cloudinary.com/practicaldev/image/fetch/s--jVeNWoEw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0gvfrzm879b0lxn42z95.png" alt="Random Is A" width="288" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we go to our If Controllers and in the one for the &lt;em&gt;A&lt;/em&gt; path, put the following condition:&lt;/p&gt;

&lt;pre&gt;${IS_A} &amp;lt;= ${PCT_A}&lt;/pre&gt;

&lt;p&gt;And in the &lt;em&gt;Not A&lt;/em&gt; path, put the opposite:&lt;/p&gt;

&lt;pre&gt;${IS_A} &amp;gt; ${PCT_A}&lt;/pre&gt;

&lt;p&gt;And &lt;em&gt;voilà&lt;/em&gt;, a near perfect split between the two paths based on the given percentage. If you are feeling really saucy, you can set the PCT_A value as a property that is passed in on the command-line. But that is a topic for another post.&lt;/p&gt;

&lt;h2&gt;Example File&lt;/h2&gt;

&lt;p&gt;A script illustrating all these examples is available here: &lt;a href="https://github.com/ambertests/JMeterExamples/blob/master/WeightedFlows.jmx" rel="noopener"&gt;WeightedFlows.jmx&lt;/a&gt;. If there is another example you would like to see, please let me know!&lt;/p&gt;



&lt;p&gt;&lt;i&gt;Originally posted &lt;a href="https://ambertests.com/2017/03/21/creating-weighted-flows-in-jmeter/" rel="noopener"&gt;here&lt;/a&gt;&lt;/i&gt;&lt;/p&gt;

</description>
      <category>jmeter</category>
      <category>performance</category>
      <category>load</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
