Set default elasticsearch heap size to 2GB (Alternate PR) by aidando73 · Pull Request #5684 · testcontainers/testcontainers-java (original) (raw)

Proposed fix for issue #5393. Thought I could help to address comments from @DKarim 's PR #5398 as it looks like he is busy (hope I am not intruding with this PR @DKarim). Had some additional improvements I wanted to make as well.

Rationale behind changes

Decided against the additional method that @DKarim introduced. I think it's better to introduce additional public api in a separate issue that way we can determine if there's a real demand for it otherwise we'd be adding extra complexity and maintenance burden for little gain.

Also opted for usage of the /usr/share/elasticsearch/config/jvm.options.d/ folder over the ES_JAVA_OPTS environment variable. For a few reasons:

  1. Elasticsearch 8 seems to have renamed ES_JAVA_OPTS to CLI_JAVA_OPTS on their docs https://www.elastic.co/guide/en/elasticsearch/reference/current/advanced-configuration.html. After testing, it seems like they have backwards compatibility for ES_JAVA_OPTS - but usage of both at the same time is unpredictable.
  2. The previous approach overrides all user defined jvm options in /usr/share/elasticsearch/config/jvm.options.d/, thus if any user had memory defined in one of these files then the default would have overwritten it:

The ES_JAVA_OPTS variable overrides all other JVM options.

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/advanced-configuration.html#set-jvm-options