threadpool.asciidoc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. [[modules-threadpool]]
  2. == Thread Pool
  3. A node holds several thread pools in order to improve how threads memory consumption
  4. are managed within a node. Many of these pools also have queues associated with them,
  5. which allow pending requests to be held instead
  6. of discarded.
  7. There are several thread pools, but the important ones include:
  8. `generic`::
  9. For generic operations (e.g., background node discovery).
  10. Thread pool type is `scaling`.
  11. `search`::
  12. For count/search/suggest operations. Thread pool type is
  13. `fixed_auto_queue_size` with a size of
  14. `int((# of available_processors * 3) / 2) + 1`, and initial queue_size of
  15. `1000`.
  16. [[search-throttled]]`search_throttled`::
  17. For count/search/suggest/get operations on `search_throttled indices`. Thread pool type is
  18. `fixed_auto_queue_size` with a size of `1`, and initial queue_size of `100`.
  19. `get`::
  20. For get operations. Thread pool type is `fixed`
  21. with a size of `# of available processors`,
  22. queue_size of `1000`.
  23. `analyze`::
  24. For analyze requests. Thread pool type is `fixed` with a size of 1, queue size of 16.
  25. `write`::
  26. For single-document index/delete/update and bulk requests. Thread pool type
  27. is `fixed` with a size of `# of available processors`, queue_size of `200`.
  28. The maximum size for this pool is `1 + # of available processors`.
  29. `snapshot`::
  30. For snapshot/restore operations. Thread pool type is `scaling` with a
  31. keep-alive of `5m` and a max of `min(5, (# of available processors)/2)`.
  32. `warmer`::
  33. For segment warm-up operations. Thread pool type is `scaling` with a
  34. keep-alive of `5m` and a max of `min(5, (# of available processors)/2)`.
  35. `refresh`::
  36. For refresh operations. Thread pool type is `scaling` with a
  37. keep-alive of `5m` and a max of `min(10, (# of available processors)/2)`.
  38. `listener`::
  39. Mainly for java client executing of action when listener threaded is set to true.
  40. Thread pool type is `scaling` with a default max of `min(10, (# of available processors)/2)`.
  41. `fetch_shard_started`::
  42. For listing shard states.
  43. Thread pool type is `scaling` with keep-alive of `5m` and a default maximum
  44. size of `2 * # of available processors`.
  45. `fetch_shard_store`::
  46. For listing shard stores.
  47. Thread pool type is `scaling` with keep-alive of `5m` and a default maximum
  48. size of `2 * # of available processors`.
  49. `flush`::
  50. For <<indices-flush,flush>>, <<indices-synced-flush-api,synced flush>>, and <<index-modules-translog, translog>> `fsync` operations.
  51. Thread pool type is `scaling` with a keep-alive of `5m` and a default
  52. maximum size of `min(5, (# of available processors)/2)`.
  53. `force_merge`::
  54. For <<indices-forcemerge,force merge>> operations.
  55. Thread pool type is `fixed` with a size of 1 and an unbounded queue size.
  56. `management`::
  57. For cluster management.
  58. Thread pool type is `scaling` with a keep-alive of `5m` and a default
  59. maximum size of `5`.
  60. Changing a specific thread pool can be done by setting its type-specific
  61. parameters; for example, changing the number of threads in the `write` thread
  62. pool:
  63. [source,yaml]
  64. --------------------------------------------------
  65. thread_pool:
  66. write:
  67. size: 30
  68. --------------------------------------------------
  69. [float]
  70. [[types]]
  71. === Thread pool types
  72. The following are the types of thread pools and their respective parameters:
  73. [float]
  74. [[fixed]]
  75. ==== `fixed`
  76. The `fixed` thread pool holds a fixed size of threads to handle the
  77. requests with a queue (optionally bounded) for pending requests that
  78. have no threads to service them.
  79. The `size` parameter controls the number of threads, and defaults to the
  80. number of cores times 5.
  81. The `queue_size` allows to control the size of the queue of pending
  82. requests that have no threads to execute them. By default, it is set to
  83. `-1` which means its unbounded. When a request comes in and the queue is
  84. full, it will abort the request.
  85. [source,yaml]
  86. --------------------------------------------------
  87. thread_pool:
  88. write:
  89. size: 30
  90. queue_size: 1000
  91. --------------------------------------------------
  92. [float]
  93. [[fixed-auto-queue-size]]
  94. ==== `fixed_auto_queue_size`
  95. experimental[]
  96. The `fixed_auto_queue_size` thread pool holds a fixed size of threads to handle
  97. the requests with a bounded queue for pending requests that have no threads to
  98. service them. It's similar to the `fixed` threadpool, however, the `queue_size`
  99. automatically adjusts according to calculations based on
  100. https://en.wikipedia.org/wiki/Little%27s_law[Little's Law]. These calculations
  101. will potentially adjust the `queue_size` up or down by 50 every time
  102. `auto_queue_frame_size` operations have been completed.
  103. The `size` parameter controls the number of threads, and defaults to the
  104. number of cores times 5.
  105. The `queue_size` allows to control the initial size of the queue of pending
  106. requests that have no threads to execute them.
  107. The `min_queue_size` setting controls the minimum amount the `queue_size` can be
  108. adjusted to.
  109. The `max_queue_size` setting controls the maximum amount the `queue_size` can be
  110. adjusted to.
  111. The `auto_queue_frame_size` setting controls the number of operations during
  112. which measurement is taken before the queue is adjusted. It should be large
  113. enough that a single operation cannot unduly bias the calculation.
  114. The `target_response_time` is a time value setting that indicates the targeted
  115. average response time for tasks in the thread pool queue. If tasks are routinely
  116. above this time, the thread pool queue will be adjusted down so that tasks are
  117. rejected.
  118. [source,yaml]
  119. --------------------------------------------------
  120. thread_pool:
  121. search:
  122. size: 30
  123. queue_size: 500
  124. min_queue_size: 10
  125. max_queue_size: 1000
  126. auto_queue_frame_size: 2000
  127. target_response_time: 1s
  128. --------------------------------------------------
  129. [float]
  130. [[scaling]]
  131. ==== `scaling`
  132. The `scaling` thread pool holds a dynamic number of threads. This
  133. number is proportional to the workload and varies between the value of
  134. the `core` and `max` parameters.
  135. The `keep_alive` parameter determines how long a thread should be kept
  136. around in the thread pool without it doing any work.
  137. [source,yaml]
  138. --------------------------------------------------
  139. thread_pool:
  140. warmer:
  141. core: 1
  142. max: 8
  143. keep_alive: 2m
  144. --------------------------------------------------
  145. [float]
  146. [[processors]]
  147. === Processors setting
  148. The number of processors is automatically detected, and the thread pool
  149. settings are automatically set based on it. In some cases it can be
  150. useful to override the number of detected processors. This can be done
  151. by explicitly setting the `processors` setting.
  152. [source,yaml]
  153. --------------------------------------------------
  154. processors: 2
  155. --------------------------------------------------
  156. There are a few use-cases for explicitly overriding the `processors`
  157. setting:
  158. . If you are running multiple instances of Elasticsearch on the same
  159. host but want Elasticsearch to size its thread pools as if it only has a
  160. fraction of the CPU, you should override the `processors` setting to the
  161. desired fraction (e.g., if you're running two instances of Elasticsearch
  162. on a 16-core machine, set `processors` to 8). Note that this is an
  163. expert-level use-case and there's a lot more involved than just setting
  164. the `processors` setting as there are other considerations like changing
  165. the number of garbage collector threads, pinning processes to cores,
  166. etc.
  167. . Sometimes the number of processors is wrongly detected and in such
  168. cases explicitly setting the `processors` setting will workaround such
  169. issues.
  170. In order to check the number of processors detected, use the nodes info
  171. API with the `os` flag.