# How to limit the Memory used by ElasticSearch

**URL:** <https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825>\
**Category:** Elasticsearch\
**Created:** [July 17, 2015, 6:02pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825 "2015-07-17T18:02:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ningjun](https://avatars.discourse-cdn.com/v4/letter/n/ec9cab/32.png) [@Ningjun](https://discuss.elastic.co/u/Ningjun)\
**Post date:** [July 17, 2015, 6:02pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/1 "2015-07-17T18:02:40Z")

</div>

I am using ElasticSearch 1.6.0 on Windows 2008 R2 server. I want to limit the Memory used by the ElasticSearch servers. I set the following and start the server  
set ES\_HEAP\_SIZE=4g

The windows resource Monitor shows that the java process use 4GB commited memory. I then perform some search and retrieve of 7 millions documents, then the Memory usage of the java process become  
Commited: 4GB (no change)  
Private: 4GB  
Sharable: 9GB  
Working set: 13GB

Why does the ES JVM used 9GB of sharable Memory? This cause my machine to be 100% memory full and it become very slow.

How can I limit the Sharable memory used by ElasticSearch?

Thanks  
Ningjun

---

<div class="post-metadata">

**Author:** ![Pradeep\_Gowda](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@Pradeep\_Gowda](https://discuss.elastic.co/u/Pradeep_Gowda)\
**Post date:** [July 17, 2015, 6:33pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/2 "2015-07-17T18:33:07Z")

</div>

Did you try to set -Xms and -Xmx for ES process? This limits the heap size.

---

<div class="post-metadata">

**Author:** ![Ningjun](https://avatars.discourse-cdn.com/v4/letter/n/ec9cab/32.png) [@Ningjun](https://discuss.elastic.co/u/Ningjun)\
**Post date:** [July 17, 2015, 9:17pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/3 "2015-07-17T21:17:15Z")

</div>

The environment variable ES\_HEAP\_SIZE achieve the same thing as -Xms and -Xmx. The heap size is 4GB but the ES use a lot more "Sharable" memory than 4GB. I believe it is Lucene which greedly eat up all available kernel memory no matter what JAVA heap size is.

---

<div class="post-metadata">

**Author:** ![Pradeep\_Gowda](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@Pradeep\_Gowda](https://discuss.elastic.co/u/Pradeep_Gowda)\
**Post date:** [July 17, 2015, 11:52pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/4 "2015-07-17T23:52:05Z")

</div>

Can I see what your "ps -ef | grep java" looks like?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 18, 2015, 2:48am UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/5 "2015-07-18T02:48:23Z")

</div>

This is Lucene caching things. Windows may have some method of restricting the overall memory of a process, but that's not really something we can help with.

Don't be worried though, if other processes need memory then they can get it, it's not going to starve them just to keep things cached.

> [@Pradeep\_Gowda](#):
>
> Can I see what your "ps -ef | grep java" looks like?

Won't work on Windows.

---

<div class="post-metadata">

**Author:** ![Pradeep\_Gowda](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@Pradeep\_Gowda](https://discuss.elastic.co/u/Pradeep_Gowda)\
**Post date:** [July 18, 2015, 6:58am UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/6 "2015-07-18T06:58:04Z")

</div>

My bad! I did not notice that it's windows server!

---

<div class="post-metadata">

**Author:** ![Ningjun](https://avatars.discourse-cdn.com/v4/letter/n/ec9cab/32.png) [@Ningjun](https://discuss.elastic.co/u/Ningjun)\
**Post date:** [July 22, 2015, 6:14pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/7 "2015-07-22T18:14:19Z")

</div>

Thanks for your reply. It does starve the windows because spark UI server running on the same machine is responding slowly due to lack of memory.

I am surprised that there is no config setting to limit the cache memory size of Lucene? This means Lucene will greedily eat up all memory and nobody can stop it?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 22, 2015, 6:49pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/8 "2015-07-22T18:49:07Z")

</div>

> I am surprised that there is no config setting to limit the cache memory size of Lucene? This means Lucene will greedily eat up all memory and nobody can stop it?

Lucene just maps files into memory and has little control over how much of it is made part of the process's working set (i.e. the part of the process's address space that's in RAM). See [Archived MSDN and TechNet Blogs | Microsoft Learn](http://blogs.technet.com/b/clinth/archive/2012/10/11/can-a-process-be-limited-on-how-much-physical-memory-it-uses.aspx) for some more background. It mentions a tool that can be used to limit the maximum working set size of a process—perhaps it's useful to you?

---

<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:** [July 5, 2017, 11:59pm UTC](https://discuss.elastic.co/t/how-to-limit-the-memory-used-by-elasticsearch/25825/9 "2017-07-05T23:59:51Z")

</div>


