Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,33 @@ elasticsearch:
timeout: 10
instances:
- 'es'
# You may want to increase the memory limit here if you are indexing images & files.
# Note you may also need to increase the memory limits for the VM and PHP also.
# Value is in Megabytes.
memory: 256
# You can override the default JVM options here as an array. For more information
# see the docs at https://www.elastic.co/guide/en/elasticsearch/reference/master/jvm-options.html
jvm_options:
# You may want to increase the memory limits here if you are indexing images & files.
# Note you may also need to increase the memory limits for the VM and PHP also.
# Alternative way to configure the memory heap size settings at a more granular level.
- '-Xms256m'
- '-Xmx256m'
```

#### Debugging Elasticsearch
### A note on memory usage

If you do increase the memory available to Elasticsearch you should generally ensure the VM itself has double that amount of memory to ensure all extensions and services run smoothly.

The below example gives Elasticsearch 1Gig of memory and increases the VM memory to 2Gig.

```yaml
elasticsearch:
memory: 1024

virtualbox:
memory: 2048
```

### Debugging Elasticsearch

If you're having trouble with Elasticsearch there are a few common commands you can run inside Vagrant.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# @summary
#
# Merges a JVM options with a defaults array, removing any duplicates from the defaults.
#
# Parameter: JVM options array to merge with defaults.
# Parameter: Default JVM options array.
#
Puppet::Functions.create_function(:merge_jvm_options) do
# @param options The options array to merge with the default.
# @param defaults The default options array to merge against.
#
# @return array of merged options.
#
dispatch :merge? do
param 'Array', :options
param 'Array', :defaults
return_type 'Array'
end

def merge?(options, defaults)
# Keys to match JVM option values
keys = [
'-Dfile.encoding',
'-Dio.netty.noKeySetOptimization',
'-Dio.netty.noUnsafe',
'-Dio.netty.recycler.maxCapacityPerThread',
'-Djava.awt.headless',
'-Djna.nosys',
'-Dlog4j.shutdownHookEnabled',
'-Dlog4j2.disable.jmx',
'AlwaysPreTouch',
'HeapDumpOnOutOfMemoryError',
'UseG1GC',
'OmitStackTraceInFastThrow',
'CMSInitiatingOccupancyFraction',
'-Xms',
'-Xmx',
'-Xss',
'server',
'InitiatingHeapOccupancyPercent',
'PrintGCApplicationStoppedTime',
'PrintGCDateStamps',
'PrintGCDetails',
'PrintTenuringDistribution',
'UseCMSInitiatingOccupancyOnly',
'UseConcMarkSweepGC',
'UseGCLogFileRotation',
'GCLogFileSize',
'NumberOfGCLogFiles',
'Xloggc'
]

# Collect corresponding keys from the options array
option_keys = options.reduce([]) do |carry, option|
option.match(/(#{keys.join('|')})/) { |m| carry << m[1] }
carry
end

# Remove matched option keys from the defaults array
trimmed_defaults = defaults.reduce([]) do |carry, default|
carry << default if option_keys.empty? or default !~ /(#{option_keys.join('|')})/
carry
end

options + trimmed_defaults
end
end
50 changes: 28 additions & 22 deletions modules/chassis_elasticsearch/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class { 'elasticsearch':
ensure => 'absent'
}
package { 'java-common':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference this was breaking using the disabled_extensions feature with this extension

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oohh let me dig into this one and open an issue to fix it! Thanks for letting me know!

ensure => absent
}
} else {
# Default settings for install
$defaults = {
Expand All @@ -28,29 +25,38 @@
'instances' => [
'es'
],
# Ensure Java doesn't try to eat all the RAMs
'jvm_options' => [
'-Xms256m',
'-Xmx256m',
# The following rules ensure these settings are only used for
# versions of Java that support them, otherwise Elastic will fail
# to start.
'8:-XX:NumberOfGCLogFiles=32',
'8:-XX:GCLogFileSize=64m',
'8:-XX:+UseGCLogFileRotation',
'8:-XX:+PrintTenuringDistribution',
'8:-XX:+PrintGCDateStamps',
'8:-XX:+PrintGCApplicationStoppedTime',
'8:-XX:+UseConcMarkSweepGC',
'8:-XX:+UseCMSInitiatingOccupancyOnly',
'-XX:+UseG1GC',
'11:-XX:InitiatingHeapOccupancyPercent=75'
],
# Ensure Java doesn't try to eat all the RAMs by default
'memory' => 256,
'jvm_options' => [],
}

# Allow override from config.yaml
$options = deep_merge($defaults, $config[elasticsearch])

# Ensure memory is an integer
$memory = Integer($options[memory])

# Create default jvm_options using memory setting
$jvm_options_defaults = [
"-Xms${memory}m",
"-Xmx${memory}m",
'-XX:+UseG1GC',
'8:-XX:NumberOfGCLogFiles=32',
'8:-XX:GCLogFileSize=64m',
'8:-XX:+UseGCLogFileRotation',
'8:-Xloggc:/var/log/elasticsearch/es/gc.log',
'8:-XX:+PrintGCDetails',
'8:-XX:+PrintTenuringDistribution',
'8:-XX:+PrintGCDateStamps',
'8:-XX:+PrintGCApplicationStoppedTime',
'8:-XX:+UseConcMarkSweepGC',
'8:-XX:+UseCMSInitiatingOccupancyOnly',
'11:-XX:InitiatingHeapOccupancyPercent=75'
]

# Merge JVM options using our custom function
$jvm_options = merge_jvm_options($options[jvm_options], $jvm_options_defaults)

# Support legacy repo version values.
$repo_version = regsubst($options[repo_version], '^(\d+).*', '\\1')

Expand All @@ -63,7 +69,7 @@
class { 'elasticsearch':
manage_repo => true,
version => $options[version],
jvm_options => $options[jvm_options],
jvm_options => $jvm_options,
api_protocol => 'http',
api_host => $options[host],
api_port => $options[port],
Expand Down