high-cpu-usage.asciidoc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. [[high-cpu-usage]]
  2. === High CPU usage
  3. {es} uses <<modules-threadpool,thread pools>> to manage CPU resources for
  4. concurrent operations. High CPU usage typically means one or more thread pools
  5. are running low.
  6. If a thread pool is depleted, {es} will <<rejected-requests,reject requests>>
  7. related to the thread pool. For example, if the `search` thread pool is
  8. depleted, {es} will reject search requests until more threads are available.
  9. You might experience high CPU usage if a <<data-tiers,data tier>>, and therefore the nodes assigned to that tier, is experiencing more traffic than other tiers. This imbalance in resource utilization is also known as <<hotspotting,hot spotting>>.
  10. [discrete]
  11. [[diagnose-high-cpu-usage]]
  12. ==== Diagnose high CPU usage
  13. **Check CPU usage**
  14. You can check the CPU usage per node using the <<cat-nodes,cat nodes API>>:
  15. // tag::cpu-usage-cat-nodes[]
  16. [source,console]
  17. ----
  18. GET _cat/nodes?v=true&s=cpu:desc
  19. ----
  20. The response's `cpu` column contains the current CPU usage as a percentage.
  21. The `name` column contains the node's name. Elevated but transient CPU usage is
  22. normal. However, if CPU usage is elevated for an extended duration, it should be
  23. investigated.
  24. To track CPU usage over time, we recommend enabling monitoring:
  25. include::{es-ref-dir}/tab-widgets/cpu-usage-widget.asciidoc[]
  26. **Check hot threads**
  27. If a node has high CPU usage, use the <<cluster-nodes-hot-threads,nodes hot
  28. threads API>> to check for resource-intensive threads running on the node.
  29. [source,console]
  30. ----
  31. GET _nodes/hot_threads
  32. ----
  33. // TEST[s/\/my-node,my-other-node//]
  34. This API returns a breakdown of any hot threads in plain text. High CPU usage
  35. frequently correlates to <<task-queue-backlog,a long-running task, or a
  36. backlog of tasks>>.
  37. [discrete]
  38. [[reduce-cpu-usage]]
  39. ==== Reduce CPU usage
  40. The following tips outline the most common causes of high CPU usage and their
  41. solutions.
  42. **Scale your cluster**
  43. Heavy indexing and search loads can deplete smaller thread pools. To better
  44. handle heavy workloads, add more nodes to your cluster or upgrade your existing
  45. nodes to increase capacity.
  46. **Spread out bulk requests**
  47. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  48. or <<search-multi-search,multi-search>> requests still require CPU resources. If
  49. possible, submit smaller requests and allow more time between them.
  50. **Cancel long-running searches**
  51. Long-running searches can block threads in the `search` thread pool. To check
  52. for these searches, use the <<tasks,task management API>>.
  53. [source,console]
  54. ----
  55. GET _tasks?actions=*search&detailed
  56. ----
  57. The response's `description` contains the search request and its queries.
  58. `running_time_in_nanos` shows how long the search has been running.
  59. [source,console-result]
  60. ----
  61. {
  62. "nodes" : {
  63. "oTUltX4IQMOUUVeiohTt8A" : {
  64. "name" : "my-node",
  65. "transport_address" : "127.0.0.1:9300",
  66. "host" : "127.0.0.1",
  67. "ip" : "127.0.0.1:9300",
  68. "tasks" : {
  69. "oTUltX4IQMOUUVeiohTt8A:464" : {
  70. "node" : "oTUltX4IQMOUUVeiohTt8A",
  71. "id" : 464,
  72. "type" : "transport",
  73. "action" : "indices:data/read/search",
  74. "description" : "indices[my-index], search_type[QUERY_THEN_FETCH], source[{\"query\":...}]",
  75. "start_time_in_millis" : 4081771730000,
  76. "running_time_in_nanos" : 13991383,
  77. "cancellable" : true
  78. }
  79. }
  80. }
  81. }
  82. }
  83. ----
  84. // TESTRESPONSE[skip: no way to get tasks]
  85. To cancel a search and free up resources, use the API's `_cancel` endpoint.
  86. [source,console]
  87. ----
  88. POST _tasks/oTUltX4IQMOUUVeiohTt8A:464/_cancel
  89. ----
  90. For additional tips on how to track and avoid resource-intensive searches, see
  91. <<avoid-expensive-searches,Avoid expensive searches>>.