threadpool.asciidoc 7.5 KB

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