threadpool.asciidoc 7.5 KB

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