Search in sources :

Example 1 with NodesHotThreadsResponse

use of org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse in project elasticsearch by elastic.

the class HotThreadsIT method testTimestampAndParams.

public void testTimestampAndParams() throws ExecutionException, InterruptedException {
    NodesHotThreadsResponse response = client().admin().cluster().prepareNodesHotThreads().execute().get();
    if (Constants.FREE_BSD) {
        for (NodeHotThreads node : response.getNodesMap().values()) {
            String result = node.getHotThreads();
            assertTrue(result.indexOf("hot_threads is not supported") != -1);
        }
    } else {
        for (NodeHotThreads node : response.getNodesMap().values()) {
            String result = node.getHotThreads();
            assertTrue(result.indexOf("Hot threads at") != -1);
            assertTrue(result.indexOf("interval=500ms") != -1);
            assertTrue(result.indexOf("busiestThreads=3") != -1);
            assertTrue(result.indexOf("ignoreIdleThreads=true") != -1);
        }
    }
}
Also used : NodeHotThreads(org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads) NodesHotThreadsResponse(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse)

Example 2 with NodesHotThreadsResponse

use of org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse in project elasticsearch by elastic.

the class RestNodesHotThreadsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    NodesHotThreadsRequest nodesHotThreadsRequest = new NodesHotThreadsRequest(nodesIds);
    nodesHotThreadsRequest.threads(request.paramAsInt("threads", nodesHotThreadsRequest.threads()));
    nodesHotThreadsRequest.ignoreIdleThreads(request.paramAsBoolean("ignore_idle_threads", nodesHotThreadsRequest.ignoreIdleThreads()));
    nodesHotThreadsRequest.type(request.param("type", nodesHotThreadsRequest.type()));
    nodesHotThreadsRequest.interval(TimeValue.parseTimeValue(request.param("interval"), nodesHotThreadsRequest.interval(), "interval"));
    nodesHotThreadsRequest.snapshots(request.paramAsInt("snapshots", nodesHotThreadsRequest.snapshots()));
    nodesHotThreadsRequest.timeout(request.param("timeout"));
    return channel -> client.admin().cluster().nodesHotThreads(nodesHotThreadsRequest, new RestResponseListener<NodesHotThreadsResponse>(channel) {

        @Override
        public RestResponse buildResponse(NodesHotThreadsResponse response) throws Exception {
            StringBuilder sb = new StringBuilder();
            for (NodeHotThreads node : response.getNodes()) {
                sb.append("::: ").append(node.getNode().toString()).append("\n");
                Strings.spaceify(3, node.getHotThreads(), sb);
                sb.append('\n');
            }
            return new BytesRestResponse(RestStatus.OK, sb.toString());
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RestResponse(org.elasticsearch.rest.RestResponse) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) NodesHotThreadsResponse(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) NodeHotThreads(org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesHotThreadsRequest(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesHotThreadsRequest(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) NodeHotThreads(org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads) NodesHotThreadsResponse(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse) IOException(java.io.IOException)

Example 3 with NodesHotThreadsResponse

use of org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse in project elasticsearch by elastic.

the class HotThreadsIT method testHotThreadsDontFail.

public void testHotThreadsDontFail() throws ExecutionException, InterruptedException {
    /**
         * This test just checks if nothing crashes or gets stuck etc.
         */
    createIndex("test");
    final int iters = scaledRandomIntBetween(2, 20);
    final AtomicBoolean hasErrors = new AtomicBoolean(false);
    for (int i = 0; i < iters; i++) {
        final String type;
        NodesHotThreadsRequestBuilder nodesHotThreadsRequestBuilder = client().admin().cluster().prepareNodesHotThreads();
        if (randomBoolean()) {
            TimeValue timeValue = new TimeValue(rarely() ? randomIntBetween(500, 5000) : randomIntBetween(20, 500));
            nodesHotThreadsRequestBuilder.setInterval(timeValue);
        }
        if (randomBoolean()) {
            nodesHotThreadsRequestBuilder.setThreads(rarely() ? randomIntBetween(500, 5000) : randomIntBetween(1, 500));
        }
        nodesHotThreadsRequestBuilder.setIgnoreIdleThreads(randomBoolean());
        if (randomBoolean()) {
            switch(randomIntBetween(0, 2)) {
                case 2:
                    type = "cpu";
                    break;
                case 1:
                    type = "wait";
                    break;
                default:
                    type = "block";
                    break;
            }
            assertThat(type, notNullValue());
            nodesHotThreadsRequestBuilder.setType(type);
        } else {
            type = null;
        }
        final CountDownLatch latch = new CountDownLatch(1);
        nodesHotThreadsRequestBuilder.execute(new ActionListener<NodesHotThreadsResponse>() {

            @Override
            public void onResponse(NodesHotThreadsResponse nodeHotThreads) {
                boolean success = false;
                try {
                    assertThat(nodeHotThreads, notNullValue());
                    Map<String, NodeHotThreads> nodesMap = nodeHotThreads.getNodesMap();
                    assertThat(nodesMap.size(), equalTo(cluster().size()));
                    for (NodeHotThreads ht : nodeHotThreads.getNodes()) {
                        assertNotNull(ht.getHotThreads());
                    //logger.info(ht.getHotThreads());
                    }
                    success = true;
                } finally {
                    if (!success) {
                        hasErrors.set(true);
                    }
                    latch.countDown();
                }
            }

            @Override
            public void onFailure(Exception e) {
                logger.error("FAILED", e);
                hasErrors.set(true);
                latch.countDown();
                fail();
            }
        });
        indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"), client().prepareIndex("test", "type1", "2").setSource("field1", "value2"), client().prepareIndex("test", "type1", "3").setSource("field1", "value3"));
        ensureSearchable();
        while (latch.getCount() > 0) {
            assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).setPostFilter(boolQuery().must(matchAllQuery()).mustNot(boolQuery().must(termQuery("field1", "value1")).must(termQuery("field1", "value2")))).get(), 3L);
        }
        latch.await();
        assertThat(hasErrors.get(), is(false));
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodesHotThreadsRequestBuilder(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder) NodeHotThreads(org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads) CountDownLatch(java.util.concurrent.CountDownLatch) NodesHotThreadsResponse(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse) Map(java.util.Map) TimeValue(org.elasticsearch.common.unit.TimeValue) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with NodesHotThreadsResponse

use of org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse in project elasticsearch by elastic.

the class HotThreadsIT method testIgnoreIdleThreads.

public void testIgnoreIdleThreads() throws ExecutionException, InterruptedException {
    assumeTrue("no support for hot_threads on FreeBSD", Constants.FREE_BSD == false);
    // First time, don't ignore idle threads:
    NodesHotThreadsRequestBuilder builder = client().admin().cluster().prepareNodesHotThreads();
    builder.setIgnoreIdleThreads(false);
    builder.setThreads(Integer.MAX_VALUE);
    NodesHotThreadsResponse response = builder.execute().get();
    int totSizeAll = 0;
    for (NodeHotThreads node : response.getNodesMap().values()) {
        totSizeAll += node.getHotThreads().length();
    }
    // Second time, do ignore idle threads:
    builder = client().admin().cluster().prepareNodesHotThreads();
    builder.setThreads(Integer.MAX_VALUE);
    // Make sure default is true:
    assertEquals(true, builder.request().ignoreIdleThreads());
    response = builder.execute().get();
    int totSizeIgnoreIdle = 0;
    for (NodeHotThreads node : response.getNodesMap().values()) {
        totSizeIgnoreIdle += node.getHotThreads().length();
    }
    // The filtered stacks should be smaller than unfiltered ones:
    assertThat(totSizeIgnoreIdle, lessThan(totSizeAll));
}
Also used : NodesHotThreadsRequestBuilder(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder) NodeHotThreads(org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads) NodesHotThreadsResponse(org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse)

Aggregations

NodeHotThreads (org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads)4 NodesHotThreadsResponse (org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse)4 NodesHotThreadsRequestBuilder (org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder)2 TimeValue (org.elasticsearch.common.unit.TimeValue)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 NodesHotThreadsRequest (org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 RestResponse (org.elasticsearch.rest.RestResponse)1 RestStatus (org.elasticsearch.rest.RestStatus)1 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)1