From: Robert Varga Date: Sun, 7 Jun 2015 00:23:41 +0000 (+0200) Subject: Tune write low/highwatermark X-Git-Tag: release/lithium~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=754bef597c3b9de84e26bde968e7ab9a502344ff;p=openflowjava.git Tune write low/highwatermark Since we rely on channel writability to throttle message writout, bring it higher up a bit, so we can flush an entire segment in one go. Change-Id: I9394aa795d3e30375f50ffd84efecbe05aa49bf4 Signed-off-by: Robert Varga --- diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java index b3b7b8c3..66fa8a60 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java @@ -43,6 +43,19 @@ final class OutboundQueueManager extends Channel */ private static final int WORKTIME_RECHECK_MSGS = 64; + /** + * Default low write watermark. Channel will become writable when number of outstanding + * bytes dips below this value. + */ + private static final int DEFAULT_LOW_WATERMARK = 128 * 1024; + + /** + * Default write high watermark. Channel will become un-writable when number of + * outstanding bytes hits this value. + */ + private static final int DEFAULT_HIGH_WATERMARK = DEFAULT_LOW_WATERMARK * 2; + + private final Queue activeQueues = new LinkedList<>(); private final AtomicBoolean flushScheduled = new AtomicBoolean(); private final ConnectionAdapterImpl parent; @@ -317,7 +330,9 @@ final class OutboundQueueManager extends Channel } /** - * Perform a single flush operation. + * Perform a single flush operation. We keep it here so we do not generate + * syntetic accessors for private fields. Otherwise it could be moved into + * {@link #flushRunnable}. */ protected void flush() { // If the channel is gone, just flush whatever is not completed @@ -405,6 +420,19 @@ final class OutboundQueueManager extends Channel conditionalFlush(ctx); } + public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { + /* + * Tune channel write buffering. We increase the writability window + * to ensure we can flush an entire queue segment in one go. We definitely + * want to keep the difference above 64k, as that will ensure we use jam-packed + * TCP packets. UDP will fragment as appropriate. + */ + ctx.channel().config().setWriteBufferHighWaterMark(DEFAULT_HIGH_WATERMARK); + ctx.channel().config().setWriteBufferLowWaterMark(DEFAULT_LOW_WATERMARK); + + super.handlerAdded(ctx); + } + @Override public void channelWritabilityChanged(final ChannelHandlerContext ctx) throws Exception { super.channelWritabilityChanged(ctx);