Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Load Testing: Re-connect when MQTT connection lost in connect-and-publish load2 scenario (#2693)

Eric Bariauxbb841d18e430
diff --git a/test/load2-eks/README.md b/test/load2-eks/README.md
index 0f043163c..079a40edc 100644
--- a/test/load2-eks/README.md
+++ b/test/load2-eks/README.md
@@ -62,6 +62,7 @@ Two scenarios are provided:
Runs for a given duration, publishing attribute value changes over MQTT once connected.
For each connection, it publishes ASSETS_COUNT values at the same time (50ms interval), then pauses for MILLIS_BETWEEN_PUBLISHES.
+If a publish fails because the connection is lost and `RECONNECT_ATTEMPTS` is greater than 0, the thread returns to the connect step and retries only while its original per-thread runtime has not yet elapsed. If `RECONNECT_ATTEMPTS` is 0, the thread does not retry and its load is lost.
At the end of publish loop, it waits for DISCONNECT_DELAY before disconnecting from MQTT.
The parameters are:
@@ -71,6 +72,7 @@ ASSETS_COUNT: Number of Light assets for which to publish an attribute during ea
RAMP_RATE: Number of thread to add per second during ramp-up. Default is 20.
DURATION: Total duration to run the test for, in seconds. Default is 300.
MILLIS_BETWEEN_PUBLISHES: Delay between each publishing iteration. Default is 1000.
+RECONNECT_ATTEMPTS: Reconnect control. Default is 0. With the current HiveMQ-based xmeter client, 0 disables automatic reconnect and any positive value enables it using the client's default reconnect configuration. The scenario also uses this setting to control JMeter-level retry behavior: 0 means no reconnect retry loop, any positive value means failed publish loops return to the connect step and retry only until the original per-thread runtime expires, even if connect attempts keep timing out.
DISCONNECT_DELAY: Delay before closing the MQTT connection after publishing loop, in seconds. Default is 0.
#### connect-settle-test
diff --git a/test/load2-eks/scenarios/connect-and-publish.jmx b/test/load2-eks/scenarios/connect-and-publish.jmx
index 4c26ab1a5..52a2fe5a1 100644
--- a/test/load2-eks/scenarios/connect-and-publish.jmx
+++ b/test/load2-eks/scenarios/connect-and-publish.jmx
@@ -27,7 +27,7 @@
</elementProp>
</SetupThreadGroup>
<hashTree>
- <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Setup">
+ <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Setup" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
@@ -57,7 +57,7 @@ props.put(&quot;successes&quot;, new java.util.concurrent.atomic.AtomicInteger(0
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
<stringProp name="ThreadGroup.on_sample_error">startnextloop</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController">
- <stringProp name="LoopController.loops">1</stringProp>
+ <stringProp name="LoopController.loops">${__groovy(((props.get(&quot;RECONNECT_ATTEMPTS&quot;) ?: &quot;0&quot;).toString().toInteger() &gt; 0) ? &quot;-1&quot; : &quot;1&quot;,)}</stringProp>
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
</ThreadGroup>
@@ -72,7 +72,7 @@ import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.NameBasedGenerator;
// Generate asset ids to be used in ForEach controller later
-def assetsCount = vars.get(&quot;ASSETS_COUNT&quot;) ?: &quot;5&quot;
+def assetsCount = props.get(&quot;ASSETS_COUNT&quot;) ?: &quot;5&quot;
def count = assetsCount.toInteger()
for (int i = 1; i &lt;= count; i++) {
def assetId = Url62.encode(Generators.nameBasedGenerator().generate(&quot;masterlight-${__threadNum}-${i}&quot;))
@@ -87,11 +87,19 @@ vars.put(&quot;assetId_matchNr&quot;, count.toString())
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="cacheKey">true</stringProp>
- <stringProp name="script">// Record when this thread started
-vars.putObject(&quot;threadStartTime&quot;, System.currentTimeMillis())
-def duration = (props.get(&quot;DURATION&quot;) ?: &quot;300&quot;).toString().toInteger()
-vars.put(&quot;testDuration&quot;, duration.toString())
-log.info(&quot;&gt;&gt;&gt; Thread ${ctx.getThreadNum()} started, will run for ${duration} seconds&quot;)
+ <stringProp name="script">// Keep a fixed per-thread end time so reconnect attempts do not extend runtime.
+if (vars.getObject(&quot;threadEndTime&quot;) == null) {
+ def startTime = System.currentTimeMillis()
+ def duration = (props.get(&quot;DURATION&quot;) ?: &quot;300&quot;).toString().toInteger()
+ def endTime = startTime + (duration * 1000L)
+ vars.putObject(&quot;threadStartTime&quot;, startTime)
+ vars.putObject(&quot;threadEndTime&quot;, endTime)
+ vars.put(&quot;testDuration&quot;, duration.toString())
+ log.info(&quot;&gt;&gt;&gt; Thread ${ctx.getThreadNum()} started, will run for ${duration} seconds&quot;)
+} else if (System.currentTimeMillis() &gt;= vars.getObject(&quot;threadEndTime&quot;)) {
+ log.info(&quot;&gt;&gt;&gt; Thread ${ctx.getThreadNum()} runtime elapsed before reconnect attempt, stopping thread&quot;)
+ ctx.getThread().stop()
+}
</stringProp>
</JSR223Sampler>
<hashTree/>
@@ -108,17 +116,15 @@ log.info(&quot;&gt;&gt;&gt; Thread ${ctx.getThreadNum()} started, will run for $
<stringProp name="mqtt.client_id_prefix">device${__threadNum}</stringProp>
<boolProp name="mqtt.client_id_suffix">false</boolProp>
<stringProp name="mqtt.conn_keep_alive">30</stringProp>
- <stringProp name="mqtt.conn_attampt_max">0</stringProp>
- <stringProp name="mqtt.reconn_attampt_max">0</stringProp>
<stringProp name="mqtt.conn_clean_session">true</stringProp>
<stringProp name="mqtt.user_name">master:serviceuser${__threadNum}</stringProp>
<stringProp name="mqtt.password">serviceuser${__threadNum}</stringProp>
<stringProp name="mqtt.connect_name">mqttconn</stringProp>
<stringProp name="mqtt.conn_attempt_max">0</stringProp>
- <stringProp name="mqtt.reconn_attempt_max">0</stringProp>
+ <stringProp name="mqtt.reconn_attempt_max">${__P(RECONNECT_ATTEMPTS,0)}</stringProp>
</net.xmeter.samplers.ConnectSampler>
<hashTree>
- <JSR223Timer guiclass="TestBeanGUI" testclass="JSR223Timer" testname="Connect Delay Timer" enabled="false">
+ <JSR223Timer guiclass="TestBeanGUI" testclass="JSR223Timer" testname="Connect Delay Timer" enabled="true">
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
@@ -161,20 +167,14 @@ return delay</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
- <WhileController guiclass="WhileControllerGui" testclass="WhileController" testname="While Controller">
+ <WhileController guiclass="WhileControllerGui" testclass="WhileController" testname="While Controller" enabled="true">
<stringProp name="WhileController.condition">${__groovy(
- def startTime = vars.getObject(&quot;threadStartTime&quot;);
- if (startTime == null) {
- false
- } else {
- def elapsed = (System.currentTimeMillis() - vars.getObject(&quot;threadStartTime&quot;)) / 1000;
- def duration = (vars.get(&quot;testDuration&quot;) ?: &quot;300&quot;).toInteger()
- elapsed &lt; duration;
- }
+ def endTime = vars.getObject(&quot;threadEndTime&quot;);
+ endTime != null &amp;&amp; System.currentTimeMillis() &lt; endTime
)}</stringProp>
</WhileController>
<hashTree>
- <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler">
+ <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
@@ -187,7 +187,7 @@ return delay</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
- <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller">
+ <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller" enabled="true">
<stringProp name="ForeachController.inputVal">assetId</stringProp>
<stringProp name="ForeachController.returnVal">currentAssetId</stringProp>
<boolProp name="ForeachController.useSeparator">true</boolProp>
@@ -228,7 +228,7 @@ log.info(&quot;&gt;&gt;&gt;Direct vars.get currentAssetId = &quot; + vars.get(&q
<hashTree/>
</hashTree>
</hashTree>
- <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Flow Control Action">
+ <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Flow Control Action" enabled="true">
<intProp name="ActionProcessor.action">1</intProp>
<intProp name="ActionProcessor.target">0</intProp>
<stringProp name="ActionProcessor.duration">${__groovy((props.get(&quot;DISCONNECT_DELAY&quot;) ?: &quot;0&quot;).toInteger() * 1000)}</stringProp>
@@ -238,6 +238,12 @@ log.info(&quot;&gt;&gt;&gt;Direct vars.get currentAssetId = &quot; + vars.get(&q
<stringProp name="mqtt.connect_name">mqttconn</stringProp>
</net.xmeter.samplers.DisConnectSampler>
<hashTree/>
+ <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Stop Thread" enabled="true">
+ <intProp name="ActionProcessor.action">0</intProp>
+ <intProp name="ActionProcessor.target">0</intProp>
+ <stringProp name="ActionProcessor.duration"></stringProp>
+ </TestAction>
+ <hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
diff --git a/test/load2-eks/scenarios/connect-and-publish.yml b/test/load2-eks/scenarios/connect-and-publish.yml
index 004b23617..0a7403a0c 100644
--- a/test/load2-eks/scenarios/connect-and-publish.yml
+++ b/test/load2-eks/scenarios/connect-and-publish.yml
@@ -8,6 +8,7 @@ settings:
RAMP_RATE: 20
DURATION: 300
MILLIS_BETWEEN_PUBLISHES: 1000
+ RECONNECT_ATTEMPTS: 0
DISCONNECT_DELAY: 0
reporting:
@@ -29,9 +30,11 @@ modules:
properties:
MANAGER_HOSTNAME: ${MANAGER_HOSTNAME}
THREAD_COUNT: ${THREAD_COUNT}
+ ASSETS_COUNT: ${ASSETS_COUNT}
RAMP_RATE: ${RAMP_RATE}
DURATION: ${DURATION}
MILLIS_BETWEEN_PUBLISHES: ${MILLIS_BETWEEN_PUBLISHES}
+ RECONNECT_ATTEMPTS: ${RECONNECT_ATTEMPTS}
DISCONNECT_DELAY: ${DISCONNECT_DELAY}
execution:
@@ -40,4 +43,3 @@ execution:
scenarios:
simple:
script: connect-and-publish.jmx
-