How Much Heap Memory Does a Single SpringBoot HTTP Request Use? A Practical Experiment
This article shows how a senior architect measured the exact heap memory allocated by individual HTTP and RPC requests in a SpringBoot 2.5.4 application using JMeter load testing and detailed GC logs, revealing that a minimal HTTP call consumes about 34 KB while an RPC call can use up to 1 MB, and discusses the performance implications of payload size and logging.
In this article a senior architect demonstrates how to measure the heap memory allocated by a single HTTP or RPC request in a SpringBoot 2.5.4 application.
Experiment Idea
By creating a simple SpringBoot service with a POST endpoint and a GET endpoint that triggers manual GC, and using JMeter to send 20,000 HTTP calls (10 threads × 2,000 calls), the GC logs are analyzed to calculate the memory growth of the young generation.
Steps
Create a new SpringBoot 2.5.4 project.
Add a POST /create endpoint and a GET /gc endpoint.
Configure JMeter with 10 threads, each looping 2,000 times, and set the Content‑Type header to application/json.
Enable detailed GC logging (e.g., -Xloggc:/path/gc.log) and start the application with a 4 GB heap (2 GB young generation, SurvivorRatio=8).
Before the load test run a manual curl http://localhost:8080/gc to clear existing objects.
Run the JMeter test, then trigger a manual GC and examine the GC log to obtain the Eden space increase, which equals the total memory allocated by the 20,000 HTTP calls.
Key Code
@Slf4j
@RestController
public class TestController {
private AtomicLong count = new AtomicLong(0);
@ResponseBody
@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@RequestBody Order order) {
return "ok";
}
@ResponseBody
@RequestMapping(value = "gc", method = RequestMethod.GET)
public String gc() {
System.gc();
return "ok";
}
}Results
The experiment shows that a single HTTP request in this minimal SpringBoot service consumes about 34 KB of heap memory, even though the request body contains only 50 characters. Adding a larger detail field (≈1.2 KB) increases the consumption to ~36 KB, confirming that most of the allocation comes from internal object creation rather than the payload.
When a log statement is added inside the controller, the average memory usage rises to ~56 KB, demonstrating that excessive logging can significantly increase per‑request memory pressure and trigger more frequent GC cycles.
In a production environment the same measurement for an RPC call yields between 0.5 MB and 1 MB per request, due to additional layers such as downstream calls, SQL queries, cache accesses and logging.
Practical Implications
Knowing the exact heap cost per request allows you to calculate the required heap size for a given concurrency level. For example, with a 0.5 MB cost per RPC and 500 requests per second, the application would allocate roughly 15 GB of memory per minute, necessitating multiple young‑generation GCs to avoid pauses.
Therefore, it is advisable to keep request payloads small, limit log volume, and tune GC parameters (heap size, survivor ratio, etc.) to achieve optimal performance.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
