threadpool.asciidoc 7.3 KB

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