Skip to content

Commit

Permalink
Change file descriptor limit to 65535 (#37537)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Jan 16, 2019
1 parent 3765cb9 commit d11e987
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion distribution/packages/src/common/env/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/deb/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/rpm/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/setup/install/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,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:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/setup/install/sysconfig-file.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`::

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/setup/sysconfig/configuring.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/setup/sysconfig/file-descriptors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<ulimit,`ulimit -n 65536`>> as
root before starting Elasticsearch, or set `nofile` to `65536` in
For the `.zip` and `.tar.gz` packages, set <<ulimit,`ulimit -n 65535`>> as
root before starting Elasticsearch, or set `nofile` to `65535` in
<<limits.conf,`/etc/security/limits.conf`>>.

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 <<cluster-nodes-stats>> API, with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static class FileDescriptorCheck implements BootstrapCheck {
private final int limit;

FileDescriptorCheck() {
this(1 << 16);
this(65535);
}

protected FileDescriptorCheck(final int limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ long getMaxHeapSize() {

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) {
Expand Down

0 comments on commit d11e987

Please sign in to comment.