How much memory does a Java application need to do its job? The answer affects how many services you can colocate on a server, how many replicas fit on a node, and how much capacity you need for the database they share.

In our four-stack benchmark, every implementation sustained the same 40 requests per second on a 512 MiB Linux VM with similar tail latency. Sampled peak application RSS ranged from about 148 to 233 MiB, even though every JVM had an 80 MiB maximum heap. Could the smaller footprint make room for another service or replica? The VM measurements show where to look. The placement decision needs measurements from your deployment.

Same workload, different Java memory footprints

We ran each stack separately with PostgreSQL on the same Debian guest. Across two rounds, sampled peak application RSS was about 148 to 150 MiB for Jex + Jdbi, 200 to 205 MiB for Quarkus + Jdbi, 210 to 219 MiB for Micronaut Data JDBC, and 222 to 233 MiB for Spring Boot + JDBC. All eight runs completed without workload errors or timeouts. Client-observed p99 ranged from 11.02 to 11.51 ms at 40 RPS.

Two rounds per stack. Jex had the lowest sampled peak application RSS and the most guest memory available. Sustained p99 was similar across all four stacks.
Framework Benchmarks v1 on a 512 MiB Debian VM. RSS peaks and guest MemAvailable minima come from sustained-phase samples. Client p99 includes scheduling and SSH transport.

In matched rounds, Jex + Jdbi used roughly 72 to 85 MiB less sampled peak application RSS than Spring Boot + JDBC. The lowest guest MemAvailable sample in each round was about 197 to 202 MiB with Jex and 119 to 127 MiB with Spring Boot. That metric estimates memory available to the whole guest, including the effects of the OS and PostgreSQL. It gives a broader view of headroom than the application process alone.

These are complete stacks, including the HTTP server, persistence code, connection pool and JVM. The fixed workload tells us how they behaved at the tested rate. Finding a saturation point would require a load sweep. PVR Labs develops CoilBase, which provided application structure and persistence integration for the Jex and Quarkus variants. The full benchmark write-up documents the fixture and recorded results. Repository CI checks correctness and report regeneration. Reproducing the performance measurements requires running the suite.

Persistence overhead adds up across replicas

In a separate experiment on a 512 MiB Linux VM, we compared Jdbi with direct Hibernate while keeping the CoilBase, Jex and JTE application infrastructure substantially the same. Across the two accepted runs per variant, median application RSS during the mixed-workload phase was 95 to 96 MiB with Jdbi and 152 to 154 MiB with Hibernate. The observed difference was about 55 to 58 MiB. Process RSS included embedded H2, and one accepted Hibernate rerun used different guest background timer settings. See the revisited persistence experiment.

SQL-first persistence can be sufficient when queries are explicit and the application mainly maps rows to objects. Managed entities, relationship mapping and change tracking can justify ORM overhead when the application relies on those capabilities. Any difference in private memory matters more when each replica pays it. Size each candidate as a complete deployment. The persistence and framework experiments used different workloads and reported different RSS statistics, so each delta applies to its own comparison.

How many Java applications can fit on a single server?

Start with the capacity available to workloads after reserving memory for the operating system, node services, existing workloads and operational headroom. On a shared server, check what colocated services consume at the same time. In Kubernetes, the scheduler fits pods against node allocatable capacity using resource requests. A memory limit sets a runtime ceiling, and exceeding it can lead to an OOM kill. Use the effective request for the whole pod, accounting for sidecars, init containers and pod overhead where applicable. See Kubernetes resource management.

  • Heap maximum caps the Java heap. The JVM also uses memory for thread stacks, class metadata, compiled code and native allocations.
  • RSS counts the resident pages mapped by a process, including shared pages in full. PSS divides shared resident pages among their users. Measure sharing with replicas running together if your capacity estimate depends on it.
  • Cgroup memory accounts for a group of processes and charges such as page cache and kernel memory. In cgroup v2, memory.current gives the current charge and memory.peak records a high-water mark. Working-set metrics can discount some file cache, so check them alongside the full charge, swap and OOM events. See the Linux cgroup v2 memory documentation and the Quarkus measurement guide.

Say a node has a hypothetical 3 GiB request budget after reservations. By memory alone, 3,072 MiB fits six pods at 512 MiB each or eight pods at 384 MiB each, provided both effective requests have been validated under load. CPU, the node’s pod limit, placement constraints and rollout capacity can lower the usable count. Check what happens if replicas start together or several see the same traffic spike. Lower requests change infrastructure costs when you can consolidate nodes, use smaller instances or avoid adding capacity.

Database connections multiply with application replicas

In our Spring Boot and HikariCP experiment, two replicas kept 20 PostgreSQL connections after a burst with fixed-size pools. With idle retirement enabled, each pool settled at one connection, leaving two in total and about 29 MiB less PostgreSQL cgroup memory in the quiet window. Lowering minimumIdle alone in the no-reclaim control left all 20 burst connections open.

When traffic returned, median connection acquisition took about 194 to 207 ms with retirement, versus under 3 ms with connections retained. Measure that cost against the latency budget for the first requests after a quiet period. The memory difference belongs to this database workload and includes cache effects. AWS’s idle-session measurements show how prior session activity can affect memory use. Database settings also matter. Our low-memory PostgreSQL experiment illustrates that with a database-only read workload.

For a shared database, multiply each app’s pool maximum by its highest concurrent replica count, including old and new replicas during rollouts. Add the ceilings for other services and leave space for jobs and administrative clients. Idle retirement reduces the quiet-period footprint. The database still needs a connection budget for overlapping bursts.

How to measure your own deployment

  1. Pin the application build, dataset, request mix, JDK build and flags, CPU quota, memory limit and swap policy. When choosing a runtime, compare deployable defaults for an operational decision or align settings to investigate a runtime difference.
  2. Repeat startup, warmup, sustained load, bursts and recovery. Identify whether each metric covers a process, container, pod or host. Record RSS or PSS, cgroup charge and peak, working set, swap and OOM events alongside CPU, p99 and errors. In our exploratory OpenJ9 and HotSpot comparison, swap made RSS alone a poor basis for sizing.
  3. Run concurrent replicas with sidecars and realistic database demand. Include overlapping startups and bursts. Change requests only after the deployment meets its latency and error targets with enough headroom at the proposed density.

Size the application and database together

Constrained VMs make differences in the JVM, application stack and database visible. Remeasure those layers together where you deploy, then check whether the footprint change makes room for another service or reduces the capacity you need. To repeat the four-stack test, start with the benchmark repository. For help investigating a deployment, see PVR Labs Java performance consulting.