fix-common-cluster-issues.asciidoc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. [[fix-common-cluster-issues]]
  2. == Fix common cluster issues
  3. This guide describes how to fix common errors and problems with {es} clusters.
  4. [discrete]
  5. === Error: disk usage exceeded flood-stage watermark, index has read-only-allow-delete block
  6. This error indicates a data node is critically low on disk space and has reached
  7. the <<cluster-routing-flood-stage,flood-stage disk usage watermark>>. To prevent
  8. a full disk, when a node reaches this watermark, {es} blocks writes to any index
  9. with a shard on the node. If the block affects related system indices, {kib} and
  10. other {stack} features may become unavailable.
  11. {es} will automatically remove the write block when the affected node's disk
  12. usage goes below the <<cluster-routing-watermark-high,high disk watermark>>. To
  13. achieve this, {es} automatically moves some of the affected node's shards to
  14. other nodes in the same data tier.
  15. To verify that shards are moving off the affected node, use the <<cat-shards,cat
  16. shards API>>.
  17. [source,console]
  18. ----
  19. GET _cat/shards?v=true
  20. ----
  21. If shards remain on the node, use the <<cluster-allocation-explain,cluster
  22. allocation explanation API>> to get an explanation for their allocation status.
  23. [source,console]
  24. ----
  25. GET _cluster/allocation/explain
  26. {
  27. "index": "my-index",
  28. "shard": 0,
  29. "primary": false,
  30. "current_node": "my-node"
  31. }
  32. ----
  33. // TEST[s/^/PUT my-index\n/]
  34. // TEST[s/"primary": false,/"primary": false/]
  35. // TEST[s/"current_node": "my-node"//]
  36. To immediately restore write operations, you can temporarily increase the disk
  37. watermarks and remove the write block.
  38. [source,console]
  39. ----
  40. PUT _cluster/settings
  41. {
  42. "persistent": {
  43. "cluster.routing.allocation.disk.watermark.low": "90%",
  44. "cluster.routing.allocation.disk.watermark.high": "95%",
  45. "cluster.routing.allocation.disk.watermark.flood_stage": "97%"
  46. }
  47. }
  48. PUT */_settings?expand_wildcards=all
  49. {
  50. "index.blocks.read_only_allow_delete": null
  51. }
  52. ----
  53. // TEST[s/^/PUT my-index\n/]
  54. As a long-term solution, we recommend you add nodes to the affected data tiers
  55. or upgrade existing nodes to increase disk space. To free up additional disk
  56. space, you can delete unneeded indices using the <<indices-delete-index,delete
  57. index API>>.
  58. [source,console]
  59. ----
  60. DELETE my-index
  61. ----
  62. // TEST[s/^/PUT my-index\n/]
  63. When a long-term solution is in place, reset or reconfigure the disk watermarks.
  64. [source,console]
  65. ----
  66. PUT _cluster/settings
  67. {
  68. "persistent": {
  69. "cluster.routing.allocation.disk.watermark.low": null,
  70. "cluster.routing.allocation.disk.watermark.high": null,
  71. "cluster.routing.allocation.disk.watermark.flood_stage": null
  72. }
  73. }
  74. ----
  75. [discrete]
  76. [[circuit-breaker-errors]]
  77. === Circuit breaker errors
  78. {es} uses <<circuit-breaker,circuit breakers>> to prevent nodes from running out
  79. of JVM heap memory. If Elasticsearch estimates an operation would exceed a
  80. circuit breaker, it stops the operation and returns an error.
  81. By default, the <<parent-circuit-breaker,parent circuit breaker>> triggers at
  82. 95% JVM memory usage. To prevent errors, we recommend taking steps to reduce
  83. memory pressure if usage consistently exceeds 85%.
  84. [discrete]
  85. [[diagnose-circuit-breaker-errors]]
  86. ==== Diagnose circuit breaker errors
  87. **Error messages**
  88. If a request triggers a circuit breaker, {es} returns an error with a `429` HTTP
  89. status code.
  90. [source,js]
  91. ----
  92. {
  93. 'error': {
  94. 'type': 'circuit_breaking_exception',
  95. 'reason': '[parent] Data too large, data for [<http_request>] would be [123848638/118.1mb], which is larger than the limit of [123273216/117.5mb], real usage: [120182112/114.6mb], new bytes reserved: [3666526/3.4mb]',
  96. 'bytes_wanted': 123848638,
  97. 'bytes_limit': 123273216,
  98. 'durability': 'TRANSIENT'
  99. },
  100. 'status': 429
  101. }
  102. ----
  103. // NOTCONSOLE
  104. {es} also writes circuit breaker errors to <<logging,`elasticsearch.log`>>. This
  105. is helpful when automated processes, such as allocation, trigger a circuit
  106. breaker.
  107. [source,txt]
  108. ----
  109. Caused by: org.elasticsearch.common.breaker.CircuitBreakingException: [parent] Data too large, data for [<transport_request>] would be [num/numGB], which is larger than the limit of [num/numGB], usages [request=0/0b, fielddata=num/numKB, in_flight_requests=num/numGB, accounting=num/numGB]
  110. ----
  111. **Check JVM memory usage**
  112. If you've enabled Stack Monitoring, you can view JVM memory usage in {kib}. In
  113. the main menu, click **Stack Monitoring**. On the Stack Monitoring **Overview**
  114. page, click **Nodes**. The **JVM Heap** column lists the current memory usage
  115. for each node.
  116. You can also use the <<cat-nodes,cat nodes API>> to get the current
  117. `heap.percent` for each node.
  118. [source,console]
  119. ----
  120. GET _cat/nodes?v=true&h=name,node*,heap*
  121. ----
  122. To get the JVM memory usage for each circuit breaker, use the
  123. <<cluster-nodes-stats,node stats API>>.
  124. [source,console]
  125. ----
  126. GET _nodes/stats/breaker
  127. ----
  128. [discrete]
  129. [[prevent-circuit-breaker-errors]]
  130. ==== Prevent circuit breaker errors
  131. **Reduce JVM memory pressure**
  132. High JVM memory pressure often causes circuit breaker errors. See
  133. <<high-jvm-memory-pressure>>.
  134. **Avoid using fielddata on `text` fields**
  135. For high-cardinality `text` fields, fielddata can use a large amount of JVM
  136. memory. To avoid this, {es} disables fielddata on `text` fields by default. If
  137. you've enabled fielddata and triggered the <<fielddata-circuit-breaker,fielddata
  138. circuit breaker>>, consider disabling it and using a `keyword` field instead.
  139. See <<fielddata>>.
  140. **Clear the fieldata cache**
  141. If you've triggered the fielddata circuit breaker and can't disable fielddata,
  142. use the <<indices-clearcache,clear cache API>> to clear the fielddata cache.
  143. This may disrupt any in-flight searches that use fielddata.
  144. [source,console]
  145. ----
  146. POST _cache/clear?fielddata=true
  147. ----
  148. // TEST[s/^/PUT my-index\n/]
  149. [discrete]
  150. [[high-cpu-usage]]
  151. === High CPU usage
  152. {es} uses <<modules-threadpool,thread pools>> to manage CPU resources for
  153. concurrent operations. High CPU usage typically means one or more thread pools
  154. are running low.
  155. If a thread pool is depleted, {es} will <<rejected-requests,reject requests>>
  156. related to the thread pool. For example, if the `search` thread pool is
  157. depleted, {es} will reject search requests until more threads are available.
  158. [discrete]
  159. [[diagnose-high-cpu-usage]]
  160. ==== Diagnose high CPU usage
  161. **Check CPU usage**
  162. include::{es-repo-dir}/tab-widgets/cpu-usage-widget.asciidoc[]
  163. **Check hot threads**
  164. If a node has high CPU usage, use the <<cluster-nodes-hot-threads,nodes hot
  165. threads API>> to check for resource-intensive threads running on the node.
  166. [source,console]
  167. ----
  168. GET _nodes/my-node,my-other-node/hot_threads
  169. ----
  170. // TEST[s/\/my-node,my-other-node//]
  171. This API returns a breakdown of any hot threads in plain text.
  172. [discrete]
  173. [[reduce-cpu-usage]]
  174. ==== Reduce CPU usage
  175. The following tips outline the most common causes of high CPU usage and their
  176. solutions.
  177. **Scale your cluster**
  178. Heavy indexing and search loads can deplete smaller thread pools. To better
  179. handle heavy workloads, add more nodes to your cluster or upgrade your existing
  180. nodes to increase capacity.
  181. **Spread out bulk requests**
  182. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  183. or <<search-multi-search,multi-search>> requests still require CPU resources. If
  184. possible, submit smaller requests and allow more time between them.
  185. **Cancel long-running searches**
  186. Long-running searches can block threads in the `search` thread pool. To check
  187. for these searches, use the <<tasks,task management API>>.
  188. [source,console]
  189. ----
  190. GET _tasks?actions=*search&detailed
  191. ----
  192. The response's `description` contains the search request and its queries.
  193. `running_time_in_nanos` shows how long the search has been running.
  194. [source,console-result]
  195. ----
  196. {
  197. "nodes" : {
  198. "oTUltX4IQMOUUVeiohTt8A" : {
  199. "name" : "my-node",
  200. "transport_address" : "127.0.0.1:9300",
  201. "host" : "127.0.0.1",
  202. "ip" : "127.0.0.1:9300",
  203. "tasks" : {
  204. "oTUltX4IQMOUUVeiohTt8A:464" : {
  205. "node" : "oTUltX4IQMOUUVeiohTt8A",
  206. "id" : 464,
  207. "type" : "transport",
  208. "action" : "indices:data/read/search",
  209. "description" : "indices[my-index], search_type[QUERY_THEN_FETCH], source[{\"query\":...}]",
  210. "start_time_in_millis" : 4081771730000,
  211. "running_time_in_nanos" : 13991383,
  212. "cancellable" : true
  213. }
  214. }
  215. }
  216. }
  217. }
  218. ----
  219. // TESTRESPONSE[skip: no way to get tasks]
  220. To cancel a search and free up resources, use the API's `_cancel` endpoint.
  221. [source,console]
  222. ----
  223. POST _tasks/oTUltX4IQMOUUVeiohTt8A:464/_cancel
  224. ----
  225. For additional tips on how to track and avoid resource-intensive searches, see
  226. <<avoid-expensive-searches,Avoid expensive searches>>.
  227. [discrete]
  228. [[high-jvm-memory-pressure]]
  229. === High JVM memory pressure
  230. High JVM memory usage can degrade cluster performance and trigger
  231. <<circuit-breaker-errors,circuit breaker errors>>. To prevent this, we recommend
  232. taking steps to reduce memory pressure if a node's JVM memory usage consistently
  233. exceeds 85%.
  234. [discrete]
  235. [[diagnose-high-jvm-memory-pressure]]
  236. ==== Diagnose high JVM memory pressure
  237. **Check JVM memory pressure**
  238. include::{es-repo-dir}/tab-widgets/jvm-memory-pressure-widget.asciidoc[]
  239. **Check garbage collection logs**
  240. As memory usage increases, garbage collection becomes more frequent and takes
  241. longer. You can track the frequency and length of garbage collection events in
  242. <<logging,`elasticsearch.log`>>. For example, the following event states {es}
  243. spent more than 50% (21 seconds) of the last 40 seconds performing garbage
  244. collection.
  245. [source,log]
  246. ----
  247. [timestamp_short_interval_from_last][INFO ][o.e.m.j.JvmGcMonitorService] [node_id] [gc][number] overhead, spent [21s] collecting in the last [40s]
  248. ----
  249. [discrete]
  250. [[reduce-jvm-memory-pressure]]
  251. ==== Reduce JVM memory pressure
  252. **Reduce your shard count**
  253. Every shard uses memory. In most cases, a small set of large shards uses fewer
  254. resources than many small shards. For tips on reducing your shard count, see
  255. <<size-your-shards>>.
  256. [[avoid-expensive-searches]]
  257. **Avoid expensive searches**
  258. Expensive searches can use large amounts of memory. To better track expensive
  259. searches on your cluster, enable <<index-modules-slowlog,slow logs>>.
  260. Expensive searches may have a large <<paginate-search-results,`size` argument>>,
  261. use aggregations with a large number of buckets, or include
  262. <<query-dsl-allow-expensive-queries,expensive queries>>. To prevent expensive
  263. searches, consider the following setting changes:
  264. * Lower the `size` limit using the
  265. <<index-max-result-window,`index.max_result_window`>> index setting.
  266. * Decrease the maximum number of allowed aggregation buckets using the
  267. <<search-settings-max-buckets,search.max_buckets>> cluster setting.
  268. * Disable expensive queries using the
  269. <<query-dsl-allow-expensive-queries,`search.allow_expensive_queries`>> cluster
  270. setting.
  271. [source,console]
  272. ----
  273. PUT _settings
  274. {
  275. "index.max_result_window": 5000
  276. }
  277. PUT _cluster/settings
  278. {
  279. "persistent": {
  280. "search.max_buckets": 20000,
  281. "search.allow_expensive_queries": false
  282. }
  283. }
  284. ----
  285. // TEST[s/^/PUT my-index\n/]
  286. **Prevent mapping explosions**
  287. Defining too many fields or nesting fields too deeply can lead to
  288. <<mapping-limit-settings,mapping explosions>> that use large amounts of memory.
  289. To prevent mapping explosions, use the <<mapping-settings-limit,mapping limit
  290. settings>> to limit the number of field mappings.
  291. **Spread out bulk requests**
  292. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  293. or <<search-multi-search,multi-search>> requests can still create high JVM
  294. memory pressure. If possible, submit smaller requests and allow more time
  295. between them.
  296. **Upgrade node memory**
  297. Heavy indexing and search loads can cause high JVM memory pressure. To better
  298. handle heavy workloads, upgrade your nodes to increase their memory capacity.
  299. [discrete]
  300. [[red-yellow-cluster-status]]
  301. === Red or yellow cluster status
  302. A red or yellow cluster status indicates one or more shards are missing or
  303. unallocated. These unassigned shards increase your risk of data loss and can
  304. degrade cluster performance.
  305. [discrete]
  306. [[diagnose-cluster-status]]
  307. ==== Diagnose your cluster status
  308. **Check your cluster status**
  309. Use the <<cluster-health,cluster health API>>.
  310. [source,console]
  311. ----
  312. GET _cluster/health?filter_path=status,*_shards
  313. ----
  314. A healthy cluster has a green `status` and zero `unassigned_shards`. A yellow
  315. status means only replicas are unassigned. A red status means one or
  316. more primary shards are unassigned.
  317. **View unassigned shards**
  318. To view unassigned shards, use the <<cat-shards,cat shards API>>.
  319. [source,console]
  320. ----
  321. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
  322. ----
  323. Unassigned shards have a `state` of `UNASSIGNED`. The `prirep` value is `p` for
  324. primary shards and `r` for replicas.
  325. To understand why an unassigned shard is not being assigned and what action
  326. you must take to allow {es} to assign it, use the
  327. <<cluster-allocation-explain,cluster allocation explanation API>>.
  328. [source,console]
  329. ----
  330. GET _cluster/allocation/explain?filter_path=index,node_allocation_decisions.node_name,node_allocation_decisions.deciders.*
  331. {
  332. "index": "my-index",
  333. "shard": 0,
  334. "primary": false,
  335. "current_node": "my-node"
  336. }
  337. ----
  338. // TEST[s/^/PUT my-index\n/]
  339. // TEST[s/"primary": false,/"primary": false/]
  340. // TEST[s/"current_node": "my-node"//]
  341. [discrete]
  342. [[fix-red-yellow-cluster-status]]
  343. ==== Fix a red or yellow cluster status
  344. A shard can become unassigned for several reasons. The following tips outline the
  345. most common causes and their solutions.
  346. **Re-enable shard allocation**
  347. You typically disable allocation during a <<restart-cluster,restart>> or other
  348. cluster maintenance. If you forgot to re-enable allocation afterward, {es} will
  349. be unable to assign shards. To re-enable allocation, reset the
  350. `cluster.routing.allocation.enable` cluster setting.
  351. [source,console]
  352. ----
  353. PUT _cluster/settings
  354. {
  355. "persistent" : {
  356. "cluster.routing.allocation.enable" : null
  357. }
  358. }
  359. ----
  360. **Recover lost nodes**
  361. Shards often become unassigned when a data node leaves the cluster. This can
  362. occur for several reasons, ranging from connectivity issues to hardware failure.
  363. After you resolve the issue and recover the node, it will rejoin the cluster.
  364. {es} will then automatically allocate any unassigned shards.
  365. To avoid wasting resources on temporary issues, {es} <<delayed-allocation,delays
  366. allocation>> by one minute by default. If you've recovered a node and don’t want
  367. to wait for the delay period, you can call the <<cluster-reroute,cluster reroute
  368. API>> with no arguments to start the allocation process. The process runs
  369. asynchronously in the background.
  370. [source,console]
  371. ----
  372. POST _cluster/reroute
  373. ----
  374. **Fix allocation settings**
  375. Misconfigured allocation settings can result in an unassigned primary shard.
  376. These settings include:
  377. * <<shard-allocation-filtering,Shard allocation>> index settings
  378. * <<cluster-shard-allocation-filtering,Allocation filtering>> cluster settings
  379. * <<shard-allocation-awareness,Allocation awareness>> cluster settings
  380. To review your allocation settings, use the <<indices-get-settings,get index
  381. settings>> and <<cluster-get-settings,cluster get settings>> APIs.
  382. [source,console]
  383. ----
  384. GET my-index/_settings?flat_settings=true&include_defaults=true
  385. GET _cluster/settings?flat_settings=true&include_defaults=true
  386. ----
  387. // TEST[s/^/PUT my-index\n/]
  388. You can change the settings using the <<indices-update-settings,update index
  389. settings>> and <<cluster-update-settings,cluster update settings>> APIs.
  390. **Allocate or reduce replicas**
  391. To protect against hardware failure, {es} will not assign a replica to the same
  392. node as its primary shard. If no other data nodes are available to host the
  393. replica, it remains unassigned. To fix this, you can:
  394. * Add a data node to the same tier to host the replica.
  395. * Change the `index.number_of_replicas` index setting to reduce the number of
  396. replicas for each primary shard. We recommend keeping at least one replica per
  397. primary.
  398. [source,console]
  399. ----
  400. PUT _settings
  401. {
  402. "index.number_of_replicas": 1
  403. }
  404. ----
  405. // TEST[s/^/PUT my-index\n/]
  406. **Free up or increase disk space**
  407. {es} uses a <<disk-based-shard-allocation,low disk watermark>> to ensure data
  408. nodes have enough disk space for incoming shards. By default, {es} does not
  409. allocate shards to nodes using more than 85% of disk space.
  410. To check the current disk space of your nodes, use the <<cat-allocation,cat
  411. allocation API>>.
  412. [source,console]
  413. ----
  414. GET _cat/allocation?v=true&h=node,shards,disk.*
  415. ----
  416. If your nodes are running low on disk space, you have a few options:
  417. * Upgrade your nodes to increase disk space.
  418. * Delete unneeded indices to free up space. If you use {ilm-init}, you can
  419. update your lifecycle policy to use <<ilm-searchable-snapshot,searchable
  420. snapshots>> or add a delete phase. If you no longer need to search the data, you
  421. can use a <<snapshot-restore,snapshot>> to store it off-cluster.
  422. * If you no longer write to an index, use the <<indices-forcemerge,force merge
  423. API>> or {ilm-init}'s <<ilm-forcemerge,force merge action>> to merge its
  424. segments into larger ones.
  425. +
  426. [source,console]
  427. ----
  428. POST my-index/_forcemerge
  429. ----
  430. // TEST[s/^/PUT my-index\n/]
  431. * If an index is read-only, use the <<indices-shrink-index,shrink index API>> or
  432. {ilm-init}'s <<ilm-shrink,shrink action>> to reduce its primary shard count.
  433. +
  434. [source,console]
  435. ----
  436. POST my-index/_shrink/my-shrunken-index
  437. ----
  438. // TEST[s/^/PUT my-index\n{"settings":{"index.number_of_shards":2,"blocks.write":true}}\n/]
  439. * If your node has a large disk capacity, you can increase the low disk
  440. watermark or set it to an explicit byte value.
  441. +
  442. [source,console]
  443. ----
  444. PUT _cluster/settings
  445. {
  446. "persistent": {
  447. "cluster.routing.allocation.disk.watermark.low": "30gb"
  448. }
  449. }
  450. ----
  451. // TEST[s/"30gb"/null/]
  452. **Reduce JVM memory pressure**
  453. Shard allocation requires JVM heap memory. High JVM memory pressure can trigger
  454. <<circuit-breaker,circuit breakers>> that stop allocation and leave shards
  455. unassigned. See <<high-jvm-memory-pressure>>.
  456. **Recover data for a lost primary shard**
  457. If a node containing a primary shard is lost, {es} can typically replace it
  458. using a replica on another node. If you can't recover the node and replicas
  459. don't exist or are irrecoverable, you'll need to re-add the missing data from a
  460. <<snapshot-restore,snapshot>> or the original data source.
  461. WARNING: Only use this option if node recovery is no longer possible. This
  462. process allocates an empty primary shard. If the node later rejoins the cluster,
  463. {es} will overwrite its primary shard with data from this newer empty shard,
  464. resulting in data loss.
  465. Use the <<cluster-reroute,cluster reroute API>> to manually allocate the
  466. unassigned primary shard to another data node in the same tier. Set
  467. `accept_data_loss` to `true`.
  468. [source,console]
  469. ----
  470. POST _cluster/reroute
  471. {
  472. "commands": [
  473. {
  474. "allocate_empty_primary": {
  475. "index": "my-index",
  476. "shard": 0,
  477. "node": "my-node",
  478. "accept_data_loss": "true"
  479. }
  480. }
  481. ]
  482. }
  483. ----
  484. // TEST[s/^/PUT my-index\n/]
  485. // TEST[catch:bad_request]
  486. If you backed up the missing index data to a snapshot, use the
  487. <<restore-snapshot-api,restore snapshot API>> to restore the individual index.
  488. Alternatively, you can index the missing data from the original data source.
  489. [discrete]
  490. [[rejected-requests]]
  491. === Rejected requests
  492. When {es} rejects a request, it stops the operation and returns an error with a
  493. `429` response code. Rejected requests are commonly caused by:
  494. * A <<high-cpu-usage,depleted thread pool>>. A depleted `search` or `write`
  495. thread pool returns a `TOO_MANY_REQUESTS` error message.
  496. * A <<circuit-breaker-errors,circuit breaker error>>.
  497. * High <<index-modules-indexing-pressure,indexing pressure>> that exceeds the
  498. <<memory-limits,`indexing_pressure.memory.limit`>>.
  499. [discrete]
  500. [[check-rejected-tasks]]
  501. ==== Check rejected tasks
  502. To check the number of rejected tasks for each thread pool, use the
  503. <<cat-thread-pool,cat thread pool API>>. A high ratio of `rejected` to
  504. `completed` tasks, particularly in the `search` and `write` thread pools, means
  505. {es} regularly rejects requests.
  506. [source,console]
  507. ----
  508. GET /_cat/thread_pool?v=true&h=id,name,active,rejected,completed
  509. ----
  510. [discrete]
  511. [[prevent-rejected-requests]]
  512. ==== Prevent rejected requests
  513. **Fix high CPU and memory usage**
  514. If {es} regularly rejects requests and other tasks, your cluster likely has high
  515. CPU usage or high JVM memory pressure. For tips, see <<high-cpu-usage>> and
  516. <<high-jvm-memory-pressure>>.
  517. **Prevent circuit breaker errors**
  518. If you regularly trigger circuit breaker errors, see <<circuit-breaker-errors>>
  519. for tips on diagnosing and preventing them.
  520. [discrete]
  521. [[task-queue-backlog]]
  522. === Task queue backlog
  523. A backlogged task queue can prevent tasks from completing and
  524. put the cluster into an unhealthy state.
  525. Resource constraints, a large number of tasks being triggered at once,
  526. and long running tasks can all contribute to a backlogged task queue.
  527. [discrete]
  528. [[diagnose-task-queue-backlog]]
  529. ==== Diagnose a task queue backlog
  530. **Check the thread pool status**
  531. A <<high-cpu-usage,depleted thread pool>> can result in <<rejected-requests,rejected requests>>.
  532. You can use the <<cat-thread-pool,cat thread pool API>> to
  533. see the number of active threads in each thread pool and
  534. how many tasks are queued, how many have been rejected, and how many have completed.
  535. [source,console]
  536. ---
  537. GET /_cat/thread_pool?v&s=t,n&h=type,name,node_name,active,queue,rejected,completed
  538. ---
  539. **Inspect the hot threads on each node**
  540. If a particular thread pool queue is backed up,
  541. you can periodically poll the <<cluster-nodes-hot-threads,Nodes hot threads>> API
  542. to determine if the thread has sufficient
  543. resources to progress and gauge how quickly it is progressing.
  544. [source,console]
  545. ---
  546. GET /_nodes/hot_threads
  547. ---
  548. **Look for long running tasks**
  549. Long-running tasks can also cause a backlog.
  550. You can use the <<tasks,task management>> API to get information about the tasks that are running.
  551. Check the `running_time_in_nanos` to identify tasks that are taking an excessive amount of time to complete.
  552. [source,console]
  553. ----
  554. GET /_tasks?filter_path=nodes.*.tasks
  555. ----
  556. [discrete]
  557. [[resolve-task-queue-backlog]]
  558. ==== Resolve a task queue backlog
  559. **Increase available resources**
  560. If tasks are progressing slowly and the queue is backing up,
  561. you might need to take steps to <<reduce-cpu-usage>>.
  562. In some cases, increasing the thread pool size might help.
  563. For example, the `force_merge` thread pool defaults to a single thread.
  564. Increasing the size to 2 might help reduce a backlog of force merge requests.
  565. **Cancel stuck tasks**
  566. If you find the active task's hot thread isn't progressing and there's a backlog,
  567. consider canceling the task.