Browse Source

Added type, max, min, queueSize & keepAlive to _cat/thread_pool

Closes #5366
Chris Earle 11 years ago
parent
commit
5528370e24

+ 68 - 1
docs/reference/cat/thread_pool.asciidoc

@@ -41,4 +41,71 @@ host2                  0                0                 0
 --------------------------------------------------
 
 Here the host columns and the active, rejected and completed suggest thread pool statistic are displayed. The suggest
-thread pool won't be displayed by default, so you always need be specific about what statistic you want to display.
+thread pool won't be displayed by default, so you always need to be specific about what statistic you want to display.
+
+[float]
+=== Available Thread Pools
+
+Currently available <<modules-threadpool,thread pools>>:
+
+[cols="<,<,<",options="header"]
+|=======================================================================
+|Thread Pool |Alias |Description
+|`bulk` |`b` |Thread pool used for <<docs-bulk,bulk>> operations
+|`flush` |`f` |Thread pool used for <<indices-flush,flush>> operations
+|`generic` |`ge` |Thread pool used for generic operations (e.g. background node discovery)
+|`get` |`g` |Thread pool used for <<docs-get,get>> operations
+|`index` |`i` |Thread pool used for <<docs-index_,index>>/<<docs-delete,delete>> operations
+|`management` |`ma` |Thread pool used for management of Elasticsearch (e.g. cluster management)
+|`merge` |`m` |Thread pool used for <<index-modules-merge,merge>> operations
+|`optimize` |`o` |Thread pool used for <<indices-optimize,optimize>> operations
+|`percolate` |`p` |Thread pool used for <<search-percolate,percolator>> operations
+|`refresh` |`r` |Thread pool used for <<indices-refresh,refresh>> operations
+|`search` |`s` |Thread pool used for <<search-search,search>>/<<search-count,count>> operations
+|`snapshot` |`sn` |Thread pool used for <<modules-snapshots,snapshot>> operations
+|`suggest` |`su` |Thread pool used for <<search-suggesters,suggester>> operations
+|`warmer` |`w` |Thread pool used for <<indices-warmers,index warm-up>> operations
+|=======================================================================
+
+The thread pool name (or alias) must be combined with a thread pool field below
+to retrieve the requested information.
+
+[float]
+==== Thread Pool Fields
+
+For each thread pool, you can load details about it by using the field names
+in the table below, either using the full field name (e.g. `bulk.active`) or
+its alias (e.g. `sa` is equivalent to `search.active`).
+
+[cols="<,<,<",options="header"]
+|=======================================================================
+|Field Name |Alias |Description
+|`type` |`t` |The current (*) type of thread pool (`cached`, `fixed` or `scaling`)
+|`active` |`a` |The number of active threads in the current thread pool
+|`size` |`s` |The number of threads in the current thread pool
+|`queue` |`q` |The number of tasks in the queue for the current thread pool
+|`queueSize` |`qs` |The maximum number of tasks in the queue for the current thread pool
+|`rejected` |`r` |The number of rejected threads in the current thread pool
+|`largest` |`l` |The highest number of active threads in the current thread pool
+|`completed` |`c` |The number of completed threads in the current thread pool
+|`min` |`mi` |The configured minimum number of active threads allowed in the current thread pool
+|`max` |`ma` |The configured maximum number of active threads allowed in the current thread pool
+|`keepAlive` |`k` |The configured keep alive time for threads
+|=======================================================================
+
+[float]
+=== Other Fields
+
+In addition to details about each thread pool, it is also convenient to get an
+understanding of where those thread pools reside.  As such, you can request
+other details like the `ip` of the responding node(s).
+
+[cols="<,<,<",options="header"]
+|=======================================================================
+|Field Name |Alias |Description
+|`id` |`nodeId` |The unique node ID
+|`pid` |`p` |The process ID of the running node
+|`host` |`h` |The hostname for the current node
+|`ip` |`i` |The IP address for the current node
+|`port` |`po` |The bound transport port for the current node
+|=======================================================================

+ 139 - 0
rest-api-spec/test/cat.thread_pool/10_basic.yaml

@@ -38,3 +38,142 @@
                /^  id   \s+  ba   \s+  fa   \s+  gea  \s+  ga   \s+  ia   \s+  maa  \s+  ma   \s+  oa   \s+  pa  \s+  \n
                   (\S+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+  \s+  \d+ \s+  \n)+  $/
 
+  - do:
+      cat.thread_pool:
+          h: id,bulk.type,bulk.active,bulk.size,bulk.queue,bulk.queueSize,bulk.rejected,bulk.largest,bulk.completed,bulk.min,bulk.max,bulk.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  bulk.type                \s+  bulk.active  \s+  bulk.size  \s+  bulk.queue  \s+  bulk.queueSize  \s+  bulk.rejected  \s+  bulk.largest  \s+  bulk.completed  \s+  bulk.min  \s+  bulk.max  \s+  bulk.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+          \d+  \s+        \d+  \s+         \d+  \s+             \d*  \s+            \d+  \s+           \d+  \s+             \d+  \s+       \d*  \s+       \d*  \s+             \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,flush.type,flush.active,flush.size,flush.queue,flush.queueSize,flush.rejected,flush.largest,flush.completed,flush.min,flush.max,flush.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  flush.type               \s+  flush.active  \s+  flush.size  \s+  flush.queue  \s+  flush.queueSize  \s+  flush.rejected  \s+  flush.largest  \s+  flush.completed  \s+  flush.min  \s+  flush.max  \s+  flush.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+           \d+  \s+         \d+  \s+          \d+  \s+              \d*  \s+             \d+  \s+            \d+  \s+              \d+  \s+        \d*  \s+        \d*  \s+              \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,generic.type,generic.active,generic.size,generic.queue,generic.queueSize,generic.rejected,generic.largest,generic.completed,generic.min,generic.max,generic.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  generic.type             \s+  generic.active  \s+  generic.size  \s+  generic.queue  \s+  generic.queueSize  \s+  generic.rejected  \s+  generic.largest  \s+  generic.completed  \s+  generic.min  \s+  generic.max  \s+  generic.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+             \d+  \s+           \d+  \s+            \d+  \s+                \d*  \s+               \d+  \s+              \d+  \s+                \d+  \s+          \d*  \s+          \d*  \s+                \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,get.type,get.active,get.size,get.queue,get.queueSize,get.rejected,get.largest,get.completed,get.min,get.max,get.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  get.type                 \s+  get.active  \s+  get.size  \s+  get.queue  \s+  get.queueSize  \s+  get.rejected  \s+  get.largest  \s+  get.completed  \s+  get.min  \s+  get.max  \s+  get.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+         \d+  \s+       \d+  \s+        \d+  \s+            \d*  \s+           \d+  \s+          \d+  \s+            \d+  \s+      \d*  \s+      \d*  \s+            \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,index.type,index.active,index.size,index.queue,index.queueSize,index.rejected,index.largest,index.completed,index.min,index.max,index.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  index.type               \s+  index.active  \s+  index.size  \s+  index.queue  \s+  index.queueSize  \s+  index.rejected  \s+  index.largest  \s+  index.completed  \s+  index.min  \s+  index.max  \s+  index.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+           \d+  \s+         \d+  \s+          \d+  \s+              \d*  \s+             \d+  \s+            \d+  \s+              \d+  \s+        \d*  \s+        \d*  \s+              \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,management.type,management.active,management.size,management.queue,management.queueSize,management.rejected,management.largest,management.completed,management.min,management.max,management.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  management.type          \s+  management.active  \s+  management.size  \s+  management.queue  \s+  management.queueSize  \s+  management.rejected  \s+  management.largest  \s+  management.completed  \s+  management.min  \s+  management.max  \s+  management.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+                \d+  \s+              \d+  \s+               \d+  \s+                   \d*  \s+                  \d+  \s+                 \d+  \s+                   \d+  \s+             \d*  \s+             \d*  \s+                   \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,merge.type,merge.active,merge.size,merge.queue,merge.queueSize,merge.rejected,merge.largest,merge.completed,merge.min,merge.max,merge.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  merge.type               \s+  merge.active  \s+  merge.size  \s+  merge.queue  \s+  merge.queueSize  \s+  merge.rejected  \s+  merge.largest  \s+  merge.completed  \s+  merge.min  \s+  merge.max  \s+  merge.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+           \d+  \s+         \d+  \s+          \d+  \s+              \d*  \s+             \d+  \s+            \d+  \s+              \d+  \s+        \d*  \s+        \d*  \s+              \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,optimize.type,optimize.active,optimize.size,optimize.queue,optimize.queueSize,optimize.rejected,optimize.largest,optimize.completed,optimize.min,optimize.max,optimize.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  optimize.type            \s+  optimize.active  \s+  optimize.size  \s+  optimize.queue  \s+  optimize.queueSize  \s+  optimize.rejected  \s+  optimize.largest  \s+  optimize.completed  \s+  optimize.min  \s+  optimize.max  \s+  optimize.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+              \d+  \s+            \d+  \s+             \d+  \s+                 \d*  \s+                \d+  \s+               \d+  \s+                 \d+  \s+           \d*  \s+           \d*  \s+                 \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,percolate.type,percolate.active,percolate.size,percolate.queue,percolate.queueSize,percolate.rejected,percolate.largest,percolate.completed,percolate.min,percolate.max,percolate.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  percolate.type           \s+  percolate.active  \s+  percolate.size  \s+  percolate.queue  \s+  percolate.queueSize  \s+  percolate.rejected  \s+  percolate.largest  \s+  percolate.completed  \s+  percolate.min  \s+  percolate.max  \s+  percolate.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+               \d+  \s+             \d+  \s+              \d+  \s+                  \d*  \s+                 \d+  \s+                \d+  \s+                  \d+  \s+            \d*  \s+            \d*  \s+                  \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,refresh.type,refresh.active,refresh.size,refresh.queue,refresh.queueSize,refresh.rejected,refresh.largest,refresh.completed,refresh.min,refresh.max,refresh.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  refresh.type             \s+  refresh.active  \s+  refresh.size  \s+  refresh.queue  \s+  refresh.queueSize  \s+  refresh.rejected  \s+  refresh.largest  \s+  refresh.completed  \s+  refresh.min  \s+  refresh.max  \s+  refresh.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+             \d+  \s+           \d+  \s+            \d+  \s+                \d*  \s+               \d+  \s+              \d+  \s+                \d+  \s+          \d*  \s+          \d*  \s+                \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,search.type,search.active,search.size,search.queue,search.queueSize,search.rejected,search.largest,search.completed,search.min,search.max,search.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  search.type              \s+  search.active  \s+  search.size  \s+  search.queue  \s+  search.queueSize  \s+  search.rejected  \s+  search.largest  \s+  search.completed  \s+  search.min  \s+  search.max  \s+  search.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+            \d+  \s+          \d+  \s+           \d+  \s+               \d*  \s+              \d+  \s+             \d+  \s+               \d+  \s+         \d*  \s+         \d*  \s+               \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,snapshot.type,snapshot.active,snapshot.size,snapshot.queue,snapshot.queueSize,snapshot.rejected,snapshot.largest,snapshot.completed,snapshot.min,snapshot.max,snapshot.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  snapshot.type            \s+  snapshot.active  \s+  snapshot.size  \s+  snapshot.queue  \s+  snapshot.queueSize  \s+  snapshot.rejected  \s+  snapshot.largest  \s+  snapshot.completed  \s+  snapshot.min  \s+  snapshot.max  \s+  snapshot.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+              \d+  \s+            \d+  \s+             \d+  \s+                 \d*  \s+                \d+  \s+               \d+  \s+                 \d+  \s+           \d*  \s+           \d*  \s+                 \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,suggest.type,suggest.active,suggest.size,suggest.queue,suggest.queueSize,suggest.rejected,suggest.largest,suggest.completed,suggest.min,suggest.max,suggest.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  suggest.type             \s+  suggest.active  \s+  suggest.size  \s+  suggest.queue  \s+  suggest.queueSize  \s+  suggest.rejected  \s+  suggest.largest  \s+  suggest.completed  \s+  suggest.min  \s+  suggest.max  \s+  suggest.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+             \d+  \s+           \d+  \s+            \d+  \s+                \d*  \s+               \d+  \s+              \d+  \s+                \d+  \s+          \d*  \s+          \d*  \s+                \S*  \s+  \n)+  $/
+
+  - do:
+      cat.thread_pool:
+          h: id,warmer.type,warmer.active,warmer.size,warmer.queue,warmer.queueSize,warmer.rejected,warmer.largest,warmer.completed,warmer.min,warmer.max,warmer.keepAlive
+          v: true
+
+  - match:
+      $body: >
+               /^  id  \s+  warmer.type              \s+  warmer.active  \s+  warmer.size  \s+  warmer.queue  \s+  warmer.queueSize  \s+  warmer.rejected  \s+  warmer.largest  \s+  warmer.completed  \s+  warmer.min  \s+  warmer.max  \s+  warmer.keepAlive  \s+  \n
+                  (\S+ \s+  (cached|fixed|scaling)?  \s+            \d+  \s+          \d+  \s+           \d+  \s+               \d*  \s+              \d+  \s+             \d+  \s+               \d+  \s+         \d*  \s+         \d*  \s+               \S*  \s+  \n)+  $/

+ 62 - 6
src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java

@@ -123,13 +123,12 @@ public class RestThreadPoolAction extends AbstractCatAction {
         clusterStateRequest.clear().nodes(true);
         clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
         clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
-        final String[] pools = fetchSortedPools(request, DEFAULT_THREAD_POOLS);
 
         client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
             @Override
             public void processResponse(final ClusterStateResponse clusterStateResponse) {
                 NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
-                nodesInfoRequest.clear().process(true);
+                nodesInfoRequest.clear().process(true).threadPool(true);
                 client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                     @Override
                     public void processResponse(final NodesInfoResponse nodesInfoResponse) {
@@ -138,7 +137,7 @@ public class RestThreadPoolAction extends AbstractCatAction {
                         client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                             @Override
                             public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
-                                return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse, pools), channel);
+                                return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                             }
                         });
                     }
@@ -151,7 +150,7 @@ public class RestThreadPoolAction extends AbstractCatAction {
     Table getTableWithHeader(final RestRequest request) {
         Table table = new Table();
         table.startHeaders();
-        table.addCell("id", "default:false;alias:id,nodeId;desc:unique node id");
+        table.addCell("id", "default:false;alias:nodeId;desc:unique node id");
         table.addCell("pid", "default:false;alias:p;desc:process id");
         table.addCell("host", "alias:h;desc:host name");
         table.addCell("ip", "alias:i;desc:ip address");
@@ -169,18 +168,26 @@ public class RestThreadPoolAction extends AbstractCatAction {
             }
 
             String defaultDisplayVal = Boolean.toString(display);
+            table.addCell(
+                    pool + ".type",
+                    "alias:" + poolAlias + "t;default:false;desc:" + pool + " thread pool type"
+            );
             table.addCell(
                     pool + ".active",
                     "alias:" + poolAlias + "a;default:" + defaultDisplayVal + ";text-align:right;desc:number of active " + pool + " threads"
             );
             table.addCell(
                     pool + ".size",
-                    "alias:" + poolAlias + "s;default:false;text-align:right;desc:number of active " + pool + " threads"
+                    "alias:" + poolAlias + "s;default:false;text-align:right;desc:number of " + pool + " threads"
             );
             table.addCell(
                     pool + ".queue",
                     "alias:" + poolAlias + "q;default:" + defaultDisplayVal + ";text-align:right;desc:number of " + pool + " threads in queue"
             );
+            table.addCell(
+                    pool + ".queueSize",
+                    "alias:" + poolAlias + "qs;default:false;text-align:right;desc:maximum number of " + pool + " threads in queue"
+            );
             table.addCell(
                     pool + ".rejected",
                     "alias:" + poolAlias + "r;default:" + defaultDisplayVal + ";text-align:right;desc:number of rejected " + pool + " threads"
@@ -193,6 +200,18 @@ public class RestThreadPoolAction extends AbstractCatAction {
                     pool + ".completed",
                     "alias:" + poolAlias + "c;default:false;text-align:right;desc:number of completed " + pool + " threads"
             );
+            table.addCell(
+                    pool + ".min",
+                    "alias:" + poolAlias + "mi;default:false;text-align:right;desc:minimum number of " + pool + " threads"
+            );
+            table.addCell(
+                    pool + ".max",
+                    "alias:" + poolAlias + "ma;default:false;text-align:right;desc:maximum number of " + pool + " threads"
+            );
+            table.addCell(
+                    pool + ".keepAlive",
+                    "alias:" + poolAlias + "k;default:false;text-align:right;desc:" + pool + " thread keep alive time"
+            );
         }
 
         table.endHeaders();
@@ -200,7 +219,7 @@ public class RestThreadPoolAction extends AbstractCatAction {
     }
 
 
-    private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats, String[] pools) {
+    private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
         boolean fullId = req.paramAsBoolean("full_id", false);
         DiscoveryNodes nodes = state.getState().nodes();
         Table table = getTableWithHeader(req);
@@ -221,23 +240,60 @@ public class RestThreadPoolAction extends AbstractCatAction {
             }
 
             final Map<String, ThreadPoolStats.Stats> poolThreadStats;
+            final Map<String, ThreadPool.Info> poolThreadInfo;
+
             if (stats == null) {
                 poolThreadStats = Collections.emptyMap();
+                poolThreadInfo = Collections.emptyMap();
             } else {
                 poolThreadStats = new HashMap<>(14);
+                poolThreadInfo = new HashMap<>(14);
+
                 ThreadPoolStats threadPoolStats = stats.getThreadPool();
                 for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) {
                     poolThreadStats.put(threadPoolStat.getName(), threadPoolStat);
                 }
+                if (info != null) {
+                    for (ThreadPool.Info threadPoolInfo : info.getThreadPool()) {
+                        poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
+                    }
+                }
             }
             for (String pool : SUPPORTED_NAMES) {
                 ThreadPoolStats.Stats poolStats = poolThreadStats.get(pool);
+                ThreadPool.Info poolInfo = poolThreadInfo.get(pool);
+
+                Long maxQueueSize = null;
+                String keepAlive = null;
+                Integer minThreads = null;
+                Integer maxThreads = null;
+
+                if (poolInfo != null) {
+                    if (poolInfo.getQueueSize() != null) {
+                        maxQueueSize = poolInfo.getQueueSize().singles();
+                    }
+                    if (poolInfo.getKeepAlive() != null) {
+                        keepAlive = poolInfo.getKeepAlive().toString();
+                    }
+                    if (poolInfo.getMin() >= 0) {
+                        minThreads = poolInfo.getMin();
+                    }
+                    if (poolInfo.getMax() >= 0) {
+                        maxThreads = poolInfo.getMax();
+                    }
+                }
+
+                table.addCell(poolInfo == null  ? null : poolInfo.getType());
                 table.addCell(poolStats == null ? null : poolStats.getActive());
                 table.addCell(poolStats == null ? null : poolStats.getThreads());
                 table.addCell(poolStats == null ? null : poolStats.getQueue());
+                table.addCell(maxQueueSize);
                 table.addCell(poolStats == null ? null : poolStats.getRejected());
                 table.addCell(poolStats == null ? null : poolStats.getLargest());
                 table.addCell(poolStats == null ? null : poolStats.getCompleted());
+                table.addCell(minThreads);
+                table.addCell(maxThreads);
+                table.addCell(keepAlive);
             }
 
             table.endRow();