Scheduler and thread group kinds

A thread group has a start and an end, and a plan can have more than one of them. This lesson uses the three kinds JMeter ships — a setUp group before the load, the ordinary group, a tearDown group after it — and then a group that stops on a clock instead of on a loop count.

setUp, main and tearDown

The setUp group runs before every other group and the tearDown group after them, whatever order the plan puts them in. Each of the three has one request, so the result file has one row from the first group, six from the two users and three loops of the main group, and one from the last.

groups.jmx

<?xml version="1.0" encoding="UTF-8"?> <jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Three thread groups" enabled="true"> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"> <elementProp name="host" elementType="Argument"> <stringProp name="Argument.name">host</stringProp> <stringProp name="Argument.value">127.0.0.1</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="port" elementType="Argument"> <stringProp name="Argument.name">port</stringProp> <stringProp name="Argument.value">8099</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> </collectionProp> </elementProp> </TestPlan> <hashTree> <SetupThreadGroup guiclass="SetupThreadGroupGui" testclass="SetupThreadGroup" testname="setUp Thread Group" enabled="true"> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">1</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">1</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.duration"/> <stringProp name="ThreadGroup.delay"/> </SetupThreadGroup> <hashTree> <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path"/> </ConfigTestElement> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="setUp: health" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path">/health</stringProp> <stringProp name="HTTPSampler.method">GET</stringProp> <boolProp name="HTTPSampler.follow_redirects">true</boolProp> <boolProp name="HTTPSampler.auto_redirects">false</boolProp> <boolProp name="HTTPSampler.use_keepalive">true</boolProp> <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp> <stringProp name="HTTPSampler.connect_timeout"/> <stringProp name="HTTPSampler.response_timeout"/> </HTTPSamplerProxy> <hashTree/> </hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">3</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">2</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.duration"/> <stringProp name="ThreadGroup.delay"/> </ThreadGroup> <hashTree> <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path"/> </ConfigTestElement> <hashTree/> <ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="groups.jtl" enabled="true"> <boolProp name="ResultCollector.error_logging">false</boolProp> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <latency>true</latency> <timestamp>true</timestamp> <success>true</success> <label>true</label> <code>true</code> <message>true</message> <threadName>true</threadName> <dataType>true</dataType> <encoding>false</encoding> <assertions>true</assertions> <subresults>false</subresults> <responseData>false</responseData> <samplerData>false</samplerData> <xml>false</xml> <fieldNames>true</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>false</responseDataOnError> <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> <sentBytes>true</sentBytes> <url>true</url> <threadCounts>true</threadCounts> <idleTime>true</idleTime> <connectTime>true</connectTime> </value> </objProp> <stringProp name="filename">groups.jtl</stringProp> </ResultCollector> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="main: health" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path">/health</stringProp> <stringProp name="HTTPSampler.method">GET</stringProp> <boolProp name="HTTPSampler.follow_redirects">true</boolProp> <boolProp name="HTTPSampler.auto_redirects">false</boolProp> <boolProp name="HTTPSampler.use_keepalive">true</boolProp> <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp> <stringProp name="HTTPSampler.connect_timeout"/> <stringProp name="HTTPSampler.response_timeout"/> </HTTPSamplerProxy> <hashTree/> </hashTree> <PostThreadGroup guiclass="PostThreadGroupGui" testclass="PostThreadGroup" testname="tearDown Thread Group" enabled="true"> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">1</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">1</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.duration"/> <stringProp name="ThreadGroup.delay"/> </PostThreadGroup> <hashTree> <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path"/> </ConfigTestElement> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="tearDown: users" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path">/api/users</stringProp> <stringProp name="HTTPSampler.method">GET</stringProp> <boolProp name="HTTPSampler.follow_redirects">true</boolProp> <boolProp name="HTTPSampler.auto_redirects">false</boolProp> <boolProp name="HTTPSampler.use_keepalive">true</boolProp> <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp> <stringProp name="HTTPSampler.connect_timeout"/> <stringProp name="HTTPSampler.response_timeout"/> </HTTPSamplerProxy> <hashTree/> </hashTree> </hashTree> </hashTree> </jmeterTestPlan>

The plan talks to the course server of the sixth lesson; its whole file is repeated here, so that this page runs on its own.

server.py

#!/usr/bin/env python3 """The target server of the JMeter course: a small JSON API on 127.0.0.1. python3 server.py 8099 Every endpoint is a few lines: the course tests them, it does not test the server. /slow sleeps, /fail answers 500, /login sets a cookie and returns a token, /secure wants that token in an Authorization header. """ import json import sys import time import uuid from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from urllib.parse import parse_qs, urlparse USERS = [{"id": 1, "name": "Ada"}, {"id": 2, "name": "Grace"}, {"id": 3, "name": "Linus"}] TOKEN = "secret-token" class Handler(BaseHTTPRequestHandler): """One request, one small JSON answer.""" protocol_version = "HTTP/1.1" def log_message(self, fmt, *args): """Keep the course\'s server log quiet: every request would be a line.""" def reply(self, status, body, ctype="application/json", headers=None): """Send a body with its length, so a keep-alive client can read it.""" data = body.encode("utf-8") self.send_response(status) self.send_header("Content-Type", ctype) self.send_header("Content-Length", str(len(data))) for name, value in (headers or {}).items(): self.send_header(name, value) self.end_headers() self.wfile.write(data) def reply_json(self, status, value, headers=None): self.reply(status, json.dumps(value), headers=headers) def do_GET(self): url = urlparse(self.path) query = parse_qs(url.query) if url.path == "/": self.reply(200, "<!doctype html><title>course</title><h1>JMeter course</h1>", "text/html") elif url.path == "/health": self.reply_json(200, {"status": "ok"}) elif url.path == "/api/users": self.reply_json(200, {"users": USERS, "count": len(USERS)}) elif url.path.startswith("/api/users/"): user = next((u for u in USERS if str(u["id"]) == url.path.rsplit("/", 1)[-1]), None) self.reply_json(200 if user else 404, user or {"error": "no such user"}) elif url.path == "/items": page = int(query.get("page", ["1"])[0]) self.reply_json(200, {"page": page, "items": [f"item-{page}-{n}" for n in range(1, 4)]}) elif url.path == "/slow": ms = int(query.get("ms", ["300"])[0]) time.sleep(ms / 1000.0) self.reply_json(200, {"slept_ms": ms}) elif url.path == "/fail": self.reply_json(500, {"error": "the server was told to fail"}) elif url.path == "/login": self.reply_json(200, {"token": TOKEN}, headers={"Set-Cookie": "session=abc123; Path=/"}) elif url.path == "/secure": if self.headers.get("Authorization") == "Bearer " + TOKEN: self.reply_json(200, {"message": "welcome"}) else: self.reply_json(401, {"error": "a token is required"}) elif url.path == "/token": self.reply_json(200, {"token": uuid.uuid4().hex}) elif url.path == "/redirect": self.reply(302, "", headers={"Location": "/health"}) elif url.path == "/xml": self.reply(200, "<user><id>1</id><name>Ada</name></user>", "application/xml") elif url.path == "/echo": body = json.dumps({"method": "GET", "path": self.path, "headers": dict(self.headers)}) self.reply(200, body) else: self.reply_json(404, {"error": "not found", "path": url.path}) def do_POST(self): length = int(self.headers.get("Content-Length", "0")) raw = self.rfile.read(length).decode("utf-8") if length else "" if self.path == "/api/orders": try: order = json.loads(raw) if raw else {} except json.JSONDecodeError: self.reply_json(400, {"error": "the body is not JSON"}) return self.reply_json(201, {"id": 1001, "received": order}) else: self.reply_json(404, {"error": "not found", "path": self.path}) if __name__ == "__main__": port = int(sys.argv[1]) if len(sys.argv) > 1 else 8099 server = ThreadingHTTPServer(("127.0.0.1", port), Handler) print(f"listening on 127.0.0.1:{port}", flush=True) server.serve_forever()

python3 server.py 8099 &

jmeter -n -t groups.jmx -l groups.jtl -j groups.log

Creating summariser <summary>
Created the tree successfully using groups.jmx
Starting standalone test @ 2026 Nov 25 05:32:16 GMT (1795584736371)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary =      8 in 00:00:01 =    7.0/s Avg:    47 Min:     2 Max:   190 Err:     0 (0.00%)
Tidying up ...    @ 2026 Nov 25 05:32:17 GMT (1795584737751)
... end of run

wc -l groups.jtl

9 groups.jtl

head -2 groups.jtl | tail -1 | cut -d, -f3

setUp: health

The first row of the file is the setUp request, and the last row is the tearDown one: the order of the rows is the order of the run, and it is stable even though the timestamps are not. A plan uses a setUp group for the data every user needs, such as a login, and a tearDown group for the clean-up that must happen once.

A run that stops on a clock

The Scheduler checkbox turns the duration and the start delay of a thread group on. With the loop count at -1 (forever) and a duration of two seconds, the group runs until the clock says stop, and the number of samples depends on how fast the server answers: no page can print that count as a fixed line.

sched.jmx

<?xml version="1.0" encoding="UTF-8"?> <jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="A timed run" enabled="true"> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"> <elementProp name="host" elementType="Argument"> <stringProp name="Argument.name">host</stringProp> <stringProp name="Argument.value">127.0.0.1</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="port" elementType="Argument"> <stringProp name="Argument.name">port</stringProp> <stringProp name="Argument.value">8099</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> </collectionProp> </elementProp> </TestPlan> <hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">true</boolProp> <stringProp name="LoopController.loops">-1</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">2</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> <boolProp name="ThreadGroup.scheduler">true</boolProp> <stringProp name="ThreadGroup.duration">2</stringProp> <stringProp name="ThreadGroup.delay">1</stringProp> </ThreadGroup> <hashTree> <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path"/> </ConfigTestElement> <hashTree/> <ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="sched.jtl" enabled="true"> <boolProp name="ResultCollector.error_logging">false</boolProp> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <latency>true</latency> <timestamp>true</timestamp> <success>true</success> <label>true</label> <code>true</code> <message>true</message> <threadName>true</threadName> <dataType>true</dataType> <encoding>false</encoding> <assertions>true</assertions> <subresults>false</subresults> <responseData>false</responseData> <samplerData>false</samplerData> <xml>false</xml> <fieldNames>true</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>false</responseDataOnError> <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> <sentBytes>true</sentBytes> <url>true</url> <threadCounts>true</threadCounts> <idleTime>true</idleTime> <connectTime>true</connectTime> </value> </objProp> <stringProp name="filename">sched.jtl</stringProp> </ResultCollector> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="health" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">${host}</stringProp> <stringProp name="HTTPSampler.port">${port}</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"/> <stringProp name="HTTPSampler.path">/health</stringProp> <stringProp name="HTTPSampler.method">GET</stringProp> <boolProp name="HTTPSampler.follow_redirects">true</boolProp> <boolProp name="HTTPSampler.auto_redirects">false</boolProp> <boolProp name="HTTPSampler.use_keepalive">true</boolProp> <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp> <stringProp name="HTTPSampler.connect_timeout"/> <stringProp name="HTTPSampler.response_timeout"/> </HTTPSamplerProxy> <hashTree/> </hashTree> </hashTree> </hashTree> </jmeterTestPlan>

The command below runs the plan and keeps only the lines of the output that are stable, because the summary line of a timed run is not. The exit status is the one of JMeter itself, which the pipe would otherwise hide.

jmeter -n -t sched.jmx -l sched.jtl -j sched.log | grep -v '^summary'; echo "exit status: ${PIPESTATUS[0]}"

Creating summariser <summary>
Created the tree successfully using sched.jmx
Starting standalone test @ 2026 Nov 25 05:32:22 GMT (1795584742731)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
Tidying up ...    @ 2026 Nov 25 05:32:26 GMT (1795584746242)
... end of run
exit status: 0

Two things about the run are stable and worth printing: two users were running at once, and the run lasted at least a second and a half between its first and its last sample. The delay of one second is not in that span, because the first sample comes after it.

awk -F, 'NR > 1 && $13 > m { m = $13 } END { print "most threads at once:", m }' sched.jtl

most threads at once: 2

awk -F, 'NR > 1 { if (min == "" || $1 < min) min = $1; if ($1 > max) max = $1 } END { print (max - min >= 1200 ? "at least 1.2 s of samples" : "shorter than 1.2 s") }' sched.jtl

at least 1.2 s of samples

The properties that matter

The thread group and the clock
FieldWhat it does
Number of Threadshow many users run at the same time
Ramp-Up Periodthe seconds over which they all start
Loop Counthow many times each user runs its block; -1 is forever
Delay Thread creation until neededstart each user when the ramp-up reaches it, not all at the start
Schedulerread the two fields below; without it they are ignored
Durationhow many seconds the group runs after the delay
Startup delayhow many seconds to wait before the first user starts

Related

Автор статьи: Arthur Isaev