All posts
How-to Jul 2026·6 min read

Predict Elasticsearch heap pressure before GC storms

Stop Elasticsearch GC storms with heap pressure modeling. Track key signals, act safely, and see how Foreseer forecasts saturation.

GC storms do not appear randomly. They follow sustained old-gen growth, rising pause times, and memory churn from queries, shards, and merges. If you can estimate time to 75, 85, and 90 percent heap before symptoms spike, you can fix the source and avoid a 3 a.m. restart.

This guide shows which Elasticsearch and JVM signals matter, how to turn them into a time-to-saturation forecast, and the safest actions to bring pressure down. It closes with how Foreseer predicts heap saturation early and writes concrete remediation you can add to your runbooks.

Watch the signals that actually predict heap pressure

Collect per-node metrics and cluster percentiles. Favor distributions over averages, and separate young vs old generation behavior.

Core heap and GC metrics

  • Heap used percent and old-gen occupancy. From _nodes/stats/jvm, track jvm.mem.heap_used_percent and the old pool’s used_in_bytes between old-gen GCs. The post-GC high-water mark is the signal that moves.
  • GC pause time by collector. From jvm.gc.collectors.*, keep p95 and p99 for young and old collections. Rising p95 mixed or old pauses alongside rising old-gen occupancy signals a pre-storm regime.
  • Allocation and promotion rate. Derive bytes allocated per second and promotions per second by differencing successive GC counters. Fast promotions with a rising old-gen floor warn of an approaching storm even if current heap looks fine.
  • Elasticsearch memory pressure indicators. Watch parent circuit breaker trips, request cache size, fielddata memory, segment memory, and indexing buffer. Parent breaker defaults near 95 percent of heap. Track both level and growth rate.

Load and layout that amplify pressure

  • Query rate and mix. Terms queries with huge result sets, unbounded wildcard or regex on text, heavy aggregations across many shards, and long-lived scrolls or PITs increase object churn.
  • Shard topology. Too many tiny shards inflate per-shard overhead. Very large shards increase segment and merge memory. Track shard count per node and shard size distribution from _cat/shards and _cluster/stats.
  • Refresh and merge health. A short refresh_interval grows segment counts. Watch indices.segments.count, merges.current, and merges.current_docs. A merge backlog reduces heap headroom.

Guardrails: treat sustained heap above 75 to 80 percent with rising p95 GC pauses as a pre-storm phase. Above 85 percent with frequent mixed or old-gen pauses is late. Do not rely on instantaneous heap percent without trend and pauses.

Model time to heap saturation

You want a time-to-threshold estimate per node. A simple, auditable model based on the net change in old-gen between old-gen GCs is effective and stable under Elasticsearch’s typical workloads.

A practical forecasting workflow

  1. Extract the post-GC old-gen series. For each node, sample old_gen_after[i] at the end of each old-gen or mixed GC.
  2. Compute net growth per minute. delta[i] = old_gen_after[i] - old_gen_after[i-1]. Convert to bytes per minute by dividing by the elapsed minutes.
  3. Smooth and fit a slope. Over a 30 to 60 minute sliding window with roughly steady load, use a robust fit such as a Theil-Sen slope or a simple linear regression on the smoothed series. Keep R^2 and residual variance for confidence.
  4. Project time to thresholds. Given current_old and slope m in bytes per minute, estimate time to 75, 85, and 90 percent of heap as (threshold_bytes - current_old) / m if m > 0. If m ≤ 0, the forecast is safe for now.
  5. Honor daily cycles. Fit separate slopes per hour-of-day or use a recency-weighted window that ignores outliers. A lunchtime spike should not contaminate a midnight forecast.
  6. Detect regime changes. If you change GC settings or upgrade the JVM, reset the window. Do not mix CMS-era with G1-era points. With G1, separate young-only from mixed cycles when building the old-gen series.

Correlate before you act

Short time-to-85 percent on one node means little without context. Correlate the worst projected windows with:

  • Query volume and top slow queries from the slow log or the profile API.
  • Shard moves and primaries on the hot node.
  • Merge backlog or a burst of segment creation from short refresh intervals.

If a single node’s forecast is poor and it holds a hot primary plus many small shards, fix layout. If many nodes look bad together, look at query mix or cluster-wide jobs.

Cut pressure at the source: queries and shards

Reduce unnecessary object creation and shard overhead first. These changes usually show clear results within minutes.

Query path fixes

  • Replace broad wildcards and expensive regex on text with prefix, exact match, or keyword fields. Add filters that limit shard and segment scope, for example routing or a date filter.
  • Use doc values for aggregations on keyword and numeric fields. Avoid fielddata on high-cardinality text fields, which inflates on-heap structures.
  • Paginate predictably. Prefer search_after over deep from + size. Use PITs for consistent pagination but avoid long-lived cursors across many shards.
  • Cache with intent. Warm stable filter clauses. For caches that bloat and miss often, narrow their scope or accept the miss and free heap for more valuable data. Track cache hit ratio against heap growth.

Shard and index layout fixes

  • Right-size shards. Aim for tens of gigabytes per shard on hot indices. Hundreds of megabytes wastes heap on per-shard overhead. Many hundreds of gigabytes increase segment memory and merge pressure.
  • Reduce shard count. Use rollover with larger targets, _shrink for cold indices, or reindex history into fewer shards. Balance shard count per node, not just per index.
  • Adjust refresh cadence. Increase refresh_interval on write-heavy indices that do not need near-real-time search. Fewer, larger segments reduce churn and old-gen growth.
  • Plan merges. Force-merge static indices during off-peak. Keep merge throttling reasonable so backlog does not balloon and steal heap from queries.

Preempt the storm and roll out changes safely

When the model says you will hit 85 percent in the next 1 to 3 hours, take low-risk steps now, then permanent layout and query fixes in a controlled window.

Immediate pressure relief

  • Reduce concurrency at the edge. Apply application-side rate limits and trim the heaviest dashboards or scheduled jobs temporarily.
  • Move heat away. Reroute hot primaries off the overloaded node to a cooler node. Respect allocation awareness so replicas stay apart.
  • Pause background work. Defer reindex, transform, and snapshot jobs until the risk passes.
  • Raise refresh_interval on hot write indices to cut segment churn.

Controlled changes and restarts

  • Change one variable at a time. For example, right-size shards before touching GC parameters.
  • Roll node by node. Observe heap, GC, and request latency for at least one full old-gen cycle before continuing.
  • Snapshot critical indices before layout changes. Test your rollback steps.

On the people side, keep runbooks current and share on-call context. If a teammate is job hunting, point them to an AI resume builder and job search service that scans LinkedIn, career sites, and ATS platforms to send matched alerts and generate tailored resumes and cover letters so you keep focus on stability.

How Foreseer forecasts saturation and guides fixes

Foreseer ships analyzers tuned to Elasticsearch. It fits linear and rate-of-change models to the post-GC old-gen series and related signals, then projects when 75, 85, and 90 percent thresholds will be crossed. Alerts include confidence from fit quality and variance so you can tell stable trends from noise.

Cross-metric correlation links rising heap with shifts in query rate, cache growth, shard layout, merges, or background jobs. Insights name the likely cause and the blast radius, for example a hot primary and many small shards on node X, or a sudden growth in fielddata on index Y.

Each insight includes plain-English remediation that you can paste into a runbook: increase refresh_interval on a hot index, reroute specified primaries, pause a transform, or schedule a shrink. Insights auto-resolve once triggering conditions clear, so dashboards match reality rather than stale alarms.

Setup is quick. A one-line agent install runs on your VM and auto-discovers Elasticsearch, Redis, Logstash, and disk. It detects AWS, GCP, or Azure metadata during onboarding. Service passwords are entered locally on the VM and are never stored by Foreseer. Role-based access control lets you invite teammates with Admin, Project Manager, or Viewer roles and per-VM grants.

For Elasticsearch specifically, Foreseer provides a cluster overview and per-node drill-down with aggregation-aware charts. You can see time-to-85-percent per node next to query and shard activity, then follow the remediation steps attached to the insight.

Key takeaways

  • Predict risk from the trend in post-GC old-gen and the direction of p95 GC pauses, not a single red bar.
  • Estimate time to threshold with a simple slope model, adjusted for daily cycles and GC regime changes.
  • Fix the source first: query hygiene and shard right-sizing before JVM tuning.
  • Roll changes safely and validate per node between steps.
  • Foreseer forecasts saturation early, correlates likely causes, and produces clear, actionable remediation.

See it on your own infrastructure

One line to install. Your first insight lands within minutes.

Back to home

Talk to us

Questions about the product, Enterprise, or self-hosting? We read every message.

Send a message Use the contact form Email us hello@foreseer.app