Backend Development 11 min read

Measuring Heap Memory Consumption of HTTP and RPC Requests in a SpringBoot Application

This article details a step‑by‑step experiment using SpringBoot 2.5.4 and JMeter to quantify how much heap memory a single HTTP or RPC request consumes, analyzes GC logs, presents code snippets for the test endpoints, and discusses the impact of logging and payload size on memory usage.

Top Architect
Top Architect
Top Architect
Measuring Heap Memory Consumption of HTTP and RPC Requests in a SpringBoot Application

1. Experiment Idea

In real‑world services we often need to perform full‑link stress testing and tune GC parameters; knowing the heap memory required for a single RPC or HTTP request allows precise calculation of required heap size and GC frequency.

2. Key Actions

Create a new SpringBoot 2.5.4 application.

Add a POST endpoint ( @RequestMapping(value="create", method=RequestMethod.POST) ) and a GET endpoint ( @RequestMapping(value="gc", method=RequestMethod.GET) ) that triggers System.gc() .

Configure a JMeter test plan: 10 threads, each looping 2000 times (total 20,000 HTTP calls).

Enable detailed GC logging in the JVM to capture new‑generation memory allocation before and after each GC.

3. SpringBoot HTTP Interface Declaration

@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";
    }
}

4. JMeter Test Plan

Thread Group: 10 threads, each performing 2000 iterations. HTTP Request Defaults: set the target URL. Header Manager: add Content-Type: application/json . HTTP Request: configure URL and JSON body.

5. Experiment Process

5.1 Start SpringBoot Application

Heap size set to 4 GB with a 2 GB young generation ( -Xmx4g -Xms4g -XX:SurvivorRatio=8 -Xmn2g ) and GC logs written to -Xloggc:/Users/testUser/log/gc.log .

5.2 Manual GC Before Load

Run curl http://localhost:8080/gc to clear existing objects.

5.3 Run JMeter Load

Execute the JMeter plan, which triggers 20,000 HTTP calls.

5.4 GC Log Analysis

After the test, the Eden space usage drops to 0, indicating that the pre‑GC Eden size equals the total memory allocated by the 20,000 HTTP calls.

6. Results

Even with a tiny request body (≈50 bytes), each HTTP call allocates about 34 KB of heap memory, mainly due to internal object creation in SpringBoot.

Increasing the detail field to 1,200 characters raises the allocation to ~36 KB, confirming a roughly linear relationship.

Adding a log statement ( log.warn(...) ) increases the per‑request allocation to ~56 KB, showing that log size directly impacts memory consumption.

7. Real‑World Observations

In production, a single RPC request can consume 0.5 MB–1 MB of heap memory because of complex business logic, multiple downstream calls, and extensive logging.

With a 0.5 MB per‑request cost and 500 concurrent requests per second, the system would allocate ~15 GB of memory per minute, requiring at least three young‑generation GCs per minute.

8. Recommendations

Control the size of individual log entries and request payloads to reduce heap pressure and GC frequency, thereby improving overall system performance.

JVMPerformanceRPCJMeterHTTPSpringBootGC
Top Architect
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.