threadpool.asciidoc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. [[modules-threadpool]]
  2. === Thread pools
  3. A node uses several thread pools to manage memory consumption.
  4. Queues associated with many of the thread pools enable pending requests
  5. to be held instead of discarded.
  6. There are several thread pools, but the important ones include:
  7. `generic`::
  8. For generic operations (for example, background node discovery).
  9. Thread pool type is `scaling`.
  10. [[search-threadpool]]
  11. `search`::
  12. For coordination of count/search operations at the shard level whose computation
  13. is offloaded to the search_worker thread pool. Used also by fetch and other search
  14. related operations Thread pool type is `fixed` with a size of `int((`<<node.processors,
  15. `# of allocated processors`>>`pass:[ * ]3) / 2) + 1`, and queue_size of `1000`.
  16. `search_worker`::
  17. For the heavy workload of count/search operations that may be executed concurrently
  18. across segments within the same shard when possible. Thread pool type is `fixed`
  19. with a size of `int((`<<node.processors, `# of allocated processors`>>`pass:[ * ]3) / 2) + 1`, and unbounded queue_size .
  20. [[search-throttled]]`search_throttled`::
  21. For count/search/suggest/get operations on `search_throttled indices`.
  22. Thread pool type is `fixed` with a size of `1`, and queue_size of `100`.
  23. `search_coordination`::
  24. For lightweight search-related coordination operations. Thread pool type is
  25. `fixed` with a size of `(`<<node.processors, `# of allocated processors`>>`) / 2`,
  26. and queue_size of `1000`.
  27. `get`::
  28. For get operations. Thread pool type is
  29. `fixed` with a size of `int((`<<node.processors,
  30. `# of allocated processors`>>`pass:[ * ]3) / 2) + 1`, and queue_size of `1000`.
  31. `analyze`::
  32. For analyze requests. Thread pool type is `fixed` with a size of `1`, queue
  33. size of `16`.
  34. `write`::
  35. For single-document index/delete/update, ingest processors, and bulk requests. Thread pool type
  36. is `fixed` with a size of <<node.processors, `# of allocated processors`>>,
  37. queue_size of `10000`. The maximum size for this pool is
  38. `pass:[1 + ]`<<node.processors, `# of allocated processors`>>.
  39. `snapshot`::
  40. For snapshot/restore operations. Thread pool type is `scaling` with a
  41. keep-alive of `5m`. On nodes with at least 750MB of heap the maximum size
  42. of this pool is `10` by default. On nodes with less than 750MB of heap the
  43. maximum size of this pool is `min(5, (`<<node.processors,
  44. `# of allocated processors`>>`) / 2)` by default.
  45. `snapshot_meta`::
  46. For snapshot repository metadata read operations. Thread pool type is `scaling` with a
  47. keep-alive of `5m` and a max of `min(50, (`<<node.processors,
  48. `# of allocated processors`>>`* 3))`.
  49. `warmer`::
  50. For segment warm-up operations. Thread pool type is `scaling` with a
  51. keep-alive of `5m` and a max of `min(5, (`<<node.processors,
  52. `# of allocated processors`>>`) / 2)`.
  53. `refresh`::
  54. For refresh operations. Thread pool type is `scaling` with a
  55. keep-alive of `5m` and a max of `min(10, (`<<node.processors,
  56. `# of allocated processors`>>`) / 2)`.
  57. `fetch_shard_started`::
  58. For listing shard states.
  59. Thread pool type is `scaling` with keep-alive of `5m` and a default maximum
  60. size of `pass:[2 * ]`<<node.processors, `# of allocated processors`>>.
  61. `fetch_shard_store`::
  62. For listing shard stores.
  63. Thread pool type is `scaling` with keep-alive of `5m` and a default maximum
  64. size of `pass:[2 * ]`<<node.processors, `# of allocated processors`>>.
  65. `flush`::
  66. For <<indices-flush,flush>> and <<index-modules-translog, translog>> `fsync`
  67. operations. Thread pool type is `scaling` with a keep-alive of `5m` and a
  68. default maximum size of `min(5, (`<<node.processors,
  69. `# of allocated processors`>>`) / 2)`.
  70. `force_merge`::
  71. For <<indices-forcemerge,force merge>> operations.
  72. Thread pool type is `fixed` with a size of `max(1, (`<<node.processors,
  73. `# of allocated processors`>>`) / 8)` and an unbounded queue size.
  74. `management`::
  75. For cluster management.
  76. Thread pool type is `scaling` with a keep-alive of `5m` and a default
  77. maximum size of `5`.
  78. `system_read`::
  79. For read operations on system indices.
  80. Thread pool type is `fixed` with a default maximum size of
  81. `min(5, (`<<node.processors, `# of allocated processors`>>`) / 2)`.
  82. `system_write`::
  83. For write operations on system indices.
  84. Thread pool type is `fixed` with a default maximum size of
  85. `min(5, (`<<node.processors, `# of allocated processors`>>`) / 2)`.
  86. `system_critical_read`::
  87. For critical read operations on system indices.
  88. Thread pool type is `fixed` with a default maximum size of
  89. `min(5, (`<<node.processors, `# of allocated processors`>>`) / 2)`.
  90. `system_critical_write`::
  91. For critical write operations on system indices.
  92. Thread pool type is `fixed` with a default maximum size of
  93. `min(5, (`<<node.processors, `# of allocated processors`>>`) / 2)`.
  94. `watcher`::
  95. For <<xpack-alerting,watch executions>>.
  96. Thread pool type is `fixed` with a default maximum size of
  97. `min(5 * (`<<node.processors, `# of allocated processors`>>`), 50)`
  98. and queue_size of `1000`.
  99. Thread pool settings are <<static-cluster-setting,static>> and can be changed by
  100. editing `elasticsearch.yml`. Changing a specific thread pool can be done by
  101. setting its type-specific parameters; for example, changing the number of
  102. threads in the `write` thread pool:
  103. [source,yaml]
  104. --------------------------------------------------
  105. thread_pool:
  106. write:
  107. size: 30
  108. --------------------------------------------------
  109. [[thread-pool-types]]
  110. ==== Thread pool types
  111. The following are the types of thread pools and their respective parameters:
  112. [[fixed-thread-pool]]
  113. ===== `fixed`
  114. The `fixed` thread pool holds a fixed size of threads to handle the
  115. requests with a queue (optionally bounded) for pending requests that
  116. have no threads to service them.
  117. The `size` parameter controls the number of threads.
  118. The `queue_size` allows to control the size of the queue of pending
  119. requests that have no threads to execute them. By default, it is set to
  120. `-1` which means its unbounded. When a request comes in and the queue is
  121. full, it will abort the request.
  122. [source,yaml]
  123. --------------------------------------------------
  124. thread_pool:
  125. write:
  126. size: 30
  127. queue_size: 1000
  128. --------------------------------------------------
  129. [[scaling-thread-pool]]
  130. ===== `scaling`
  131. The `scaling` thread pool holds a dynamic number of threads. This
  132. number is proportional to the workload and varies between the value of
  133. the `core` and `max` parameters.
  134. The `keep_alive` parameter determines how long a thread should be kept
  135. around in the thread pool without it doing any work.
  136. [source,yaml]
  137. --------------------------------------------------
  138. thread_pool:
  139. warmer:
  140. core: 1
  141. max: 8
  142. keep_alive: 2m
  143. --------------------------------------------------
  144. [[node.processors]]
  145. ==== Allocated processors setting
  146. The number of processors is automatically detected, and the thread pool settings
  147. are automatically set based on it. In some cases it can be useful to override
  148. the number of detected processors. This can be done by explicitly setting the
  149. `node.processors` setting. This setting is bounded by the number of available
  150. processors and accepts floating point numbers, which can be useful in environments
  151. where the {es} nodes are configured to run with CPU limits, such as cpu
  152. shares or quota under `Cgroups`.
  153. [source,yaml]
  154. --------------------------------------------------
  155. node.processors: 2
  156. --------------------------------------------------
  157. There are a few use-cases for explicitly overriding the `node.processors`
  158. setting:
  159. . If you are running multiple instances of {es} on the same host but want
  160. {es} to size its thread pools as if it only has a fraction of the CPU, you
  161. should override the `node.processors` setting to the desired fraction, for
  162. example, if you're running two instances of {es} on a 16-core machine, set
  163. `node.processors` to 8. Note that this is an expert-level use case and there's
  164. a lot more involved than just setting the `node.processors` setting as there are
  165. other considerations like changing the number of garbage collector threads,
  166. pinning processes to cores, and so on.
  167. . Sometimes the number of processors is wrongly detected and in such cases
  168. explicitly setting the `node.processors` setting will workaround such issues.
  169. In order to check the number of processors detected, use the nodes info
  170. API with the `os` flag.