heap-size.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.
  9. The value for these setting depends on the amount of RAM available on your
  10. server. Good rules of thumb are:
  11. * Set the minimum heap size (`Xms`) and maximum heap size (`Xmx`) to be equal to
  12. each other.
  13. * The more heap available to Elasticsearch, the more memory it can use for
  14. caching. But note that too much heap can subject you to long garbage
  15. collection pauses.
  16. * Set `Xmx` to no more than 50% of your physical RAM, to ensure that there is
  17. enough physical RAM left for kernel file system caches.
  18. * Don’t set `Xmx` to above the cutoff that the JVM uses for compressed object
  19. pointers (compressed oops); the exact cutoff varies but is near 32 GB. You can
  20. verify that you are under the limit by looking for a line in the logs like the
  21. following:
  22. +
  23. heap size [1.9gb], compressed ordinary object pointers [true]
  24. * Even better, try to stay below the threshold for zero-based compressed oops;
  25. the exact cutoff varies but 26 GB is safe on most systems, but can be as large
  26. as 30 GB on some systems. You can verify that you are under the limit by
  27. starting Elasticsearch with the JVM options `-XX:+UnlockDiagnosticVMOptions
  28. -XX:+PrintCompressedOopsMode` and looking for a line like the following:
  29. +
  30. --
  31. heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
  32. showing that zero-based compressed oops are enabled instead of
  33. heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
  34. --
  35. Here are examples of how to set the heap size via the jvm.options file:
  36. [source,txt]
  37. ------------------
  38. -Xms2g <1>
  39. -Xmx2g <2>
  40. ------------------
  41. <1> Set the minimum heap size to 2g.
  42. <2> Set the maximum heap size to 2g.
  43. It is also possible to set the heap size via an environment variable. This can
  44. be done by commenting out the `Xms` and `Xmx` settings in the
  45. <<jvm-options,`jvm.options`>> file and setting these values via `ES_JAVA_OPTS`:
  46. [source,sh]
  47. ------------------
  48. ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <1>
  49. ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch <2>
  50. ------------------
  51. <1> Set the minimum and maximum heap size to 2 GB.
  52. <2> Set the minimum and maximum heap size to 4000 MB.
  53. NOTE: Configuring the heap for the <<windows-service,Windows service>> is
  54. different than the above. The values initially populated for the Windows service
  55. can be configured as above but are different after the service has been
  56. installed. Consult the <<windows-service,Windows service documentation>> for
  57. additional details.