# How to pass the MAX\_OPEN\_FILES argument to JVM?

**URL:** <https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807>\
**Category:** Elasticsearch\
**Created:** [October 7, 2015, 10:42pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807 "2015-10-07T22:42:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![terrasacer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@terrasacer](https://discuss.elastic.co/u/terrasacer)\
**Post date:** [October 7, 2015, 10:42pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/1 "2015-10-07T22:42:30Z")

</div>

Hi there,

I'm trying to pass MAX\_OPEN\_FILES parameter to JVM.

Actually, I am trying to increase fd on mac os x. I made it with launchctl command but the default behavior is to set the limit value by JVM, which is 10240. Therefore, I need pass MaxFDLimit parameter jvm when Elasticsearch starting.

I tried to use shell file

```
export MAX_OPEN_FILES=1000000

ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.path.conf=$ES_CONF_DIR"

#ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.path.data=$ES_DATA_DIR -Des.path.conf=$ES_CONF_DIR"
export ES_JAVA_OPTS

cd $ES_HOME
exec $ES_HOME/bin/elasticsearch

```

It did not work.

Does anyone have any suggestions?

Thanks.

---

<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:** [October 8, 2015, 5:43am UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/2 "2015-10-08T05:43:08Z")

</div>

Doesn't the JVM by default use the process's fd limit (OPEN\_MAX), indicating that you're not upping that limit correctly? Now, if you _do_ need to pass `-XX:-MaxFDLimit` I don't see why setting MAX\_OPEN\_FILES would help. Wouldn't you actually want to append `-XX:-MaxFDLimit` to ES\_JAVA\_OPTS? Seemingly relevant: [http://stackoverflow.com/a/23530494/414355](http://stackoverflow.com/a/23530494/414355)

---

<div class="post-metadata">

**Author:** ![terrasacer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@terrasacer](https://discuss.elastic.co/u/terrasacer)\
**Post date:** [October 8, 2015, 3:47pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/3 "2015-10-08T15:47:48Z")

</div>

> [@magnusbaeck](#):
>
> Doesn't the JVM by default use the process's fd limit (OPEN\_MAX), indicating that you're not upping that limit correctly? Now, if you do need to pass -XX:-MaxFDLimit I don't see why setting MAX\_OPEN\_FILES would help. Wouldn't you actually want to append -XX:-MaxFDLimit to ES\_JAVA\_OPTS? Seemingly relevant:

Hi @magnusbaeck,

I used launchctl command for increasing fd.

```
sudo launchctl limit maxfiles 1000000 1000000
$ ulimit -n
1000000

```

After the above step and restarted Elasticsearch, I'm getting the following response from Elasticsearch when I uses this command: curl -XGET 'localhost:9200/\_nodes/process?pretty'

```
{
  "cluster_name" : "elasticsearch",
  "nodes" : {
    "y92KgXVuSdiB5khExFWA9g" : {
      "name" : "Hyperion",
      "transport_address" : "inet[/192.168.1.21:9300]",
      "host" : "terrasacer-air.local",
      "ip" : "192.168.1.21",
      "version" : "1.7.1",
      "build" : "b88f43f",
      "http_address" : "inet[/192.168.1.21:9200]",
      "process" : {
        "refresh_interval_in_millis" : 1000,
        "id" : 1395,
        "max_file_descriptors" : 10240,
        "mlockall" : false
      }
    }
  }
}

```

I can use the -XX:-MaxFDLimit in terminal but I can't use it in a shell file.

---

<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:** [October 8, 2015, 4:17pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/4 "2015-10-08T16:17:24Z")

</div>

> I can use the -XX:-MaxFDLimit in terminal but I can't use it in a shell file.

What do you mean? Please be explicit.

---

<div class="post-metadata">

**Author:** ![terrasacer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@terrasacer](https://discuss.elastic.co/u/terrasacer)\
**Post date:** [October 8, 2015, 6:26pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/5 "2015-10-08T18:26:19Z")

</div>

> [@magnusbaeck](#):
>
> What do you mean? Please be explicit.

For example, when I used `sudo bin/elasticsearch -XX:-MaxFDLimit` then I'm getting the response:

```
"max_file_descriptors" : 1000000,

```

I want to get a similar result when starting Elasticsearch with a shell file.

```
export ES_HOME=/Users/terrasacer/Downloads/elasticsearch
export ES_CONF_DIR=$ES_HOME/config
export ES_DATA_DIR=$ES_HOME/data
export CLASSPATH=$ES_HOME/lib/elasticsearch-*.jar:$ES_HOME/lib/*:$ES_HOME/lib/sigar/*

ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.path.data=$ES_DATA_DIR -Des.path.conf=$ES_CONF_DIR"

export ES_JAVA_OPTS

cd $ES_HOME
exec $ES_HOME/bin/elasticsearch

```

How do I use the above file `-XX:-MaxFDLimit` JVM option?

---

<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:** [October 8, 2015, 6:50pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/6 "2015-10-08T18:50:20Z")

</div>

It's hard to believe that adding it to ES\_JAVA\_OPTS or mimicking what you did in the shell (i.e. passing it directly to bin/elasticsearch) doesn't work. If that indeed is the case, inspecting the actual, full, command line in both cases should provide clues.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 8, 2015, 6:59pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/7 "2015-10-08T18:59:16Z")

</div>

The `-XX:-MaxFDLimit` flag for JVM is not doing anything useful. It was meant for old Solaris 8 OS, where the kernel allocates only 256 file descriptors per process by default.

You should be aware that this flag will be removed in future JDK releases.

This flag is not needed any more. In Linux, you have to adjust the kernel settings in `/etc/security/limits.conf` but the default settings for file descriptors is already increased to 10240 in current distributions, which is more than you will need for Elasticsearch.

---

<div class="post-metadata">

**Author:** ![terrasacer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@terrasacer](https://discuss.elastic.co/u/terrasacer)\
**Post date:** [October 8, 2015, 7:13pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/8 "2015-10-08T19:13:15Z")

</div>

Gentlemen, thank you for your answers.

> [@jprante](#):
>
> You should be aware that this flag will be removed in future JDK releases.

@jprante

Is this documented anywhere?

---

<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:45pm UTC](https://discuss.elastic.co/t/how-to-pass-the-max-open-files-argument-to-jvm/31807/9 "2017-07-05T23:45:48Z")

</div>


