heap-size.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. [[heap-size-settings]]
  2. [discrete]
  3. === Heap size settings
  4. By default, {es} tells the JVM to use a heap with a minimum and maximum
  5. size of 1 GB. When moving to production, it is important to configure heap size
  6. to ensure that {es} has enough heap available.
  7. {es} will assign the entire heap specified in
  8. <<jvm-options,jvm.options>> via the `Xms` (minimum heap size) and `Xmx` (maximum
  9. heap size) settings. These two settings must be equal to each other.
  10. The value for these settings depends on the amount of RAM available on your
  11. server:
  12. * Set `Xmx` and `Xms` to no more than 50% of your physical RAM. {es} requires
  13. memory for purposes other than the JVM heap and it is important to leave
  14. space for this. For instance, {es} uses off-heap buffers for efficient
  15. network communication, relies on the operating system's filesystem cache for
  16. efficient access to files, and the JVM itself requires some memory too. It is
  17. normal to observe the {es} process using more memory than the limit
  18. configured with the `Xmx` setting.
  19. * Set `Xmx` and `Xms` to no more than the threshold that the JVM uses for
  20. compressed object pointers (compressed oops). The exact threshold varies but
  21. is near 32 GB. You can verify that you are under the threshold by looking for a line in the logs like the following:
  22. +
  23. [source,txt]
  24. ----
  25. heap size [1.9gb], compressed ordinary object pointers [true]
  26. ----
  27. * Set `Xmx` and `Xms` to no more than the threshold for zero-based
  28. compressed oops. The exact threshold varies but 26 GB is safe on most
  29. systems and can be as large as 30 GB on some systems. You can verify that
  30. you are under this threshold by starting {es} with the JVM options
  31. `-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode` and looking for
  32. a line like the following:
  33. +
  34. [source,txt]
  35. ----
  36. heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
  37. ----
  38. +
  39. This line shows that zero-based compressed oops are enabled. If zero-based
  40. compressed oops are not enabled, you'll see a line like the following instead:
  41. +
  42. [source,txt]
  43. ----
  44. heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
  45. ----
  46. The more heap available to {es}, the more memory it can use for its internal
  47. caches, but the less memory it leaves available for the operating system to use
  48. for the filesystem cache. Also, larger heaps can cause longer garbage
  49. collection pauses.
  50. Here is an example of how to set the heap size via a `jvm.options.d/` file:
  51. [source,txt]
  52. ------------------
  53. -Xms2g <1>
  54. -Xmx2g <2>
  55. ------------------
  56. <1> Set the minimum heap size to 2g.
  57. <2> Set the maximum heap size to 2g.
  58. Using `jvm.options.d` is the preferred method for configuring the heap size for
  59. production deployments.
  60. It is also possible to set the heap size via the `ES_JAVA_OPTS` environment
  61. variable. This is generally discouraged for production deployments but is useful
  62. for testing because it overrides all other means of setting JVM options.
  63. [source,sh]
  64. ------------------
  65. ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <1>
  66. ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch <2>
  67. ------------------
  68. <1> Set the minimum and maximum heap size to 2 GB.
  69. <2> Set the minimum and maximum heap size to 4000 MB.
  70. NOTE: Configuring the heap for the <<windows-service,Windows service>> is
  71. different than the above. The values initially populated for the Windows
  72. service can be configured as above but are different after the service has been
  73. installed. Consult the <<windows-service,Windows service documentation>> for
  74. additional details.