Elasticsearch Optimization or Elascitsearch Performance Tuning
ElasticSearch Optimization
ElasticSearch Performance Tuning
How to make Elasticsearch Efficient
Running Elasticsearch may costs you in an unwanted way by eating up resources of your infrastructure. Hence you should do optimization/tuning to run it cost and performance efficiently. This post will drive you through the basic optimization of Elasticsearch. Following are some points to understand first.
- Indexes are horizontally split into shards.
- Shards are distributed by Elasticsearch on different Nodes.
- A Node is a java process.
- There could be more than one Node on the same machine.
- Nodes are formed automatically to form clusters.
- Shards replica would be on different Node to prevent failure.
The above points can be understood by seeing the following diagram..
Example of a cluster with 2 nodes holding one index with 4 shards and 1 replica shard
There are three roles a node can play
1. Master – A master node is responsible for managing state of the cluster and distribution of shards in the cluster. If the master goes down, the cluster automatically starts election process and choose a master.
2. Data – Data node is responsible for holding all the indexes in shards. It perform indexing and execute search queries.
3. Client – Client node act as the communication interface for the coming requests and distribute it to data nodes. Than it aggregate the overall results from all the shards and responds back.
Scalable Architecture
Performance Tuning
# Set Heap Size
# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g
ES_HEAP_SIZE=2g
# Process should not get swapped
To set this to 1 add the following line to /etc/sysctl.confvm.swappiness = 1
# Java Pointers
On 64-bit system the ordinary object pointers (POP) can take 8 bytes of memory to address the complete memory. But we can compress the pointers to take only 4 bytes by setting the heap size to under 32gb.
Therefore if the Elasticsearch run on a JDK before 6u23 release, than we should use XX:UseCompressedOops flag if the heap size is less than 32gb.