Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 37 ยท Distributed Testing

Sizing and Tuning JMeter Load Generators

Size JMeter agents correctly: heap and GC settings, threads per CPU core, bandwidth limits, ports and file descriptors, and how to prove the generator is not the bottleneck.

A load generator that is itself overloaded gives wrong results. Response times include the time a thread waited for CPU, garbage collection pauses look like server slowness, and throughput flattens at the generator's limit instead of the application's. Good tests therefore prove that the generator has headroom. This lesson covers JVM settings, a sizing rule of thumb, and the checks that tell you when to add agents. JMeter cannot run here; the Python code is a labelled stand-in for the arithmetic.

What limits one JMeter instance

Resource Symptom when exhausted
CPU threads wait; response times rise as threads increase while the server is idle
Heap memory frequent full GC pauses, OutOfMemoryError
Network bandwidth throughput stops growing; large downloads are capped
Ephemeral ports and file descriptors connection errors such as Address already in use or Too many open files
Disk slow writes when the results file or logs grow fast

JMeter uses one Java thread per virtual user. Threads are cheap compared with browsers, but scripts, assertions and large responses cost CPU and memory.

JVM settings

Edit the HEAP line in bin/jmeter (or set JVM_ARGS):

Terminal
export JVM_ARGS="-Xms2g -Xmx2g -XX:+UseG1GC -XX:MaxGCPauseMillis=100"
jmeter -n -t plan.jmx -l results.jtl
  • Set -Xms equal to -Xmx so the heap does not resize during the run.
  • Do not give JMeter more than about 80 percent of the machine's RAM, and keep the heap small enough that GC stays short. A 4 GB heap with a short GC pause beats an 8 GB heap with long pauses.
  • G1 is the default in modern JDKs and is a good choice. Watch GC logs with -Xlog:gc*:file=gc.log if you suspect pauses.
  • Run with non-GUI mode. The GUI alone can double memory use.

Reduce what each sample costs

  1. Disable or remove View Results Tree, Table, and Graph listeners during real runs.
  2. Save only needed fields in the result file (see jmeter.save.saveservice.* properties). Do not store response bodies unless debugging.
  3. Avoid __BeanShell; use JSR223 samplers with Groovy and cache compilation (tick "Cache compiled script if available").
  4. Avoid regular expressions with heavy backtracking on large bodies; boundary or JSON extractors are cheaper.
  5. Keep assertions focused. A Response Assertion on a 5 MB body is not free.
  6. Use HTTP Request Defaults and Retrieve All Embedded Resources only when the test really needs them; each resource is an extra request.

Rule-of-thumb sizing

There is no fixed number: a plan with 5-second think times uses far fewer resources per user than a tight loop. A practical method is calibration:

  1. Run the real plan against a fast stub or the real system with a small number of threads, for example 50.
  2. Record the CPU use of the generator at that load.
  3. Scale: if 50 threads use 10 percent CPU, you can expect about 300 threads at 60 percent. Add a safety margin and verify.
  4. Keep CPU below roughly 70 to 75 percent and watch the GC time.
Python Stand-in: calibrate threads per agent

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The numbers in this example are made up to illustrate the method; always calibrate with your own plan on your own hardware.

Bandwidth

Large responses (images, downloads, video) saturate a 1 Gbit/s network card quickly. A test with 1,000 users each downloading a 2 MB page every 10 seconds needs about 1.6 Gbit/s. Either distribute across agents on separate network interfaces or avoid downloading content that is not part of what you want to measure (such as third-party CDN assets).

Ports, files and the OS

  • Ephemeral ports: each active TCP connection from the same client to the same server IP and port uses a local port. Linux defaults give about 28,000. Reuse connections with keep-alive (HTTP Request: Use KeepAlive ticked) and widen the range (sysctl net.ipv4.ip_local_port_range) when you open very many short connections.
  • File descriptors: raise ulimit -n (for example 65535) for the user running JMeter.
  • Time-wait: lots of short connections leave sockets in TIME_WAIT; tune kernel settings only after confirming it is the cause.
  • DNS: JMeter caches DNS per thread by default; test plans with many hosts may flood the resolver. Use a DNS Cache Manager if you need control.

Prove the generator is healthy

Run a control test: point the same plan at a trivial local endpoint that answers immediately (a static file on a fast web server). If response times are already high or erratic, the generator is the bottleneck. During the real test, also monitor:

  • CPU and memory of every agent (top, vmstat, a monitoring agent),
  • GC pause time,
  • network interface throughput,
  • the .jtl file's Latency and Connect columns, which expose connection-level issues,
  • the Active Threads Over Time and Response Times vs Threads charts. A plateau in throughput while threads rise points to a limit somewhere.

When any agent exceeds the CPU, memory or network headroom, split the load across more agents rather than tuning forever.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why set -Xms equal to -Xmx?

    A fixed heap prevents resize work while the test is running.
  2. 2. Which CPU level is a sensible upper bound for a load generator?

    Above that, threads wait for CPU and measured response times include generator delays.
  3. 3. How do you check that the generator is not the bottleneck?

    A control test removes the application from the picture and reveals generator limits.
  4. 4. What reduces ephemeral port use for many requests?

    Keep-alive reuses TCP connections, so fewer local ports are consumed.

Summary

  • A saturated generator produces wrong numbers; always keep headroom.
  • Use non-GUI mode, a fixed heap, G1 GC, lean listeners and cached Groovy scripts.
  • Calibrate threads per agent with a probe run, then add a safety margin.
  • Watch CPU, GC, bandwidth, ports and file descriptors on every agent.
  • A control test proves whether the generator or the application is slow.

Next: Reading the Statistics Table