advanced-configuration.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. [[advanced-configuration]]
  2. === Set JVM options
  3. [[set-jvm-options]]
  4. If needed, you can override the default JVM options by adding custom options
  5. files (preferred) or setting the `ES_JAVA_OPTS` environment variable.
  6. JVM options files must have the suffix '.options' and contain a line-delimited
  7. list of JVM arguments. JVM processes options files in lexicographic order.
  8. Where you put the JVM options files depends on the type of installation:
  9. * tar.gz or .zip: Add custom JVM options files to `config/jvm.options.d/`.
  10. * Debian or RPM: Add custom JVM options files to `/etc/elasticsearch/jvm.options.d/`.
  11. * Docker: Bind mount custom JVM options files into
  12. `/usr/share/elasticsearch/config/jvm.options.d/`.
  13. CAUTION: Setting your own JVM options is generally not recommended and could negatively
  14. impact performance and stability. Using the {es}-provided defaults
  15. is recommended in most circumstances.
  16. NOTE: Do not modify the root `jvm.options` file. Use files in `jvm.options.d/` instead.
  17. [[jvm-options-syntax]]
  18. ==== JVM options syntax
  19. A JVM options file contains a line-delimited list of JVM arguments.
  20. Arguments are preceded by a dash (`-`).
  21. To apply the setting to specific versions, prepend the version
  22. or a range of versions followed by a colon.
  23. * Apply a setting to all versions:
  24. +
  25. [source,text]
  26. -------------------------------------
  27. -Xmx2g
  28. -------------------------------------
  29. * Apply a setting to a specific version:
  30. +
  31. [source,text]
  32. -------------------------------------
  33. 17:-Xmx2g
  34. -------------------------------------
  35. * Apply a setting to a range of versions:
  36. +
  37. [source,text]
  38. -------------------------------------
  39. 17-18:-Xmx2g
  40. -------------------------------------
  41. +
  42. To apply a setting to a specific version and any later versions,
  43. omit the upper bound of the range.
  44. For example, this setting applies to Java 17 and later:
  45. +
  46. [source,text]
  47. -------------------------------------
  48. 17-:-Xmx2g
  49. -------------------------------------
  50. Blank lines are ignored. Lines beginning with `#` are treated as comments
  51. and ignored. Lines that aren't commented out and aren't recognized
  52. as valid JVM arguments are rejected and {es} will fail to start.
  53. [[jvm-options-env]]
  54. ==== Use environment variables to set JVM options
  55. In production, use JVM options files to override the
  56. default settings. In testing and development environments,
  57. you can also set JVM options through the `ES_JAVA_OPTS` environment variable.
  58. [source,sh]
  59. ---------------------------------
  60. export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"
  61. ./bin/elasticsearch
  62. ---------------------------------
  63. If you're using the RPM or Debian packages, you can specify
  64. `ES_JAVA_OPTS` in the <<sysconfig,system configuration file>>.
  65. NOTE: {es} ignores the `JAVA_TOOL_OPTIONS` and `JAVA_OPTS` environment variables.
  66. [[set-jvm-heap-size]]
  67. ==== Set the JVM heap size
  68. By default, {es} automatically sets the JVM heap size based on a node's
  69. <<node-roles,roles>> and total memory.
  70. Using the default sizing is recommended for most production environments.
  71. To override the default heap size, set the minimum and maximum heap size
  72. settings, `Xms` and `Xmx`. The minimum and maximum values must be the same.
  73. The heap size should be based on the available RAM:
  74. * Set `Xms` and `Xmx` to no more than 50% of your total memory. {es} requires
  75. memory for purposes other than the JVM heap. For example, {es} uses
  76. off-heap buffers for efficient network communication and relies
  77. on the operating system's filesystem cache for
  78. efficient access to files. The JVM itself also requires some memory. It's
  79. normal for {es} to use more memory than the limit
  80. configured with the `Xmx` setting.
  81. +
  82. NOTE: When running in a container, such as <<docker,Docker>>, total memory is
  83. defined as the amount of memory visible to the container, not the total system
  84. memory on the host.
  85. * Set `Xms` and `Xmx` to no more than the threshold for compressed ordinary
  86. object pointers (oops). The exact threshold varies but 26GB is safe on most
  87. systems and can be as large as 30GB on some systems. To verify you are under the
  88. threshold, check the {es} log for an entry like this:
  89. +
  90. [source,txt]
  91. ----
  92. heap size [1.9gb], compressed ordinary object pointers [true]
  93. ----
  94. +
  95. Or check the `jvm.using_compressed_ordinary_object_pointers` value for the nodes using the <<cluster-nodes-info,nodes info API>>:
  96. +
  97. [source,console]
  98. ----
  99. GET _nodes/_all/jvm
  100. ----
  101. The more heap available to {es}, the more memory it can use for its internal
  102. caches. This leaves less memory for the operating system to use
  103. for the filesystem cache. Larger heaps can also cause longer garbage
  104. collection pauses.
  105. To configure the heap size, add the `Xms` and `Xmx` JVM arguments to a
  106. custom JVM options file with the extension `.options` and
  107. store it in the `jvm.options.d/` directory.
  108. For example, to set the maximum heap size to 2GB, set both `Xms` and `Xmx` to `2g`:
  109. [source,txt]
  110. ------------------
  111. -Xms2g
  112. -Xmx2g
  113. ------------------
  114. For testing, you can also set the heap sizes using the `ES_JAVA_OPTS`
  115. environment variable:
  116. [source,sh]
  117. ------------------
  118. ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch
  119. ------------------
  120. The `ES_JAVA_OPTS` variable overrides all other JVM
  121. options. We do not recommend using `ES_JAVA_OPTS` in production.
  122. NOTE: If you are running {es} as a Windows service, you can change the heap size
  123. using the service manager. See <<windows-service>>.
  124. include::important-settings/heap-dump-path.asciidoc[leveloffset=-1]
  125. [[gc-logging]]
  126. include::important-settings/gc-logging.asciidoc[leveloffset=-1]
  127. [[error-file-path]]
  128. include::important-settings/error-file.asciidoc[leveloffset=-1]