当前位置: 首页>>代码示例>>Java>>正文


Java EsExecutors.newFixed方法代码示例

本文整理汇总了Java中org.elasticsearch.common.util.concurrent.EsExecutors.newFixed方法的典型用法代码示例。如果您正苦于以下问题:Java EsExecutors.newFixed方法的具体用法?Java EsExecutors.newFixed怎么用?Java EsExecutors.newFixed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.util.concurrent.EsExecutors的用法示例。


在下文中一共展示了EsExecutors.newFixed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Override
ThreadPool.ExecutorHolder build(final FixedExecutorSettings settings, final ThreadContext threadContext) {
    int size = settings.size;
    int queueSize = settings.queueSize;
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(EsExecutors.threadName(settings.nodeName, name()));
    final ExecutorService executor = EsExecutors.newFixed(name(), size, queueSize, threadFactory, threadContext);
    final ThreadPool.Info info =
        new ThreadPool.Info(name(), ThreadPool.ThreadPoolType.FIXED, size, size, null, queueSize < 0 ? null : new SizeValue(queueSize));
    return new ThreadPool.ExecutorHolder(executor, info);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:FixedExecutorBuilder.java

示例2: LocalTransport

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Inject
public LocalTransport(Settings settings, ThreadPool threadPool, Version version, NamedWriteableRegistry namedWriteableRegistry) {
    super(settings);
    this.threadPool = threadPool;
    this.version = version;
    int workerCount = this.settings.getAsInt(TRANSPORT_LOCAL_WORKERS, EsExecutors.boundedNumberOfProcessors(settings));
    int queueSize = this.settings.getAsInt(TRANSPORT_LOCAL_QUEUE, -1);
    logger.debug("creating [{}] workers, queue_size [{}]", workerCount, queueSize);
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(this.settings, LOCAL_TRANSPORT_THREAD_NAME_PREFIX);
    this.workers = EsExecutors.newFixed(LOCAL_TRANSPORT_THREAD_NAME_PREFIX, workerCount, queueSize, threadFactory);
    this.namedWriteableRegistry = namedWriteableRegistry;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:LocalTransport.java

示例3: testThreadedRandomDocs

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Test
public void testThreadedRandomDocs() throws Exception {
    int maxthreads = Runtime.getRuntime().availableProcessors();
    int maxactions = MAX_ACTIONS;
    final long maxloop = NUM_ACTIONS;
    logger.info("HttpBulkNodeClient max={} maxactions={} maxloop={}", maxthreads, maxactions, maxloop);
    final HttpBulkClient client = HttpBulkClient.builder()
            .url(new URL("http://127.0.0.1:9200"))
            .maxActionsPerRequest(maxactions)
            .flushIngestInterval(TimeValue.timeValueSeconds(60))
            .build();
    try {
        client.newIndex("test")
                .startBulk("test", -1);
        ThreadPoolExecutor pool = EsExecutors.newFixed("http-bulk-nodeclient-test", maxthreads, 30,
                EsExecutors.daemonThreadFactory("http-bulk-nodeclient-test"));
        final CountDownLatch latch = new CountDownLatch(maxthreads);
        for (int i = 0; i < maxthreads; i++) {
            pool.execute(() -> {
                for (int j = 0; j < maxloop; j++) {
                    client.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
                }
                latch.countDown();
            });
        }
        logger.info("waiting for max 30 seconds...");
        latch.await(30, TimeUnit.SECONDS);
        logger.info("flush...");
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        logger.info("got all responses, thread pool shutdown...");
        pool.shutdown();
        logger.info("pool is shut down");
        client.stopBulk("test", 1000);
        if (client.hasException()) {
            logger.error("error", client.getException());
        }
        assertFalse(client.hasException());
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setQuery(QueryBuilders.matchAllQuery()).setSize(0);
        assertEquals(maxthreads * maxloop,
                searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-client-http,代码行数:51,代码来源:HttpBulkClientTest.java

示例4: testThreadedRandomDocs

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Test
public void testThreadedRandomDocs() throws Exception {
    int maxthreads = Runtime.getRuntime().availableProcessors();
    long maxactions = MAX_ACTIONS;
    final long maxloop = NUM_ACTIONS;
    logger.info("HttpBulkNodeClient max={} maxactions={} maxloop={}", maxthreads, maxactions, maxloop);
    final HttpBulkNodeClient client = ClientBuilder.builder()
            .put("host", "127.0.0.1")
            .put("port", 9200)
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, maxactions)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))
            .setMetric(new LongAdderIngestMetric())
            .toHttpBulkNodeClient();
    try {
        client.newIndex("test")
                .startBulk("test", -1, 1000);
        ThreadPoolExecutor pool = EsExecutors.newFixed("http-bulk-nodeclient-test", maxthreads, 30,
                EsExecutors.daemonThreadFactory("http-bulk-nodeclient-test"));
        final CountDownLatch latch = new CountDownLatch(maxthreads);
        for (int i = 0; i < maxthreads; i++) {
            pool.execute(new Runnable() {
                public void run() {
                    for (int i = 0; i < maxloop; i++) {
                        client.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
                    }
                    latch.countDown();
                }
            });
        }
        logger.info("waiting for max 30 seconds...");
        latch.await(30, TimeUnit.SECONDS);
        logger.info("flush...");
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        logger.info("got all responses, thread pool shutdown...");
        pool.shutdown();
        logger.info("pool is shut down");
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.stopBulk("test");
        assertEquals(maxthreads * maxloop, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setQuery(QueryBuilders.matchAllQuery()).setSize(0);
        assertEquals(maxthreads * maxloop,
                searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:55,代码来源:HttpBulkNodeClientTest.java

示例5: testThreadedRandomDocsIngestClient

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Test
public void testThreadedRandomDocsIngestClient() throws Exception {
    int maxthreads = Runtime.getRuntime().availableProcessors();
    long maxactions = MAX_ACTIONS;
    final long maxloop = NUM_ACTIONS;
    Settings settings = Settings.settingsBuilder()
            .put("index.number_of_shards", 2)
            .put("index.number_of_replicas", 1)
            .build();
    final IngestTransportClient ingest = ClientBuilder.builder()
            .put(getSettings())
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, maxactions)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))
            .setMetric(new LongAdderIngestMetric())
            .toIngestTransportClient();
    try {
        ingest.newIndex("test", settings, null)
                .startBulk("test", -1, 1000);
        ThreadPoolExecutor pool =
                EsExecutors.newFixed("ingestclient-test", maxthreads, 30, EsExecutors.daemonThreadFactory("ingestclient-test"));
        final CountDownLatch latch = new CountDownLatch(maxthreads);
        for (int i = 0; i < maxthreads; i++) {
            pool.execute(new Runnable() {
                public void run() {
                    for (int i = 0; i < maxloop; i++) {
                        ingest.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
                    }
                    latch.countDown();
                }
            });
        }
        logger.info("waiting for max 30 seconds...");
        latch.await(30, TimeUnit.SECONDS);
        logger.info("client flush ...");
        ingest.flushIngest();
        ingest.waitForResponses(TimeValue.timeValueSeconds(30));
        logger.info("thread pool to be shut down ...");
        pool.shutdown();
        logger.info("thread pool shut down");
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        ingest.stopBulk("test");
        assertEquals(maxthreads * maxloop, ingest.getMetric().getSucceeded().getCount());
        if (ingest.hasThrowable()) {
            logger.error("error", ingest.getThrowable());
        }
        assertFalse(ingest.hasThrowable());
        ingest.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(ingest.client(), SearchAction.INSTANCE)
                .setIndices("_all") // to avoid NPE
                .setQuery(QueryBuilders.matchAllQuery())
                .setSize(0);
        assertEquals(maxthreads * maxloop,
                searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
        ingest.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:59,代码来源:IngestTransportClientTest.java

示例6: testThreadedRandomDocsBulkClient

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Test
public void testThreadedRandomDocsBulkClient() throws Exception {
    int maxthreads = Runtime.getRuntime().availableProcessors();
    long maxactions = MAX_ACTIONS;
    final long maxloop = NUM_ACTIONS;

    Settings settingsForIndex = Settings.settingsBuilder()
            .put("index.number_of_shards", 2)
            .put("index.number_of_replicas", 1)
            .build();

    final BulkTransportClient client = ClientBuilder.builder()
            .put(getSettings())
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, maxactions)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60)) // = disable autoflush for this test
            .setMetric(new LongAdderIngestMetric())
            .toBulkTransportClient();
    try {
        client.newIndex("test", settingsForIndex, null)
                .startBulk("test", -1, 1000);
        ThreadPoolExecutor pool =
                EsExecutors.newFixed("bulkclient-test", maxthreads, 30, EsExecutors.daemonThreadFactory("bulkclient-test"));
        final CountDownLatch latch = new CountDownLatch(maxthreads);
        for (int i = 0; i < maxthreads; i++) {
            pool.execute(new Runnable() {
                public void run() {
                    for (int i = 0; i < maxloop; i++) {
                        client.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
                    }
                    latch.countDown();
                }
            });
        }
        logger.info("waiting for max 30 seconds...");
        latch.await(30, TimeUnit.SECONDS);
        logger.info("client flush ...");
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        logger.info("thread pool to be shut down ...");
        pool.shutdown();
        logger.info("poot shut down");
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.stopBulk("test");
        assertEquals(maxthreads * maxloop, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setIndices("_all") // to avoid NPE at org.elasticsearch.action.search.SearchRequest.writeTo(SearchRequest.java:580)
                .setQuery(QueryBuilders.matchAllQuery())
                .setSize(0);
        assertEquals(maxthreads * maxloop,
                searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:61,代码来源:BulkTransportClientTest.java

示例7: testThreadedRandomDocsNodeClient

import org.elasticsearch.common.util.concurrent.EsExecutors; //导入方法依赖的package包/类
@Test
public void testThreadedRandomDocsNodeClient() throws Exception {
    int maxthreads = Runtime.getRuntime().availableProcessors();
    Long maxactions = MAX_ACTIONS;
    final Long maxloop = NUM_ACTIONS;
    logger.info("NodeClient max={} maxactions={} maxloop={}", maxthreads, maxactions, maxloop);
    final BulkNodeClient client = ClientBuilder.builder()
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, maxactions)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))// disable auto flush for this test
            .setMetric(new LongAdderIngestMetric())
            .toBulkNodeClient(client("1"));
    try {
        client.newIndex("test")
                .startBulk("test", -1, 1000);
        ThreadPoolExecutor pool = EsExecutors.newFixed("bulk-nodeclient-test", maxthreads, 30,
                EsExecutors.daemonThreadFactory("bulk-nodeclient-test"));
        final CountDownLatch latch = new CountDownLatch(maxthreads);
        for (int i = 0; i < maxthreads; i++) {
            pool.execute(new Runnable() {
                public void run() {
                    for (int i = 0; i < maxloop; i++) {
                        client.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
                    }
                    latch.countDown();
                }
            });
        }
        logger.info("waiting for max 30 seconds...");
        latch.await(30, TimeUnit.SECONDS);
        logger.info("flush...");
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        logger.info("got all responses, thread pool shutdown...");
        pool.shutdown();
        logger.info("pool is shut down");
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.stopBulk("test");
        assertEquals(maxthreads * maxloop, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setQuery(QueryBuilders.matchAllQuery()).setSize(0);
        assertEquals(maxthreads * maxloop,
                searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:53,代码来源:BulkNodeClientTest.java


注:本文中的org.elasticsearch.common.util.concurrent.EsExecutors.newFixed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。