@Test public void testBasic() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); RpcScheduler scheduler = new SimpleRpcScheduler( conf, 10, 0, 0, qosFunction, 0); scheduler.init(CONTEXT); scheduler.start(); CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); scheduler.dispatch(task); verify(task, timeout(10000)).run(); scheduler.stop(); }
@Override public int getActiveRpcHandlerCount() { return delegate.getActiveRpcHandlerCount(); }
SimpleServerRpcConnection register(SocketChannel channel) { SimpleServerRpcConnection connection = getConnection(channel, System.currentTimeMillis()); add(connection); if (LOG.isTraceEnabled()) { LOG.trace("Connection from " + connection + "; connections=" + size() + ", queued calls size (bytes)=" + callQueueSizeInBytes.sum() + ", general queued calls=" + scheduler.getGeneralQueueLength() + ", priority queued calls=" + scheduler.getPriorityQueueLength() + ", meta priority queued calls=" + scheduler.getMetaPriorityQueueLength()); } return connection; }
HConstants.QOS_THRESHOLD); try { scheduler.start(); doAnswerTaskExecution(hugeCallTask, work, 100, 250); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(hugeCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(largeCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask); scheduler.stop();
@Override public void init(Context context) { delegate.init(context); } @Override
@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { return delegate.dispatch(task); }
@Override public void start() { delegate.start(); } @Override
@Override public void stop() { delegate.stop(); } @Override
@Override public int getReplicationQueueLength() { return delegate.getReplicationQueueLength(); }
@Override public int getPriorityQueueLength() { return delegate.getPriorityQueueLength(); }
@Override public int getGeneralQueueLength() { return delegate.getGeneralQueueLength(); }
/** * Test that we delegate to the passed {@link RpcScheduler} when the call priority is outside * the index range * @throws Exception */ @Test public void testDelegateWhenOutsideRange() throws Exception { PriorityFunction qosFunction = Mockito.mock(PriorityFunction.class); Abortable abortable = new AbortServer(); RpcScheduler mock = Mockito.mock(RpcScheduler.class); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, mock, 200, 250,qosFunction,abortable); dispatchCallWithPriority(scheduler, 100); dispatchCallWithPriority(scheduler, 251); // try again, this time we tweak the ranges we support scheduler = new PhoenixRpcScheduler(conf, mock, 101, 110,qosFunction,abortable); dispatchCallWithPriority(scheduler, 200); dispatchCallWithPriority(scheduler, 111); Mockito.verify(mock, Mockito.times(4)).init(Mockito.any(Context.class)); Mockito.verify(mock, Mockito.times(4)).dispatch(Mockito.any(CallRunner.class)); scheduler.stop(); }
@Override public long getNumGeneralCallsDropped() { return delegate.getNumGeneralCallsDropped(); }
@Override public CallQueueInfo getCallQueueInfo() { return delegate.getCallQueueInfo(); } }
HConstants.QOS_THRESHOLD); try { scheduler.start(); scheduler.dispatch(putCallTask); scheduler.dispatch(putCallTask); scheduler.dispatch(putCallTask); scheduler.dispatch(getCallTask); scheduler.dispatch(getCallTask); scheduler.dispatch(getCallTask); scheduler.dispatch(scanCallTask); scheduler.dispatch(scanCallTask); scheduler.dispatch(scanCallTask); scheduler.stop();
/** * Constructs a server listening on the named port and address. * @param server hosting instance of {@link Server}. We will do authentications if an * instance else pass null for no authentication check. * @param name Used keying this rpc servers' metrics and for naming the Listener thread. * @param services A list of services. * @param bindAddress Where to listen * @param conf * @param scheduler * @param reservoirEnabled Enable ByteBufferPool or not. */ public SimpleRpcServer(final Server server, final String name, final List<BlockingServiceAndInterface> services, final InetSocketAddress bindAddress, Configuration conf, RpcScheduler scheduler, boolean reservoirEnabled) throws IOException { super(server, name, services, bindAddress, conf, scheduler, reservoirEnabled); this.socketSendBufferSize = 0; this.readThreads = conf.getInt("hbase.ipc.server.read.threadpool.size", 10); this.purgeTimeout = conf.getLong("hbase.ipc.client.call.purge.timeout", 2 * HConstants.DEFAULT_HBASE_RPC_TIMEOUT); // Start the listener here and let it bind to the port listener = new Listener(name); this.port = listener.getAddress().getPort(); // Create the responder here responder = new SimpleRpcServerResponder(this); connectionManager = new ConnectionManager(); initReconfigurable(conf); this.scheduler.init(new RpcSchedulerContext(this)); }
this.addr, timeout, this.callCleanup); if (!this.rpcServer.scheduler.dispatch(new CallRunner(this.rpcServer, call))) { this.rpcServer.callQueueSizeInBytes.add(-1 * call.getSize()); this.rpcServer.metrics.exception(RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION);
private ThreadPoolExecutor disableHandlers(RpcScheduler scheduler) { ThreadPoolExecutor rpcExecutor=null; try { Field ExecutorField = scheduler.getClass().getDeclaredField("executor"); ExecutorField.setAccessible(true); scheduler.start(); rpcExecutor = (ThreadPoolExecutor) ExecutorField.get(scheduler); rpcExecutor.setMaximumPoolSize(1); rpcExecutor.allowCoreThreadTimeOut(true); rpcExecutor.setCorePoolSize(0); rpcExecutor.setKeepAliveTime(1, TimeUnit.MICROSECONDS); // Wait for 2 seconds, so that idle threads will die Thread.sleep(2000); } catch (NoSuchFieldException e) { LOG.error("No such field exception:"+e); } catch (IllegalAccessException e) { LOG.error("Illegal access exception:"+e); } catch (InterruptedException e) { LOG.error("Interrupted exception:"+e); } return rpcExecutor; }
/** Stops the service. No new calls will be handled after this is called. */ @Override public synchronized void stop() { LOG.info("Stopping server on " + port); running = false; if (authTokenSecretMgr != null) { authTokenSecretMgr.stop(); authTokenSecretMgr = null; } listener.interrupt(); listener.doStop(); responder.interrupt(); scheduler.stop(); notifyAll(); }
@Override public int getReplicationQueueLength() { if (!isServerStarted() || this.server.getScheduler() == null) { return 0; } return server.getScheduler().getReplicationQueueLength(); }