From 18a3e48a4a7aaff948dc209f7c0798b703d439cc Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 16 Jan 2019 17:19:12 -0500 Subject: [PATCH] Change file descriptor limit to 65535 (#37537) Some systems default to a nofile ulimit of 65535. To reduce the pain of deploying Elasticsearch to such systems, this commit lowers the required limit from 65536 to 65535. --- distribution/packages/src/common/env/elasticsearch | 2 +- .../packages/src/common/systemd/elasticsearch.service | 2 +- distribution/packages/src/deb/init.d/elasticsearch | 2 +- distribution/packages/src/rpm/init.d/elasticsearch | 2 +- docs/reference/getting-started.asciidoc | 2 +- docs/reference/setup/install/docker.asciidoc | 2 +- docs/reference/setup/install/sysconfig-file.asciidoc | 2 +- docs/reference/setup/sysconfig/configuring.asciidoc | 4 ++-- docs/reference/setup/sysconfig/file-descriptors.asciidoc | 6 +++--- .../src/test/resources/packaging/tests/60_systemd.bats | 2 +- .../java/org/elasticsearch/bootstrap/BootstrapChecks.java | 2 +- .../org/elasticsearch/bootstrap/BootstrapChecksTests.java | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/distribution/packages/src/common/env/elasticsearch b/distribution/packages/src/common/env/elasticsearch index 995a264e513..76d9473b0fb 100644 --- a/distribution/packages/src/common/env/elasticsearch +++ b/distribution/packages/src/common/env/elasticsearch @@ -36,7 +36,7 @@ ES_STARTUP_SLEEP_TIME=5 # Specifies the maximum file descriptor number that can be opened by this process # When using Systemd, this setting is ignored and the LimitNOFILE defined in # /usr/lib/systemd/system/elasticsearch.service takes precedence -#MAX_OPEN_FILES=65536 +#MAX_OPEN_FILES=65535 # The maximum number of bytes of memory that may be locked into RAM # Set to "unlimited" if you use the 'bootstrap.memory_lock: true' option diff --git a/distribution/packages/src/common/systemd/elasticsearch.service b/distribution/packages/src/common/systemd/elasticsearch.service index a4d67d8830a..a03f1befdb7 100644 --- a/distribution/packages/src/common/systemd/elasticsearch.service +++ b/distribution/packages/src/common/systemd/elasticsearch.service @@ -29,7 +29,7 @@ StandardOutput=journal StandardError=inherit # Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 +LimitNOFILE=65535 # Specifies the maximum number of processes LimitNPROC=4096 diff --git a/distribution/packages/src/deb/init.d/elasticsearch b/distribution/packages/src/deb/init.d/elasticsearch index 5ff7a5e74c6..1e503fa0cfa 100755 --- a/distribution/packages/src/deb/init.d/elasticsearch +++ b/distribution/packages/src/deb/init.d/elasticsearch @@ -39,7 +39,7 @@ ES_HOME=/usr/share/$NAME #ES_JAVA_OPTS= # Maximum number of open files -MAX_OPEN_FILES=65536 +MAX_OPEN_FILES=65535 # Maximum amount of locked memory #MAX_LOCKED_MEMORY= diff --git a/distribution/packages/src/rpm/init.d/elasticsearch b/distribution/packages/src/rpm/init.d/elasticsearch index 8f91db31273..bdaf8fbec37 100644 --- a/distribution/packages/src/rpm/init.d/elasticsearch +++ b/distribution/packages/src/rpm/init.d/elasticsearch @@ -33,7 +33,7 @@ fi # Sets the default values for elasticsearch variables used in this script ES_HOME="/usr/share/elasticsearch" -MAX_OPEN_FILES=65536 +MAX_OPEN_FILES=65535 MAX_MAP_COUNT=262144 ES_PATH_CONF="${path.conf}" diff --git a/docs/reference/getting-started.asciidoc b/docs/reference/getting-started.asciidoc index ff1bdd6b7a6..b79dd5c36c2 100755 --- a/docs/reference/getting-started.asciidoc +++ b/docs/reference/getting-started.asciidoc @@ -248,7 +248,7 @@ If everything goes well with installation, you should see a bunch of messages th [2018-09-13T12:20:05,006][INFO ][o.e.n.Node ] [localhost.localdomain] initialized [2018-09-13T12:20:05,007][INFO ][o.e.n.Node ] [localhost.localdomain] starting ... [2018-09-13T12:20:05,202][INFO ][o.e.t.TransportService ] [localhost.localdomain] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} -[2018-09-13T12:20:05,221][WARN ][o.e.b.BootstrapChecks ] [localhost.localdomain] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] +[2018-09-13T12:20:05,221][WARN ][o.e.b.BootstrapChecks ] [localhost.localdomain] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2018-09-13T12:20:05,221][WARN ][o.e.b.BootstrapChecks ] [localhost.localdomain] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [2018-09-13T12:20:08,355][INFO ][o.e.c.s.MasterService ] [localhost.localdomain] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: master node changed {previous [], current [{localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test}]} [2018-09-13T12:20:08,360][INFO ][o.e.c.s.ClusterApplierService] [localhost.localdomain] master node changed {previous [], current [{localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test}]}, reason: apply cluster state (from master [master {localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]]) diff --git a/docs/reference/setup/install/docker.asciidoc b/docs/reference/setup/install/docker.asciidoc index 267ea144209..92710f4429f 100644 --- a/docs/reference/setup/install/docker.asciidoc +++ b/docs/reference/setup/install/docker.asciidoc @@ -338,7 +338,7 @@ needed, adjust them in the Daemon, or override them per container, for example using `docker run`: + -- - --ulimit nofile=65536:65536 + --ulimit nofile=65535:65535 NOTE: One way of checking the Docker daemon defaults for the aforementioned ulimits is by running: diff --git a/docs/reference/setup/install/sysconfig-file.asciidoc b/docs/reference/setup/install/sysconfig-file.asciidoc index d2df5cd4e0c..0532132cdad 100644 --- a/docs/reference/setup/install/sysconfig-file.asciidoc +++ b/docs/reference/setup/install/sysconfig-file.asciidoc @@ -5,7 +5,7 @@ `MAX_OPEN_FILES`:: - Maximum number of open files, defaults to `65536`. + Maximum number of open files, defaults to `65535`. `MAX_LOCKED_MEMORY`:: diff --git a/docs/reference/setup/sysconfig/configuring.asciidoc b/docs/reference/setup/sysconfig/configuring.asciidoc index 8390991aeb1..c9513885370 100644 --- a/docs/reference/setup/sysconfig/configuring.asciidoc +++ b/docs/reference/setup/sysconfig/configuring.asciidoc @@ -25,7 +25,7 @@ open file handles (`ulimit -n`) to 65,536, you can do the following: [source,sh] -------------------------------- sudo su <1> -ulimit -n 65536 <2> +ulimit -n 65535 <2> su elasticsearch <3> -------------------------------- <1> Become `root`. @@ -46,7 +46,7 @@ the `limits.conf` file: [source,sh] -------------------------------- -elasticsearch - nofile 65536 +elasticsearch - nofile 65535 -------------------------------- This change will only take effect the next time the `elasticsearch` user opens diff --git a/docs/reference/setup/sysconfig/file-descriptors.asciidoc b/docs/reference/setup/sysconfig/file-descriptors.asciidoc index 17e7884be0d..4c22a0021ff 100644 --- a/docs/reference/setup/sysconfig/file-descriptors.asciidoc +++ b/docs/reference/setup/sysconfig/file-descriptors.asciidoc @@ -12,15 +12,15 @@ file descriptors can be disastrous and will most probably lead to data loss. Make sure to increase the limit on the number of open files descriptors for the user running Elasticsearch to 65,536 or higher. -For the `.zip` and `.tar.gz` packages, set <> as -root before starting Elasticsearch, or set `nofile` to `65536` in +For the `.zip` and `.tar.gz` packages, set <> as +root before starting Elasticsearch, or set `nofile` to `65535` in <>. On macOS, you must also pass the JVM option `-XX:-MaxFDLimit` to Elasticsearch in order for it to make use of the higher file descriptor limit. RPM and Debian packages already default the maximum number of file -descriptors to 65536 and do not require further configuration. +descriptors to 65535 and do not require further configuration. You can check the `max_file_descriptors` configured for each node using the <> API, with: diff --git a/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats b/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats index db062eb337e..3cf495939af 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats @@ -234,7 +234,7 @@ setup() { local max_processes=$(cat /proc/$pid/limits | grep "Max processes" | awk '{ print $3 }') [ "$max_processes" == "4096" ] local max_open_files=$(cat /proc/$pid/limits | grep "Max open files" | awk '{ print $4 }') - [ "$max_open_files" == "65536" ] + [ "$max_open_files" == "65535" ] local max_address_space=$(cat /proc/$pid/limits | grep "Max address space" | awk '{ print $4 }') [ "$max_address_space" == "unlimited" ] systemctl stop elasticsearch.service diff --git a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java index e77568105db..ebda7df66dc 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java @@ -267,7 +267,7 @@ final class BootstrapChecks { private final int limit; FileDescriptorCheck() { - this(1 << 16); + this(65535); } protected FileDescriptorCheck(final int limit) { diff --git a/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java b/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java index be8387be87c..33a3aea37b4 100644 --- a/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java +++ b/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java @@ -188,7 +188,7 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase { public void testFileDescriptorLimits() throws NodeValidationException { final boolean osX = randomBoolean(); // simulates OS X versus non-OS X - final int limit = osX ? 10240 : 1 << 16; + final int limit = osX ? 10240 : 65535; final AtomicLong maxFileDescriptorCount = new AtomicLong(randomIntBetween(1, limit - 1)); final BootstrapChecks.FileDescriptorCheck check; if (osX) {