# Logstash memory use keeps increasing linearly over time

**URL:** <https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927>\
**Category:** Logstash\
**Created:** [October 5, 2020, 5:30am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927 "2020-10-05T05:30:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHINRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinra/32/46751_2.png) [@SHINRA](https://discuss.elastic.co/u/SHINRA)\
**Post date:** [October 5, 2020, 5:30am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/1 "2020-10-05T05:30:37Z")

</div>

I have a logstash pipelines that runs tasks every day on a fixed time using the http input.

Each task completes executing (from input of first pipeline to outputs of the last one)  
within few minutes.

Rest of the day it's supposedly idle.

The logstash instance is deployed on kubernetes pod.  
When I monitor the pod's memory usage it's forever increasing since the initialization.

**Over the span of 2 weeks the memory use has been linearly growing -- almost in a straight line-- from 750MB to 1.8GB.**

The input plugins in use are:

- http\_poller
- dead\_letter\_queue
- jdbc

The filters:

- ruby
- elasticsearch
- mutate
- split
- fingerprint
- date
- translate
- prune
- http

The outputs:

- s3
- amazon\_es
- jdbc

On my jvm.options file heap size looks like this:

```
-Xms1g
-Xmx1g

```

On my pod the env LS\_JAVA\_OPTS is set:

```
-Xms2g
-Xmx2g 

```

This is my jvm status from node stats API

```
"mem" : {
      "heap_used_percent" : 47,
      "heap_committed_in_bytes" : 2138767360,
      "heap_max_in_bytes" : 2138767360,
      "heap_used_in_bytes" : 1010755840,
      "non_heap_used_in_bytes" : 217426408,
      "non_heap_committed_in_bytes" : 257306624,
      "pools" : {
        "survivor" : {
          "peak_used_in_bytes" : 8716288,
          "committed_in_bytes" : 8716288,
          "peak_max_in_bytes" : 8716288,
          "used_in_bytes" : 1019440,
          "max_in_bytes" : 8716288
        },
        "young" : {
          "peak_used_in_bytes" : 69795840,
          "committed_in_bytes" : 69795840,
          "peak_max_in_bytes" : 69795840,
          "used_in_bytes" : 19164000,
          "max_in_bytes" : 69795840
        },
        "old" : {
          "peak_used_in_bytes" : 1303750856,
          "committed_in_bytes" : 2060255232,
          "peak_max_in_bytes" : 2060255232,
          "used_in_bytes" : 990572400,
          "max_in_bytes" : 2060255232
        }
      }
    },
    "gc" : {
      "collectors" : {
        "young" : {
          "collection_time_in_millis" : 171762,
          "collection_count" : 6665
        },
        "old" : {
          "collection_time_in_millis" : 17094,
          "collection_count" : 14
        }
      }
    },

```

Why is my memory use only ever increasing?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 5, 2020, 2:01pm UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/2 "2020-10-05T14:01:41Z")

</div>

> [@SHINRA](#):
>
> Over the span of 2 weeks the memory use has been linearly growing -- almost in a straight line-- from 750MB to 1.8GB.

This is the way Java works. The JVM will keep allocating heap until it runs out. When it runs out it will run garbage collection which will free up some of the heap. Then it will start allocating heap again.

---

<div class="post-metadata">

**Author:** ![SHINRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinra/32/46751_2.png) [@SHINRA](https://discuss.elastic.co/u/SHINRA)\
**Post date:** [October 5, 2020, 3:20pm UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/3 "2020-10-05T15:20:19Z")

</div>

Thanks Badger!  
I have just one more question: as far as I understand we set xms and xmx to same value to avoid overhead of allocating more memory on runtime.

I set xmx=2g and xms=2g. Why is my pod's memory usage not corresponding to this?

Is my pod memory showing the actual heap usage?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 5, 2020, 3:39pm UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/4 "2020-10-05T15:39:11Z")

</div>

> [@SHINRA](#):
>
> I set xmx=2g and xms=2g. Why is my pod's memory usage not corresponding to this?

This controls the size of the Java heap. For most applications this dominates the memory usage of the JVM process, but it is possible for the JVM to use far more memory than the heap consumes. I have seen JVMs with heaps of a few GB consume dozens of megabytes of native memory.

---

<div class="post-metadata">

**Author:** ![SHINRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinra/32/46751_2.png) [@SHINRA](https://discuss.elastic.co/u/SHINRA)\
**Post date:** [October 8, 2020, 1:19am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/5 "2020-10-08T01:19:55Z")

</div>

Hi again,

It seems like logstash is ignoring the both jvm.options and LS\_JAVA\_OPTS's heap size settings.  
I set both heap sizes to xmx=1g and it's again linearly increasing now reaching 1.1G.  
It's increasing at a very constant rate -- about 20MB surge every 30 minutes.

Calling `_node/stats/jvm` gives me `heap_used_in_bytes` somewhere between 500MB to 600MB.  
The actual memory use is 1.1G.

Where is the memory leaking? Any help on finding the leak spot is appreciated! Thanks!

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 8, 2020, 2:42am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/6 "2020-10-08T02:42:28Z")

</div>

> [@SHINRA](#):
>
> Where is the memory leaking?

You have not given any indication that there is a memory leak. If a JVM's heap is limited to 2GB then the JVM's overall memory use could be 2.1 GB or 100 GB.

---

<div class="post-metadata">

**Author:** ![SHINRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinra/32/46751_2.png) [@SHINRA](https://discuss.elastic.co/u/SHINRA)\
**Post date:** [October 8, 2020, 4:43am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/7 "2020-10-08T04:43:04Z")

</div>

You were right! After reaching 1.15G it stopped! Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 5, 2020, 4:43am UTC](https://discuss.elastic.co/t/logstash-memory-use-keeps-increasing-linearly-over-time/250927/8 "2020-11-05T04:43:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
