threadpool.asciidoc 7.9 KB

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