heap-size.asciidoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. [[heap-size]]
  2. === Setting the heap size
  3. By default, Elasticsearch tells the JVM to use a heap with a minimum and maximum
  4. size of 1 GB. When moving to production, it is important to configure heap size
  5. to ensure that Elasticsearch has enough heap available.
  6. Elasticsearch will assign the entire heap specified in
  7. <<jvm-options,jvm.options>> via the `Xms` (minimum heap size) and `Xmx` (maximum
  8. heap size) settings. You should set these two settings to be equal to each
  9. 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
  22. line in the logs like the following:
  23. +
  24. heap size [1.9gb], compressed ordinary object pointers [true]
  25. * Ideally set `Xmx` and `Xms` to no more than the threshold for zero-based
  26. compressed oops; the exact threshold varies but 26 GB is safe on most
  27. systems, but can be as large as 30 GB on some systems. You can verify that
  28. you are under this threshold by starting {es} with the JVM options
  29. `-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode` and looking for
  30. a line like the following:
  31. +
  32. --
  33. heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
  34. showing that zero-based compressed oops are enabled. If zero-based compressed
  35. oops are not enabled then you will see a line like the following instead:
  36. heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
  37. --
  38. The more heap available to {es}, the more memory it can use for its internal
  39. caches, but the less memory it leaves available for the operating system to use
  40. for the filesystem cache. Also, larger heaps can cause longer garbage
  41. collection pauses.
  42. Here are examples of how to set the heap size via the jvm.options file:
  43. [source,txt]
  44. ------------------
  45. -Xms2g <1>
  46. -Xmx2g <2>
  47. ------------------
  48. <1> Set the minimum heap size to 2g.
  49. <2> Set the maximum heap size to 2g.
  50. It is also possible to set the heap size via an environment variable. This can
  51. be done by commenting out the `Xms` and `Xmx` settings in the
  52. <<jvm-options,`jvm.options`>> file and setting these values via `ES_JAVA_OPTS`:
  53. [source,sh]
  54. ------------------
  55. ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <1>
  56. ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch <2>
  57. ------------------
  58. <1> Set the minimum and maximum heap size to 2 GB.
  59. <2> Set the minimum and maximum heap size to 4000 MB.
  60. NOTE: Configuring the heap for the <<windows-service,Windows service>> is
  61. different than the above. The values initially populated for the Windows
  62. service can be configured as above but are different after the service has been
  63. installed. Consult the <<windows-service,Windows service documentation>> for
  64. additional details.