Load Testing with Postman, Apache Bench, JMeter, and Java Concurrency Utilities
This article explains how to perform HTTP load testing using Postman, Apache Bench, JMeter, and Java concurrency classes such as CountDownLatch and Semaphore, providing step‑by‑step setup, configuration, and code examples for simulating high‑traffic scenarios.
The article introduces several popular tools for HTTP load testing, including Postman, Apache Bench (ab), JMeter, and Java concurrency utilities, and demonstrates how to use each of them to generate and measure traffic against a Spring Boot endpoint.
For Postman, a simple Spring Boot controller is created (see code below) and the tool’s environment variable (e.g., http://127.0.0.1:8080 ) is configured. The author shows how to open the global settings, input the base URL, and run a concurrency test, illustrating the generated logs and CPU usage.
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("test")
public class TestConrtoller {
@GetMapping("demo")
public String testDemo() {
return "result~";
}
}Apache Bench is presented as a lightweight command‑line load generator. The guide walks through downloading the Apache HTTP Server on Windows, editing httpd.conf (DocumentRoot, ServerName, and listening port), installing the service with httpd.exe -k install , and starting it with httpd.exe -k start . The basic usage of ab is shown, where -n specifies the total number of requests and -c the level of concurrency.
httpd.exe -k install httpd.exe -k startJMeter, a graphical load‑testing tool, requires Java 8+. After downloading and extracting JMeter, the user launches jmeter.bat , creates a Thread Group, adds an HTTP Request sampler, and attaches listeners such as “Graph Results” and “View Results Tree”. The article includes screenshots of the UI and explains how to run the test and interpret the results.
The article then shifts to Java concurrency primitives. It explains the purpose of CountDownLatch (a one‑time latch) and its constructor, as well as the three key methods await() , await(long, TimeUnit) , and countDown() . It also describes Semaphore , which controls access to a limited number of permits via acquire() and release() .
public CountDownLatch(int count) { /* count is the initial latch value */ }
public void await() throws InterruptedException { /* blocks until count reaches 0 */ }
public boolean await(long timeout, TimeUnit unit) throws InterruptedException { /* blocks up to timeout */ }
public void countDown() { /* decrements count */ }Finally, a complete Java example demonstrates how to simulate 5,000 requests with 200 concurrent threads using an ExecutorService , a Semaphore , and a CountDownLatch . The code logs the final request count, highlighting that the shared count variable is not thread‑safe, which leads to incorrect results.
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.*;
@Slf4j
public class CuncurrencyTest {
public static int clientTotal = 5000;
public static int threadTotal = 200;
public static int count = 0;
public static void main(String[] args) throws InterruptedException {
ExecutorService executorService = Executors.newCachedThreadPool();
final Semaphore semaphore = new Semaphore(threadTotal);
final CountDownLatch countDownLatch = new CountDownLatch(clientTotal);
for (int i = 0; i < clientTotal; i++) {
executorService.execute(() -> {
try {
semaphore.acquire();
add();
semaphore.release();
} catch (InterruptedException e) {
e.printStackTrace();
log.error("exception", e);
}
countDownLatch.countDown();
});
}
countDownLatch.await();
executorService.shutdown();
log.info("count:{}", count);
}
private static void add() {
count++;
}
}The author notes that while CountDownLatch and Semaphore are useful for load‑testing simulations, they have broader applications in Java concurrency and will be covered in more depth in future articles.
Top Architecture Tech Stack
Sharing Java and Python tech insights, with occasional practical development tool tips.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.