﻿---
title: High JVM memory pressure
description: High JVM memory usage can degrade cluster performance and trigger circuit breaker errors. To prevent this, we recommend taking steps to reduce memory...
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/troubleshoot/elasticsearch/high-jvm-memory-pressure
products:
  - Elasticsearch
---

# High JVM memory pressure
High JVM memory usage can degrade cluster performance and trigger [circuit breaker errors](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/troubleshoot/elasticsearch/circuit-breaker-errors). To prevent this, we recommend taking steps to reduce memory pressure if a node’s JVM memory usage consistently exceeds 85%.
<admonition title="Simplify monitoring with AutoOps" applies-to="{ ess:, ece:, eck:, self:, "serverless": "ga" }">
  AutoOps is a monitoring tool that simplifies cluster management through performance recommendations, resource utilization visibility, and real-time issue detection with resolution paths. Learn more about [AutoOps](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/deploy-manage/monitor/autoops).
</admonition>


## Diagnose high JVM memory pressure

**Check JVM memory pressure**
<tab-set>
  <tab-item title="Elastic Cloud Hosted">
    From your deployment menu, click **Elasticsearch**. Under **Instances**, each instance displays a **JVM memory pressure** indicator. When the JVM memory pressure reaches 75%, the indicator turns red.You can also use the [nodes stats API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-nodes-stats) to calculate the current JVM memory pressure for each node.
    ```json
    ```
    Use the response to calculate memory pressure as follows:JVM Memory Pressure = `used_in_bytes` / `max_in_bytes`
  </tab-item>

  <tab-item title="Self-managed">
    To calculate the current JVM memory pressure for each node, use the [nodes stats API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-nodes-stats).
    ```json
    ```
    Use the response to calculate memory pressure as follows:JVM Memory Pressure = `used_in_bytes` / `max_in_bytes`
  </tab-item>
</tab-set>

**Check garbage collection logs**
As memory usage increases, garbage collection becomes more frequent and takes longer. You can track the frequency and length of garbage collection events in [`elasticsearch.log`](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/deploy-manage/monitor/logging-configuration/elasticsearch-log4j-configuration-self-managed). For example, the following event states Elasticsearch spent more than 50% (21 seconds) of the last 40 seconds performing garbage collection.
```txt
[timestamp_short_interval_from_last][INFO ][o.e.m.j.JvmGcMonitorService] [node_id] [gc][number] overhead, spent [21s] collecting in the last [40s]
```

**Capture a JVM heap dump**
To determine the exact reason for the high JVM memory pressure, capture a heap dump of the JVM while its memory usage is high, and also capture the [garbage collector logs](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/jvm-settings#gc-logging) covering the same time period.

## Reduce JVM memory pressure

This section contains some common suggestions for reducing JVM memory pressure.
**Reduce your shard count**
Every shard uses memory. In most cases, a small set of large shards uses fewer resources than many small shards. For tips on reducing your shard count, see [*Size your shards*](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/deploy-manage/production-guidance/optimize-performance/size-shards).

**Avoid expensive searches**
Expensive searches can use large amounts of memory. To better track expensive searches on your cluster, enable [slow logs](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/4436/deploy-manage/monitor/logging-configuration/slow-logs).
Expensive searches may have a large [`size` argument](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/rest-apis/paginate-search-results), use aggregations with a large number of buckets, or include [expensive queries](/elastic/docs-content/pull/4436/explore-analyze/query-filter/languages/querydsl#query-dsl-allow-expensive-queries). To prevent expensive searches, consider the following setting changes:
- Lower the `size` limit using the [`index.max_result_window`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/index-settings/index-modules#index-max-result-window) index setting.
- Decrease the maximum number of allowed aggregation buckets using the [search.max_buckets](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/search-settings#search-settings-max-buckets) cluster setting.
- Disable expensive queries using the [`search.allow_expensive_queries`](/elastic/docs-content/pull/4436/explore-analyze/query-filter/languages/querydsl#query-dsl-allow-expensive-queries) cluster setting.
- Set a default search timeout using the [`search.default_search_timeout`](/elastic/docs-content/pull/4436/solutions/search/the-search-api#search-timeout) cluster setting.

```json

{
  "index.max_result_window": 5000
}


{
  "persistent": {
    "search.max_buckets": 20000,
    "search.allow_expensive_queries": false
  }
}
```

**Prevent mapping explosions**
Defining too many fields or nesting fields too deeply can lead to [mapping explosions](/elastic/docs-content/pull/4436/manage-data/data-store/mapping#mapping-limit-settings) that use large amounts of memory. To prevent mapping explosions, use the [mapping limit settings](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/index-settings/mapping-limit) to limit the number of field mappings.
**Spread out bulk requests**
While more efficient than individual requests, large [bulk indexing](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk) or [multi-search](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-msearch) requests can still create high JVM memory pressure. If possible, submit smaller requests and allow more time between them.
**Upgrade node memory**
Heavy indexing and search loads can cause high JVM memory pressure. To better handle heavy workloads, upgrade your nodes to increase their memory capacity.