Merge lp:~michael.nelson/charms/trusty/elasticsearch/heap-config into lp:~onlineservices-charmers/charms/trusty/elasticsearch/elasticsearch2

Proposed by Michael Nelson
Status: Merged
Merged at revision: 42
Proposed branch: lp:~michael.nelson/charms/trusty/elasticsearch/heap-config
Merge into: lp:~onlineservices-charmers/charms/trusty/elasticsearch/elasticsearch2
Diff against target: 79 lines (+43/-0)
5 files modified
config.yaml (+7/-0)
playbook.yaml (+16/-0)
templates/elasticsearch.yml (+3/-0)
templates/etc_default.j2 (+14/-0)
templates/limits.conf (+3/-0)
To merge this branch: bzr merge lp:~michael.nelson/charms/trusty/elasticsearch/heap-config
Reviewer Review Type Date Requested Status
Wes Mason (community) Approve
Bret Barker (community) Approve
Review via email: mp+277788@code.launchpad.net

Commit message

Add heap_size config option, defaulting to min(0.5*available_mem, 31g)

Description of the change

I've used http://stackoverflow.com/a/18152957/523729 as a basis. Testing it I can confirm locally that the heap size is updated in ES, using:

curl -s http://localhost:9200/_nodes/stats | python -m json.tool | grep heap_max_in_bytes

What I can't confirm is the memory lock - and that's either simply because I'm testing in an lxc container :P, or additionally because /etc/security/limits.d/ aren't applied to non-interactive users (ie. system jobs - I see this reported too).

I'll test on staging before landing. EDIT: Just tested on staging and confirm that setting the heap-size works as expected:

https://pastebin.canonical.com/144362/

Also, top shows a similar resident memory value too.

To post a comment you must log in.
Revision history for this message
Bret Barker (noise) wrote :

minor comment - with the conditional below, you can't set a heap of e.g. 1.4g and can't specify it as 1400m either. I know the recommended heap is 1/2 total ram, but for a 2g system it fails pretty miserably with any kind of load unless you do 1300-1500m heap.

Revision history for this message
Bret Barker (noise) wrote :

+1

review: Approve
Revision history for this message
Wes Mason (wesmason) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-10-01 19:00:31 +0000
+++ config.yaml 2015-11-18 20:40:41 +0000
@@ -27,3 +27,10 @@
27 By default, the admin and peer ports (9200 and 9300) are only accessible27 By default, the admin and peer ports (9200 and 9300) are only accessible
28 to clients and peers respectively. Switch this to false to enable access28 to clients and peers respectively. Switch this to false to enable access
29 from any machine.29 from any machine.
30 heap_size:
31 type: string
32 default: ""
33 description: |
34 By default, the heap size will be set to the maximum of half of the
35 available memory and 30.5G. A number in gigabytes for the Elasticsearch
36 heap size.
3037
=== modified file 'playbook.yaml'
--- playbook.yaml 2015-10-27 22:23:15 +0000
+++ playbook.yaml 2015-11-18 20:40:41 +0000
@@ -37,6 +37,22 @@
37 notify:37 notify:
38 - Restart ElasticSearch38 - Restart ElasticSearch
3939
40 - name: Update defaults
41 tags:
42 - config-changed
43 template: src={{ charm_dir }}/templates/etc_default.j2
44 dest=/etc/default/elasticsearch
45 notify:
46 - Restart ElasticSearch
47
48 - name: Set Elasticsearch user limits
49 tags:
50 - upgrade-charm
51 template: src={{ charm_dir }}/templates/limits.conf
52 dest=/etc/security/limits.d/elasticsearch.conf
53 notify:
54 - Restart ElasticSearch
55
40 - name: Open ES Port when exposed56 - name: Open ES Port when exposed
41 command: open-port 920057 command: open-port 9200
42 tags:58 tags:
4359
=== modified file 'templates/elasticsearch.yml'
--- templates/elasticsearch.yml 2015-10-30 03:32:29 +0000
+++ templates/elasticsearch.yml 2015-11-18 20:40:41 +0000
@@ -13,3 +13,6 @@
13{% for reln in relations.peer %}13{% for reln in relations.peer %}
14 - {{ reln['private-address'] }}14 - {{ reln['private-address'] }}
15{% endfor %}15{% endfor %}
16
17# https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
18bootstrap.mlockall: true
1619
=== added file 'templates/etc_default.j2'
--- templates/etc_default.j2 1970-01-01 00:00:00 +0000
+++ templates/etc_default.j2 2015-11-18 20:40:41 +0000
@@ -0,0 +1,14 @@
1# See https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
2{% set calculated_heap_size = ansible_memtotal_mb / 1024.0 / 2.0 %}
3{# min/max filters only available in ansible 1.8 #}
4{% if calculated_heap_size >= 31.5 %}{% set calculated_heap_size = 31 %}{% endif %}
5{% set heap_size = heap_size | default(calculated_heap_size, true) | float %}
6# Note: ES doesn't start if the heap size is not an int of either gigabytes (g)
7# or megabytes (m)
8{% if heap_size > 4 %}
9ES_HEAP_SIZE={{ heap_size | int }}g
10{% else %}
11ES_HEAP_SIZE={{ (heap_size * 1024) | int }}m
12{% endif %}
13MAX_OPEN_FILES=65535
14MAX_LOCKED_MEMORY=unlimited
015
=== added file 'templates/limits.conf'
--- templates/limits.conf 1970-01-01 00:00:00 +0000
+++ templates/limits.conf 2015-11-18 20:40:41 +0000
@@ -0,0 +1,3 @@
1# Ensure ES user can run with max open files and unlimited memlock.
2elasticsearch - nofile 65535
3elasticsearch - memlock unlimited

Subscribers

People subscribed via source and target branches