threadpool.asciidoc 6.5 KB

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