/** * @param readLimit Channel read limit */ public void setReadChannelLimit(long readLimit) { readChannelLimit = readLimit; long now = TrafficCounter.milliSecondFromNano(); for (PerChannel perChannel : channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(now); } }
/** * @param writeLimit Channel write limit */ public void setWriteChannelLimit(long writeLimit) { writeChannelLimit = writeLimit; long now = TrafficCounter.milliSecondFromNano(); for (PerChannel perChannel : channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(now); } }
/** * @param newWriteLimit Channel write limit * @param newReadLimit Channel read limit */ public void configureChannel(long newWriteLimit, long newReadLimit) { writeChannelLimit = newWriteLimit; readChannelLimit = newReadLimit; long now = TrafficCounter.milliSecondFromNano(); for (PerChannel perChannel : channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(now); } }
private void init(long checkInterval) { // absolute time: informative only lastCumulativeTime = System.currentTimeMillis(); writingTime = milliSecondFromNano(); readingTime = writingTime; lastWritingTime = writingTime; lastReadingTime = writingTime; configure(checkInterval); }
private PerChannel getOrSetPerChannel(ChannelHandlerContext ctx) { // ensure creation is limited to one thread per channel Channel channel = ctx.channel(); Integer key = channel.hashCode(); PerChannel perChannel = channelQueues.get(key); if (perChannel == null) { perChannel = new PerChannel(); perChannel.messagesQueue = new ArrayDeque<ToSend>(); perChannel.queueSize = 0L; perChannel.lastReadTimestamp = TrafficCounter.milliSecondFromNano(); perChannel.lastWriteTimestamp = perChannel.lastReadTimestamp; channelQueues.put(key, perChannel); } return perChannel; }
/** * <p>Note the change will be taken as best effort, meaning * that all already scheduled traffics will not be * changed, but only applied to new traffics.</p> * <p>So the expected usage of this method is to be used not too often, * accordingly to the traffic shaping configuration.</p> * * @param readLimit the readLimit to set */ public void setReadLimit(long readLimit) { this.readLimit = readLimit; if (trafficCounter != null) { trafficCounter.resetAccounting(TrafficCounter.milliSecondFromNano()); } }
/** * <p>Note the change will be taken as best effort, meaning * that all already scheduled traffics will not be * changed, but only applied to new traffics.</p> * <p>So the expected usage of this method is to be used not too often, * accordingly to the traffic shaping configuration.</p> * * @param writeLimit the writeLimit to set */ public void setWriteLimit(long writeLimit) { this.writeLimit = writeLimit; if (trafficCounter != null) { trafficCounter.resetAccounting(TrafficCounter.milliSecondFromNano()); } }
/** * Returns the time to wait (if any) for the given length message, using the given limitTraffic and * the max wait time. * * @param size * the write size * @param limitTraffic * the traffic limit in bytes per second. * @param maxTime * the max time in ms to wait in case of excess of traffic. * @return the current time to wait (in ms) if needed for Write operation. */ @Deprecated public long writeTimeToWait(final long size, final long limitTraffic, final long maxTime) { return writeTimeToWait(size, limitTraffic, maxTime, milliSecondFromNano()); }
/** * Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait * time. * * @param size * the recv size * @param limitTraffic * the traffic limit in bytes per second. * @param maxTime * the max time in ms to wait in case of excess of traffic. * @return the current time to wait (in ms) if needed for Read operation. */ @Deprecated public long readTimeToWait(final long size, final long limitTraffic, final long maxTime) { return readTimeToWait(size, limitTraffic, maxTime, milliSecondFromNano()); }
/** * Start the monitoring process. */ public synchronized void start() { if (monitorActive) { return; } lastTime.set(milliSecondFromNano()); long localCheckInterval = checkInterval.get(); // if executor is null, it means it is piloted by a GlobalChannelTrafficCounter, so no executor if (localCheckInterval > 0 && executor != null) { monitorActive = true; monitor = new TrafficMonitoringTask(); scheduledFuture = executor.schedule(monitor, localCheckInterval, TimeUnit.MILLISECONDS); } }
/** * Change the underlying limitations. * <p>Note the change will be taken as best effort, meaning * that all already scheduled traffics will not be * changed, but only applied to new traffics.</p> * <p>So the expected usage of this method is to be used not too often, * accordingly to the traffic shaping configuration.</p> * * @param newWriteLimit The new write limit (in bytes) * @param newReadLimit The new read limit (in bytes) */ public void configure(long newWriteLimit, long newReadLimit) { writeLimit = newWriteLimit; readLimit = newReadLimit; if (trafficCounter != null) { trafficCounter.resetAccounting(TrafficCounter.milliSecondFromNano()); } }
/** * @param readLimit Channel read limit */ public void setReadChannelLimit(long readLimit) { readChannelLimit = readLimit; long now = TrafficCounter.milliSecondFromNano(); for (PerChannel perChannel : channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(now); } }
private void init(long checkInterval) { // absolute time: informative only lastCumulativeTime = System.currentTimeMillis(); writingTime = milliSecondFromNano(); readingTime = writingTime; lastWritingTime = writingTime; lastReadingTime = writingTime; configure(checkInterval); }
/** * @param writeLimit Channel write limit */ public void setWriteChannelLimit(long writeLimit) { writeChannelLimit = writeLimit; long now = TrafficCounter.milliSecondFromNano(); for (PerChannel perChannel : channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(now); } }
@Override public void run() { if (!monitorActive) { return; } resetAccounting(milliSecondFromNano()); if (trafficShapingHandler != null) { trafficShapingHandler.doAccounting(TrafficCounter.this); } scheduledFuture = executor.schedule(this, checkInterval.get(), TimeUnit.MILLISECONDS); } }
private PerChannel getOrSetPerChannel(ChannelHandlerContext ctx) { // ensure creation is limited to one thread per channel Channel channel = ctx.channel(); Integer key = channel.hashCode(); PerChannel perChannel = channelQueues.get(key); if (perChannel == null) { perChannel = new PerChannel(); perChannel.messagesQueue = new ArrayDeque<ToSend>(); // Don't start it since managed through the Global one perChannel.channelTrafficCounter = new TrafficCounter(this, null, "ChannelTC" + ctx.channel().hashCode(), checkInterval); perChannel.queueSize = 0L; perChannel.lastReadTimestamp = TrafficCounter.milliSecondFromNano(); perChannel.lastWriteTimestamp = perChannel.lastReadTimestamp; channelQueues.put(key, perChannel); } return perChannel; }
abstract void submitWrite( ChannelHandlerContext ctx, Object msg, long size, long delay, long now, ChannelPromise promise);
/** * Change checkInterval between two computations in millisecond. * * @param newCheckInterval The new check interval (in milliseconds) */ public void configure(long newCheckInterval) { long newInterval = newCheckInterval / 10 * 10; if (checkInterval.getAndSet(newInterval) != newInterval) { if (newInterval <= 0) { stop(); // No more active monitoring lastTime.set(milliSecondFromNano()); } else { // Start if necessary start(); } } }
/** * Stop the monitoring process. */ public synchronized void stop() { if (!monitorActive) { return; } monitorActive = false; resetAccounting(milliSecondFromNano()); if (trafficShapingHandler != null) { trafficShapingHandler.doAccounting(this); } if (scheduledFuture != null) { scheduledFuture.cancel(true); } }
@Override public void run() { if (!counter.monitorActive) { return; } long newLastTime = milliSecondFromNano(); counter.resetAccounting(newLastTime); for (PerChannel perChannel : trafficShapingHandler1.channelQueues.values()) { perChannel.channelTrafficCounter.resetAccounting(newLastTime); } trafficShapingHandler1.doAccounting(counter); counter.scheduledFuture = counter.executor.schedule(this, counter.checkInterval.get(), TimeUnit.MILLISECONDS); } }