Measuring Heap Memory Consumption per HTTP Request in SpringBoot Applications
This article presents a systematic experiment that uses JMeter to generate HTTP requests against a SpringBoot 2.5.4 service, records detailed GC logs, and calculates that each HTTP call consumes roughly 34 KB of heap memory, while logging and payload size can significantly increase the allocation.
In practical backend development, full‑link performance testing and JVM GC tuning are essential for high‑concurrency services. By knowing the heap memory required for a single RPC or HTTP request, one can predict total heap demand and GC frequency under a given load.
Experiment Idea : Create a minimal SpringBoot 2.5.4 application, expose a POST endpoint for JMeter to call, enable detailed GC logging, and measure the heap growth of the young generation after a fixed number of requests.
Key Steps :
Create a new SpringBoot project (version 2.5.4 ).
Add a POST endpoint /create and a GET endpoint /gc that triggers System.gc() .
Configure a JMeter test plan with 10 threads, each performing 2000 POST calls (total 20 000 requests).
Start the application with a 4 GB heap (young generation 2 GB) and GC log options such as -Xloggc:/Users/testUser/log/gc.log and detailed GC flags.
The controller code used in the experiment:
@Slf4j
@RestController
public class TestController {
private AtomicLong count = new AtomicLong(0);
@ResponseBody
@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@RequestBody Order order) {
//log.warn("Received order cnt{}:{}", count.getAndIncrement(), order);
return "ok";
}
@ResponseBody
@RequestMapping(value = "gc", method = RequestMethod.GET)
public String gc() {
System.gc();
return "ok";
}
}After executing the JMeter plan, the GC logs show that the Eden space of the young generation returns to zero, indicating that the total memory allocated during the 20 000 HTTP calls equals the Eden usage before the GC. The measured average heap allocation per HTTP request is about 34 KB , even though the request body contains only 50 characters.
Increasing the request payload (e.g., setting the detail field to 1200 characters) raises the average allocation to 36 KB , confirming that payload size contributes roughly proportionally to heap usage.
Enabling detailed request logging adds another 20 KB per request (average 56 KB), demonstrating that log volume can significantly affect memory consumption and GC frequency.
In a production environment, the author observes RPC calls consuming between 0.5 MB and 1 MB due to complex business logic, multiple downstream calls, and extensive logging, which can trigger frequent young GCs when concurrency reaches hundreds of requests per second.
Conclusion : A single SpringBoot HTTP request typically allocates around 34 KB of heap memory; logging and larger payloads increase this figure. Controlling log size and understanding per‑request memory footprints are crucial for capacity planning and GC tuning in high‑throughput backend services.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.