Keycloak Ops
Identity & Access Management (IAM) Ops

Keycloak Memory and Heap Sizing Calculator

Estimate the Infinispan session cache footprint, the per-node Quarkus JVM heap and the container limit that heap needs, for a given peak session load. Everything runs in the browser, and every assumption is listed underneath.

Keycloak's default is 10,000 entries per node. Raise it here only if your deployment has raised it.

Session cache, cluster-wide
—
JVM heap per node
—
Container limit per node
—
Nodes
—

Heap is a per-node figure. The container limit is derived from it with Keycloak's own rule, (total instance memory - 300 MB non-heap) / 0.7, which is simply heap / 0.7, because the image sizes the heap as a percentage of the limit rather than the other way round.

How this estimate is calculated

The model is deliberately simple, and every constant it uses is listed below so you can replace one with a figure from your own deployment. It is an estimate for planning, not a measurement of any particular installation, and it is only as good as the per-session size you feed it.

Three of the inputs below are documented Keycloak figures. The rest are assumptions, and they are marked as such.

  • Session footprint (assumption). The cluster-wide cache figure is the number of session entries held in memory times the per-session size you selected. Each node holds its share of your session count times the number of in-memory copies, up to the per-node cap. The 4.5 KB default is an estimate, not a Keycloak figure: the selectable sizes are planning assumptions for leaner or larger session data. They are not token-size measurements or documented per-session memory costs.
  • Session cache cap (documented default). The caching guide limits the embedded session caches to 10,000 entries per node by default, set with options such as cache-embedded-sessions-max-count. Sessions beyond the cap are not lost: they stay in the database and are loaded on demand, which costs database reads rather than heap. The base figure below already includes 10,000 cached sessions, so only entries above 10,000 per node are added to the heap. Keep the default unless your deployment has raised the cap so that more sessions are held in memory.
  • Base memory (documented). Keycloak's sizing guidance states that "the base memory usage for a Pod including caches of Realm data and 10,000 cached sessions is 1250 MB of RAM". That figure is total instance memory, not heap, so the baseline used here is 1250 MB minus the documented 300 MB non-heap allowance, or 950 MB of heap. Each realm past the first adds a further 100 MB, which is an assumption rather than a documented figure, on the basis that a realm carries its own configuration, keys and client set in the realm cache.
  • Working headroom (assumption). The per-node heap is the session share above the base's 10,000 entries plus the base, multiplied by 1.2 to leave room for request-time allocation and garbage collection slack. There is no documented multiplier for this; 20 percent is a planning convention.
  • Node count (assumption). Nodes are added so that no single node holds more than 3 GB of session cache, with a floor of two nodes so that a rolling restart is possible. Real node count is usually decided by CPU rather than by memory: the sizing guide allocates 1 vCPU per 15 password logins per second and 1 vCPU per 120 refresh requests per second, and that arithmetic is worked through in the sizing article rather than here.
  • Container limit (documented). The container image sets the heap as a percentage of the container limit, not the reverse, using -XX:MaxRAMPercentage=70, and the sizing guide budgets approximately 300 MB of non-heap memory per instance. The documented rule is (total instance memory - 300 MB non-heap) / 0.7, and because the heap is exactly that subtraction, the limit above is heap / 0.7. The 300 MB of non-heap memory is already covered by the remaining 30 percent of the limit, so it is not added again.
  • Cache owners on current releases. The caching documentation states: "By default, with persistent user sessions enabled, sessions are loaded on-demand from the database into the embedded caches." For the user and client session caches it adds: "Cache entries use a single owner per entry." On such a release the 2-owner and 3-owner settings model an older or externally-replicated topology and will overstate memory. Select the lowest option that matches your deployment.

Read how the Infinispan cache and heap figures are derived for the documented sizing model, cache limits, and CPU calculations that complement this estimate.

Related guides