@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); } }
if (call.disconnectSince() >= 0) { if (RpcServer.LOG.isDebugEnabled()) { RpcServer.LOG.debug(Thread.currentThread().getName() + ": skipped " + call); call.setResponse(null, null, CALL_DROPPED_EXCEPTION, "Call dropped, server " + (address != null ? address : "(channel closed)") + " is overloaded, please retry."); call.sendResponseIfReady(); } catch (ClosedChannelException cce) { InetSocketAddress address = rpcServer.getListenerAddress(); } finally { if (!sucessful) { this.rpcServer.addCallSize(call.getSize() * -1);
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; }
@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); }
public void run() { try { if (call.disconnectSince() >= 0) { if (RpcServer.LOG.isDebugEnabled()) { RpcServer.LOG.debug(Thread.currentThread().getName() + ": skipped " + call); call.setStartTime(System.currentTimeMillis()); if (call.getStartTime() > call.getDeadline()) { RpcServer.LOG.warn("Dropping timed out call: " + call); return; this.status.setConnection(call.getRemoteAddress().getHostAddress(), call.getRemotePort()); if (RpcServer.LOG.isTraceEnabled()) { Optional<User> remoteUser = call.getRequestUser(); RpcServer.LOG.trace(call.toShortString() + " executing as " + (remoteUser.isPresent() ? "NULL principal" : remoteUser.get().getName())); call.getService() != null ? call.getService().getDescriptorForType().getName() : ""; String methodName = (call.getMethod() != null) ? call.getMethod().getName() : ""; String traceString = serviceName + "." + methodName; TraceUtil.createTrace(traceString); RpcServer.LOG.trace(call.toShortString(), e); RpcServer.LOG.debug(call.toShortString() + ", exception=" + e); RpcServer.CurCall.set(null); if (resultPair != null) { this.rpcServer.addCallSize(call.getSize() * -1); sucessful = true;
MonitoredRPCHandler status) throws IOException { try { MethodDescriptor md = call.getMethod(); Message param = call.getParam(); status.setRPC(md.getName(), new Object[]{param}, call.getReceiveTime()); HBaseRpcController controller = new HBaseRpcControllerImpl(call.getCellScanner()); controller.setCallTimeout(call.getTimeout()); Message result = call.getService().callBlockingMethod(md, controller, param); long receiveTime = call.getReceiveTime(); long startTime = call.getStartTime(); long endTime = System.currentTimeMillis(); int processingTime = (int) (endTime - startTime); long requestSize = call.getSize(); long responseSize = result.getSerializedSize(); if (call.isClientCellBlockSupported()) { responseSize += call.getResponseCellSize();
@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 public boolean dispatch(CallRunner task) throws IOException, InterruptedException { int priority = task.getRpcCall().getPriority(); if (priority > HConstants.QOS_THRESHOLD) { numPriorityCalls++; } return super.dispatch(task); } }
/** Returns the remote side ip address when invoked inside an RPC * Returns null incase of an error. * @return InetAddress */ public static InetAddress getRemoteIp() { RpcCall call = CurCall.get(); if (call != null) { return call.getRemoteAddress(); } return null; }
/** * @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; }
Optional<RpcCall> call = RpcServer.getCurrentCall(); if (call.isPresent()) { long deadline = call.get().getDeadline(); if (deadline < Long.MAX_VALUE) { int timeToDeadline = (int) (deadline - System.currentTimeMillis());
long afterTime = rpcCall.get().disconnectSince(); if (afterTime >= 0) { throw new CallerDisconnectedException(
@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { int priority = task.getRpcCall().getPriority(); if (priority > HConstants.QOS_THRESHOLD) { numPriorityCalls++; } return super.dispatch(task); } }
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; }