/** * @param callRunner to validate * @return true if this call needs to be skipped based on call timestamp * and internal queue state (deemed overloaded). */ private boolean needToDrop(CallRunner callRunner) { long now = EnvironmentEdgeManager.currentTime(); long callDelay = now - callRunner.getRpcCall().getReceiveTime(); long localMinDelay = this.minDelay; // Try and determine if we should reset // the delay time and determine overload if (now > intervalTime && !resetDelay.get() && !resetDelay.getAndSet(true)) { intervalTime = now + codelInterval; isOverloaded.set(localMinDelay > codelTargetDelay); } // If it looks like we should reset the delay // time do it only once on one thread if (resetDelay.get() && resetDelay.getAndSet(false)) { minDelay = callDelay; // we just reset the delay dunno about how this will work return false; } else if (callDelay < localMinDelay) { minDelay = callDelay; } return isOverloaded.get() && callDelay > 2 * codelTargetDelay; }
private CallRunner createMockTask() { ServerCall call = mock(ServerCall.class); CallRunner task = mock(CallRunner.class); when(task.getRpcCall()).thenReturn(call); return task; }
@Override public int compare(CallRunner a, CallRunner b) { RpcCall callA = a.getRpcCall(); RpcCall callB = b.getRpcCall(); long deadlineA = priority.getDeadline(callA.getHeader(), callA.getParam()); long deadlineB = priority.getDeadline(callB.getHeader(), callB.getParam()); deadlineA = callA.getReceiveTime() + Math.min(deadlineA, maxDelay); deadlineB = callB.getReceiveTime() + Math.min(deadlineB, maxDelay); return Long.compare(deadlineA, deadlineB); } }
protected String getCallMethod(final CallRunner task) { RpcCall call = task.getRpcCall(); if (call != null && call.getMethod() != null) { return call.getMethod().getName(); } return null; } }
public Map<String, Long> getCallQueueCountsSummary() { HashMap<String, Long> callQueueMethodTotalCount = new HashMap<>(); for(BlockingQueue<CallRunner> queue: queues) { for (CallRunner cr:queue) { RpcCall rpcCall = cr.getRpcCall(); String method; if (null==rpcCall.getMethod() || StringUtil.isNullOrEmpty(method = rpcCall.getMethod().getName())) { method = "Unknown"; } callQueueMethodTotalCount.put(method, 1+callQueueMethodTotalCount.getOrDefault(method, 0L)); } } return callQueueMethodTotalCount; }
private CallRunner createMockTask() { ServerCall call = mock(ServerCall.class); CallRunner task = mock(CallRunner.class); when(task.getRpcCall()).thenReturn(call); doAnswer(new Answer<Void>() { @Override public Void answer (InvocationOnMock invocation) throws Throwable { callExecutionCount.incrementAndGet(); Thread.sleep(1000); return null; } }).when(task).run(); return task; }
public Map<String, Long> getCallQueueSizeSummary() { HashMap<String, Long> callQueueMethodTotalSize = new HashMap<>(); for(BlockingQueue<CallRunner> queue: queues) { for (CallRunner cr:queue) { RpcCall rpcCall = cr.getRpcCall(); String method; if (null==rpcCall.getMethod() || StringUtil.isNullOrEmpty(method = rpcCall.getMethod().getName())) { method = "Unknown"; } long size = rpcCall.getSize(); callQueueMethodTotalSize.put(method, size+callQueueMethodTotalSize.getOrDefault(method, 0L)); } } return callQueueMethodTotalSize; }
protected void updateMethodCountAndSizeByQueue(BlockingQueue<Runnable> queue, HashMap<String, Long> methodCount, HashMap<String, Long> methodSize) { for (Runnable r : queue) { FifoCallRunner mcr = (FifoCallRunner) r; RpcCall rpcCall = mcr.getCallRunner().getRpcCall(); String method = getCallMethod(mcr.getCallRunner()); if (StringUtil.isNullOrEmpty(method)) { method = "Unknown"; } long size = rpcCall.getSize(); methodCount.put(method, 1 + methodCount.getOrDefault(method, 0L)); methodSize.put(method, size + methodSize.getOrDefault(method, 0L)); } }
@Override public boolean dispatch(final CallRunner callTask) throws InterruptedException { RpcCall call = callTask.getRpcCall(); int queueIndex; if (isWriteRequest(call.getHeader(), call.getParam())) { queueIndex = writeBalancer.getNextQueue(); } else if (numScanQueues > 0 && isScanRequest(call.getHeader(), call.getParam())) { queueIndex = numWriteQueues + numReadQueues + scanBalancer.getNextQueue(); } else { queueIndex = numWriteQueues + readBalancer.getNextQueue(); } BlockingQueue<CallRunner> queue = queues.get(queueIndex); if (queue.size() >= currentQueueLimit) { return false; } return queue.offer(callTask); }
@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { int priority = task.getRpcCall().getPriority(); if (priority > HConstants.QOS_THRESHOLD) { numPriorityCalls++; } return super.dispatch(task); } }
private CallRunner createMockTask(AtomicInteger callExecutionCount, boolean isRegionServerReportTask) { CallRunner task = mock(CallRunner.class); ServerCall call = mock(ServerCall.class); when(task.getRpcCall()).thenReturn(call); when(call.getHeader()).thenReturn(RPCProtos.RequestHeader.newBuilder() .setMethodName(isRegionServerReportTask ? REGION_SERVER_REPORT : OTHER).build()); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { callExecutionCount.incrementAndGet(); Thread.sleep(1000); return null; } }).when(task).run(); return task; }
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException { RpcCall call = callTask.getRpcCall(); int level = priority.getPriority(call.getHeader(), call.getParam(), call.getRequestUser().orElse(null)); if (level == HConstants.PRIORITY_UNSET) { level = HConstants.NORMAL_QOS; } if (metaTransitionExecutor != null && level == HConstants.META_QOS) { return metaTransitionExecutor.dispatch(callTask); } else if (priorityExecutor != null && level > highPriorityLevel) { return priorityExecutor.dispatch(callTask); } else if (replicationExecutor != null && level == HConstants.REPLICATION_QOS) { return replicationExecutor.dispatch(callTask); } else { return callExecutor.dispatch(callTask); } }
/** * Override this method because we can't mock a Descriptors.MethodDescriptor */ @Override protected String getCallMethod(final CallRunner task) { RpcCall call = task.getRpcCall(); if (call.getHeader() != null) { return call.getHeader().getMethodName(); } return null; } }
Bytes.toBytes("abc"), new Put(Bytes.toBytes("row"))); RequestHeader putHead = RequestHeader.newBuilder().setMethodName("mutate").build(); when(putCallTask.getRpcCall()).thenReturn(putCall); when(putCall.getHeader()).thenReturn(putHead);
ServerCall smallCall = mock(ServerCall.class); RequestHeader smallHead = RequestHeader.newBuilder().setCallId(1).build(); when(smallCallTask.getRpcCall()).thenReturn(smallCall); when(smallCall.getHeader()).thenReturn(smallHead); ServerCall largeCall = mock(ServerCall.class); RequestHeader largeHead = RequestHeader.newBuilder().setCallId(50).build(); when(largeCallTask.getRpcCall()).thenReturn(largeCall); when(largeCall.getHeader()).thenReturn(largeHead); ServerCall hugeCall = mock(ServerCall.class); RequestHeader hugeHead = RequestHeader.newBuilder().setCallId(100).build(); when(hugeCallTask.getRpcCall()).thenReturn(hugeCall); when(hugeCall.getHeader()).thenReturn(hugeHead);
Bytes.toBytes("abc"), new Put(Bytes.toBytes("row"))); RequestHeader putHead = RequestHeader.newBuilder().setMethodName("mutate").build(); when(putCallTask.getRpcCall()).thenReturn(putCall); when(putCall.getHeader()).thenReturn(putHead); when(putCall.getParam()).thenReturn(putCall.param); ServerCall getCall = mock(ServerCall.class); RequestHeader getHead = RequestHeader.newBuilder().setMethodName("get").build(); when(getCallTask.getRpcCall()).thenReturn(getCall); when(getCall.getHeader()).thenReturn(getHead); scanCall.param = ScanRequest.newBuilder().setScannerId(1).build(); RequestHeader scanHead = RequestHeader.newBuilder().setMethodName("scan").build(); when(scanCallTask.getRpcCall()).thenReturn(scanCall); when(scanCall.getHeader()).thenReturn(scanHead); when(scanCall.getParam()).thenReturn(scanCall.param);
private CallRunner createMockTask() { ServerCall call = mock(ServerCall.class); CallRunner task = mock(CallRunner.class); when(task.getRpcCall()).thenReturn(call); return task; }
private CallRunner createMockTask() { ServerCall call = mock(ServerCall.class); CallRunner task = mock(CallRunner.class); when(task.getRpcCall()).thenReturn(call); doAnswer(new Answer<Void>() { @Override public Void answer (InvocationOnMock invocation) throws Throwable { callExecutionCount.incrementAndGet(); Thread.sleep(1000); return null; } }).when(task).run(); return task; }
@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { int priority = task.getRpcCall().getPriority(); if (priority > HConstants.QOS_THRESHOLD) { numPriorityCalls++; } return super.dispatch(task); } }
/** * Override this method because we can't mock a Descriptors.MethodDescriptor */ @Override protected String getCallMethod(final CallRunner task) { RpcCall call = task.getRpcCall(); if (call.getHeader() != null) { return call.getHeader().getMethodName(); } return null; } }