geerlingguy / ansible-role-elasticsearch

Ansible Role - Elasticsearch
https://galaxy.ansible.com/geerlingguy/elasticsearch/
MIT License
185 stars 208 forks source link

Add ability to configure heap size #7

Closed geerlingguy closed 5 years ago

geerlingguy commented 9 years ago

There's an ES_HEAP_SIZE environment variable that can be used to limit Elasticsearch RAM usage. It would be nice to allow that to be configured for the role. It's configured (along with other directives) inside /etc/default/elasticsearch.

astik commented 6 years ago

I just use your ansible role to install elastic search :

# dpkg --status elasticsearch
Package: elasticsearch
Status: install ok installed
Priority: optional
Section: web
Installed-Size: 36755
Maintainer: Elasticsearch Team <info@elastic.co>
Architecture: all
Source: elasticsearch
Version: 5.6.10
Depends: libc6, adduser, bash
Conffiles:
 /etc/elasticsearch/elasticsearch.yml 31655f8d9bce94581724510ebc90ed75
 /etc/elasticsearch/jvm.options fc1db089e7603d1064d974d794baa9e6
 /etc/elasticsearch/log4j2.properties 7637854ddf5af38795d69f87bb6b1d76
 /usr/lib/systemd/system/elasticsearch.service d7a5cf6b0ab7ebe37749324c9d4aae69
 /etc/init.d/elasticsearch 41d03d1e8b83ba1779b0fb44ddc57383
 /etc/default/elasticsearch 672c8561909e81d49094953fe6fd35ee
Description: Elasticsearch is a distributed RESTful search engine built for the cloud. Reference documentation can be found at https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html and the 'Elasticsearch: The Definitive Guide' book can be found at https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
 Elasticsearch subproject :distribution:deb
Homepage: https://www.elastic.co/

Version is 5.6.10, 2 month ago it uses to be 2.4.6.

Elastic search is now packaged with a new conf file : /etc/elasticsearch/jvm.options (on debian 9). It contains some jvm options, especially :

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms2g
-Xmx2g

So the file for setting the heapsize is now jvm.options.

astik commented 6 years ago

One problem i have with the new default file and the ansible role is the fact that the role is waiting for elastic search to run. As it is expecting to get 2g of RAM and I only have 1.3, the process is killed (There is insufficient memory for the Java Runtime Environment to continue), and the role is waiting for the timeout to stop with an error. It would be great to have a way to define the heapsize setting define before starting the process. Or, maybe a way to disable the automatic boot.

Cyclonecode commented 5 years ago

I have the same problem on my vagrant box, the machine only have <1g RAM and the task Make sure Elasticsearch is running before proceeding. times out in this case. If I change the -Xms512mb in the jvm.options file before trying to start the service, it works as expected. The solution to this should be to be able to override the -Xms2g parts in the jvm.options file.

Cyclonecode commented 5 years ago

The following pull request fixes this issue: https://github.com/geerlingguy/ansible-role-elasticsearch/pull/42

geerlingguy commented 5 years ago

Btw, for newer versions of Elasticsearch, the options are inside /etc/elasticsearch/jvm.options. See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html

In my case, I wanted to increase -Xmx1g (the default) to -Xmx4g, so an Ansible task that could do this (instead of templating the entire file) is:

- name: Increase Elasticsearch's heap size.
   lineinfile:
    dest: /etc/elasticsearch/jvm.options
    regexp: '^-Xmx.+$'
    line: '-Xmx4g'
    state: present
geerlingguy commented 5 years ago

Fixed via #42.