Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 763b31f

Browse files
committed
fd, dont touch section
1 parent 9493d5f commit 763b31f

4 files changed

+150
-30
lines changed

510_Deployment.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ include::510_Deployment/40_config.asciidoc[]
1111

1212
include::510_Deployment/50_heap.asciidoc[]
1313

14+
include::510_Deployment/60_file_descriptors.asciidoc[]
15+
1416
=== Post-Deployment
1517

1618
-Prereqs

510_Deployment/30_other.asciidoc

-30
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,6 @@ clusters, the first step is often to remove all custom configurations. About
3535
half the time this alone restores stability and performance.
3636
****
3737

38-
=== Garbage Collector
39-
40-
As briefly introduces in <<garbage_collector_primer>>, the JVM uses a garbage
41-
collector to free unused memory. This tip is really an extension of the last tip,
42-
but deserves it's own section for emphasis:
43-
44-
Do not change the default garbage collector!
45-
46-
The default GC for Elasticsearch is Concurrent-Mark and Sweep (CMS). This GC
47-
runs concurrently with the execution of the application so that it can minimize
48-
pauses. It does, however, have two stop-the-world phases. It also has trouble
49-
collecting large heaps.
50-
51-
Despite these downsides, it is currently the best GC for low-latency server software
52-
like Elasticsearch. The official recommendation is to use CMS.
53-
54-
There is a newer GC called the Garbage First GC (G1GC). This newer GC is designed
55-
to minimize pausing even more than CMS, and operate on large heaps. It works
56-
by dividing the heap into regions and predicting which regions contain the most
57-
reclaimable space. By collecting those regions first ("garbage first"), it can
58-
minimize pauses and operate on very large heaps.
59-
60-
Sounds great! Unfortunately, G1GC is still new and fresh bugs are found routinely.
61-
These bugs are usually of the segfault variety, and will cause hard crashes.
62-
The Lucene test suite is brutal on GC algorithms, and it seems that G1GC hasn't
63-
had the kinks worked out yet.
64-
65-
We would like to recommend G1GC someday, but for now, it is simply not stable
66-
enough to meet the demands of Elasticsearch and Lucene.
67-
6838
=== TransportClient vs NodeClient
6939

7040
If you are using Java, you may wonder when to use the TransportClient vs the

510_Deployment/45_dont_touch.asciidoc

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
=== Don't touch these settings!
3+
4+
There are a few hotspots in Elasticsearch that people just can't seem to avoid
5+
tweaking. We understand: knobs just beg to be turned.
6+
7+
But of all the knobs to turn, these you should _really_ leave alone. They are
8+
often abused and will contribute to terrible stability or terrible performance.
9+
Or both.
10+
11+
==== Garbage Collector
12+
13+
As briefly introduces in <<garbage_collector_primer>>, the JVM uses a garbage
14+
collector to free unused memory. This tip is really an extension of the last tip,
15+
but deserves it's own section for emphasis:
16+
17+
Do not change the default garbage collector!
18+
19+
The default GC for Elasticsearch is Concurrent-Mark and Sweep (CMS). This GC
20+
runs concurrently with the execution of the application so that it can minimize
21+
pauses. It does, however, have two stop-the-world phases. It also has trouble
22+
collecting large heaps.
23+
24+
Despite these downsides, it is currently the best GC for low-latency server software
25+
like Elasticsearch. The official recommendation is to use CMS.
26+
27+
There is a newer GC called the Garbage First GC (G1GC). This newer GC is designed
28+
to minimize pausing even more than CMS, and operate on large heaps. It works
29+
by dividing the heap into regions and predicting which regions contain the most
30+
reclaimable space. By collecting those regions first ("garbage first"), it can
31+
minimize pauses and operate on very large heaps.
32+
33+
Sounds great! Unfortunately, G1GC is still new and fresh bugs are found routinely.
34+
These bugs are usually of the segfault variety, and will cause hard crashes.
35+
The Lucene test suite is brutal on GC algorithms, and it seems that G1GC hasn't
36+
had the kinks worked out yet.
37+
38+
We would like to recommend G1GC someday, but for now, it is simply not stable
39+
enough to meet the demands of Elasticsearch and Lucene.
40+
41+
==== Threadpools
42+
43+
Everyone _loves_ to tweak threadpools. For whatever reason, it seems people
44+
cannot resist increasing thread counts. Indexing a lot? More threads! Searching
45+
a lot? More threads! Node idling 95% of the time? More threads!
46+
47+
The default threadpool settings in Elasticsearch are very sensible. For all
48+
threadpools (except `search`) the threadcount is set to the number of CPU cores.
49+
If you have 8 cores, you can only be running 8 threads simultaneously. It makes
50+
sense to only assign 8 threads to any particular threadpool.
51+
52+
Search gets a larger threadpool, and is configured to `# cores * 3`.
53+
54+
You might argue that some threads can block (such as on a disk I/O operation),
55+
which is why you need more threads. This is not actually not a problem in Elasticsearch:
56+
much of the disk IO is handled by threads managed by Lucene, not Elasticsearch.
57+
58+
Furthermore, threadpools cooperate by passing work between each other. You don't
59+
need to worry about a networking thread blocking because it is waiting on a disk
60+
write. The networking thread will have long since handed off that work unit to
61+
another threadpool and gotten back to networking.
62+
63+
Finally, the compute capacity of your process is finite. More threads just forces
64+
the processor to switch thread contexts. A processor can only run one thread
65+
at a time, so when it needs to switch to a different thread, it stores the current
66+
state (registers, etc) and loads another thread. If you are lucky, the switch
67+
will happen on the same core. If you are unlucky, the switch may migrate to a
68+
different core and require transport on inter-core communication bus.
69+
70+
This context switching eats up cycles simply doing administrative housekeeping
71+
-- estimates can peg it as high as 30us on modern CPUs. So unless the thread
72+
will be blocked for longer than 30us, it is highly likely that that time would
73+
have been better spent just processing and finishing early.
74+
75+
People routinely set threadpools to silly values. On 8 core machines, we have
76+
run across configs with 60, 100 or even 1000 threads. These settings will simply
77+
thrash the CPU more than getting real work done.
78+
79+
So. Next time you want to tweak a threadpool...please don't. And if you
80+
_absolutely cannot resist_, please keep your core count in mind and perhaps set
81+
the count to double. More than that is just a waste.
82+
83+
84+
85+
86+
87+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
=== File Descriptors and MMap
3+
4+
Lucene uses are _very_ large number of files. At the same time, Elasticsearch
5+
uses a large number of sockets to communicate between nodes and HTTP clients.
6+
All of this requires available file descriptors.
7+
8+
Sadly, many modern linux distributions ship with a paltry 1024 file descriptors
9+
allowed per process. This is _far_ too low for even a small Elasticsearch
10+
node, let alone one that is handling hundreds of indices.
11+
12+
You should increase your file descriptor count to something very large, such as
13+
64,000. This process is irritatingly difficult and highly dependent on your
14+
particular OS and distribution. Consult the documentation for your OS to determine
15+
how best to change the allowed file descriptor count.
16+
17+
Once you think you've changed it, check Elasticsearch to make sure it really does
18+
have enough file descriptors. You can check with:
19+
20+
[source,js]
21+
----
22+
GET /_nodes/process
23+
24+
{
25+
"cluster_name": "elasticsearch__zach",
26+
"nodes": {
27+
"TGn9iO2_QQKb0kavcLbnDw": {
28+
"name": "Zach",
29+
"transport_address": "inet[/192.168.1.131:9300]",
30+
"host": "zacharys-air",
31+
"ip": "192.168.1.131",
32+
"version": "2.0.0-SNAPSHOT",
33+
"build": "612f461",
34+
"http_address": "inet[/192.168.1.131:9200]",
35+
"process": {
36+
"refresh_interval_in_millis": 1000,
37+
"id": 19808,
38+
"max_file_descriptors": 64000, <1>
39+
"mlockall": true
40+
}
41+
}
42+
}
43+
}
44+
----
45+
<1> The `max_file_descriptors` field will inform you how many available descriptors
46+
the Elasticsearch process can access
47+
48+
Elasticsearch also uses a mix of NioFS and MMapFS for the various files. Ensure
49+
that the maximum map count so that there is ample virtual memory available for
50+
mmapped files. This can be set temporarily with:
51+
52+
[source,js]
53+
----
54+
sysctl -w vm.max_map_count=262144
55+
----
56+
57+
Or permanently by modifying `vm.max_map_count` setting in your `/etc/sysctl.conf`
58+
59+
60+
61+

0 commit comments

Comments
 (0)