public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); int minWorkerThreads = options.minWorkerThreads; int maxWorkerThreads = options.maxWorkerThreads; if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue( new LinkedBlockingQueue<>(options.maxQueuedRequests), metrics); minWorkerThreads = maxWorkerThreads; } else { this.callQueue = new CallQueue(new SynchronousQueue<>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new THBaseThreadPoolExecutor(minWorkerThreads, maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build(), metrics); executorService.allowCoreThreadTimeOut(true); serverOptions = options; }
protected TServer getTHsHaServer(TNonblockingServerTransport serverTransport, TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) { LOG.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString()); THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY, TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics); int workerThread = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY, serverArgs.getMaxWorkerThreads()); ExecutorService executorService = createExecutor( callQueue, workerThread, workerThread); serverArgs.executorService(executorService).processor(processor) .transportFactory(transportFactory).protocolFactory(protocolFactory); return new THsHaServer(serverArgs); }
protected TServer getTThreadedSelectorServer(TNonblockingServerTransport serverTransport, TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) { LOG.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString()); TThreadedSelectorServer.Args serverArgs = new HThreadedSelectorServerArgs(serverTransport, conf); int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY, TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics); int workerThreads = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY, serverArgs.getWorkerThreads()); int selectorThreads = conf.getInt(THRIFT_SELECTOR_NUM, serverArgs.getSelectorThreads()); serverArgs.selectorThreads(selectorThreads); ExecutorService executorService = createExecutor( callQueue, workerThreads, workerThreads); serverArgs.executorService(executorService).processor(processor) .transportFactory(transportFactory).protocolFactory(protocolFactory); return new TThreadedSelectorServer(serverArgs); }
@Test public void testOfferPoll() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.offer(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.poll(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
@Test public void testPutTake() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.put(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.take(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
private static ExecutorService createExecutor( int workerThreads, ThriftMetrics metrics) { CallQueue callQueue = new CallQueue( new LinkedBlockingQueue<Call>(), metrics); ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift2-worker-%d"); return new ThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build()); }
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue( new LinkedBlockingQueue<Call>(options.maxQueuedRequests), metrics); } else { this.callQueue = new CallQueue(new SynchronousQueue<Call>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build()); serverOptions = options; }
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); int minWorkerThreads = options.minWorkerThreads; int maxWorkerThreads = options.maxWorkerThreads; if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue( new LinkedBlockingQueue<>(options.maxQueuedRequests), metrics); minWorkerThreads = maxWorkerThreads; } else { this.callQueue = new CallQueue(new SynchronousQueue<>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new THBaseThreadPoolExecutor(minWorkerThreads, maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build(), metrics); executorService.allowCoreThreadTimeOut(true); serverOptions = options; }
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); int minWorkerThreads = options.minWorkerThreads; int maxWorkerThreads = options.maxWorkerThreads; if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue( new LinkedBlockingQueue<>(options.maxQueuedRequests), metrics); minWorkerThreads = maxWorkerThreads; } else { this.callQueue = new CallQueue(new SynchronousQueue<>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new THBaseThreadPoolExecutor(minWorkerThreads, maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build(), metrics); executorService.allowCoreThreadTimeOut(true); serverOptions = options; }
private static ExecutorService createExecutor( int workerThreads, int maxCallQueueSize, ThriftMetrics metrics) { CallQueue callQueue; if (maxCallQueueSize > 0) { callQueue = new CallQueue(new LinkedBlockingQueue<>(maxCallQueueSize), metrics); } else { callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift2-worker-%d"); ThreadPoolExecutor pool = new THBaseThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics); pool.prestartAllCoreThreads(); return pool; }
private static ExecutorService createExecutor( int workerThreads, int maxCallQueueSize, ThriftMetrics metrics) { CallQueue callQueue; if (maxCallQueueSize > 0) { callQueue = new CallQueue(new LinkedBlockingQueue<>(maxCallQueueSize), metrics); } else { callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift2-worker-%d"); ThreadPoolExecutor pool = new THBaseThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics); pool.prestartAllCoreThreads(); return pool; }
THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<Call>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getWorkerThreads()); new HThreadedSelectorServerArgs(serverTransport, conf); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<Call>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getWorkerThreads());
@Test public void testOfferPoll() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.offer(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.poll(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
@Test public void testOfferPoll() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.offer(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.poll(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
@Test public void testPutTake() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.put(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.take(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
@Test public void testPutTake() throws Exception { ThriftMetrics metrics = createMetrics(); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); for (int i = 0; i < elementsAdded; ++i) { callQueue.put(createDummyRunnable()); } for (int i = 0; i < elementsRemoved; ++i) { callQueue.take(); } verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved); }
} else if (implType == ImplType.HS_HA) { THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getMaxWorkerThreads(), serverArgs.getMaxWorkerThreads()); TThreadedSelectorServer.Args serverArgs = new HThreadedSelectorServerArgs(serverTransport, conf); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getWorkerThreads(), serverArgs.getWorkerThreads());
} else if (implType == ImplType.HS_HA) { THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getMaxWorkerThreads(), serverArgs.getMaxWorkerThreads()); TThreadedSelectorServer.Args serverArgs = new HThreadedSelectorServerArgs(serverTransport, conf); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics); ExecutorService executorService = createExecutor( callQueue, serverArgs.getWorkerThreads(), serverArgs.getWorkerThreads());