private EventExecutor chooseWithLeastConns() { EventExecutor leastExec = null; int leastValue = Integer.MAX_VALUE; Map<Thread, Integer> connsPer = groupMetrics.connectionsPerEventLoop(); // Shuffle the list of executors each time so that if they all have the same number of connections, then // we don't favour the 1st one. Collections.shuffle(executors, ThreadLocalRandom.current()); for (EventExecutor executor : executors) { int value = connsPer.getOrDefault(executor, 0); if (value < leastValue) { leastValue = value; leastExec = executor; } } // If none chosen, then just use first. if (leastExec == null) { leastExec = executors.get(0); } if (LOG.isDebugEnabled()) { LOG.debug("Chose eventloop: " + String.valueOf(leastExec) + ", leastValue=" + leastValue + ", connsPer=" + String.valueOf(connsPer)); } return leastExec; } }
private void incrementCurrentRequestsInFlight(ChannelHandlerContext ctx) { groupMetrics.getForCurrentEventLoop().incrementCurrentRequests(); ctx.channel().attr(ATTR_REQ_INFLIGHT).set(INFLIGHT); }
@Inject public EventLoopGroupMetrics(Registry registry) { this.registry = registry; this.metricsForCurrentThread = ThreadLocal.withInitial(() -> { String name = nameForCurrentEventLoop(); EventLoopMetrics metrics = new EventLoopMetrics(registry, name); byEventLoop.put(Thread.currentThread(), metrics); return metrics; }); }
private void decrementCurrentRequestsIfOneInflight(ChannelHandlerContext ctx) { if (ctx.channel().attr(ATTR_REQ_INFLIGHT).getAndRemove() != null) { groupMetrics.getForCurrentEventLoop().decrementCurrentRequests(); } } }
@Inject public EventLoopGroupMetrics(Registry registry) { this.registry = registry; this.metricsForCurrentThread = ThreadLocal.withInitial(() -> { String name = nameForCurrentEventLoop(); EventLoopMetrics metrics = new EventLoopMetrics(registry, name); byEventLoop.put(Thread.currentThread(), metrics); return metrics; }); }
private EventExecutor chooseWithLeastConns() { EventExecutor leastExec = null; int leastValue = Integer.MAX_VALUE; Map<Thread, Integer> connsPer = groupMetrics.connectionsPerEventLoop(); // Shuffle the list of executors each time so that if they all have the same number of connections, then // we don't favour the 1st one. Collections.shuffle(executors, ThreadLocalRandom.current()); for (EventExecutor executor : executors) { int value = connsPer.getOrDefault(executor, 0); if (value < leastValue) { leastValue = value; leastExec = executor; } } // If none chosen, then just use first. if (leastExec == null) { leastExec = executors.get(0); } if (LOG.isDebugEnabled()) { LOG.debug("Chose eventloop: " + String.valueOf(leastExec) + ", leastValue=" + leastValue + ", connsPer=" + String.valueOf(connsPer)); } return leastExec; } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { groupMetrics.getForCurrentEventLoop().decrementCurrentConnections(); } } }
@Inject public EventLoopGroupMetrics(Registry registry) { this.registry = registry; this.metricsForCurrentThread = ThreadLocal.withInitial(() -> { String name = nameForCurrentEventLoop(); EventLoopMetrics metrics = new EventLoopMetrics(registry, name); byEventLoop.put(Thread.currentThread(), metrics); return metrics; }); }
private EventExecutor chooseWithLeastConns() { EventExecutor leastExec = null; int leastValue = Integer.MAX_VALUE; Map<Thread, Integer> connsPer = groupMetrics.connectionsPerEventLoop(); // Shuffle the list of executors each time so that if they all have the same number of connections, then // we don't favour the 1st one. Collections.shuffle(executors, ThreadLocalRandom.current()); for (EventExecutor executor : executors) { int value = connsPer.getOrDefault(executor, 0); if (value < leastValue) { leastValue = value; leastExec = executor; } } // If none chosen, then just use first. if (leastExec == null) { leastExec = executors.get(0); } if (LOG.isDebugEnabled()) { LOG.debug("Chose eventloop: " + String.valueOf(leastExec) + ", leastValue=" + leastValue + ", connsPer=" + String.valueOf(connsPer)); } return leastExec; } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { groupMetrics.getForCurrentEventLoop().incrementCurrentConnections(); super.channelActive(ctx); }
private void incrementCurrentRequestsInFlight(ChannelHandlerContext ctx) { groupMetrics.getForCurrentEventLoop().incrementCurrentRequests(); ctx.channel().attr(ATTR_REQ_INFLIGHT).set(INFLIGHT); }
private void decrementCurrentRequestsIfOneInflight(ChannelHandlerContext ctx) { if (ctx.channel().attr(ATTR_REQ_INFLIGHT).getAndRemove() != null) { groupMetrics.getForCurrentEventLoop().decrementCurrentRequests(); } } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { groupMetrics.getForCurrentEventLoop().incrementCurrentConnections(); super.channelActive(ctx); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { groupMetrics.getForCurrentEventLoop().decrementCurrentConnections(); } } }
private void incrementCurrentRequestsInFlight(ChannelHandlerContext ctx) { groupMetrics.getForCurrentEventLoop().incrementCurrentRequests(); ctx.channel().attr(ATTR_REQ_INFLIGHT).set(INFLIGHT); }
private void decrementCurrentRequestsIfOneInflight(ChannelHandlerContext ctx) { if (ctx.channel().attr(ATTR_REQ_INFLIGHT).getAndRemove() != null) { groupMetrics.getForCurrentEventLoop().decrementCurrentRequests(); } } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { groupMetrics.getForCurrentEventLoop().decrementCurrentConnections(); } } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { groupMetrics.getForCurrentEventLoop().incrementCurrentConnections(); super.channelActive(ctx); }