Tune write low/highwatermark 44/22044/3
authorRobert Varga <rovarga@cisco.com>
Sun, 7 Jun 2015 00:23:41 +0000 (02:23 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 9 Jun 2015 13:31:18 +0000 (15:31 +0200)
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 <rovarga@cisco.com>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java

index b3b7b8c384b49af1a09ec2e56a214a8ba6c37d8a..66fa8a60ca799fe9772bfd5db0e65bceb0f43382 100644 (file)
@@ -43,6 +43,19 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> 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<OutboundQueueImpl> activeQueues = new LinkedList<>();
     private final AtomicBoolean flushScheduled = new AtomicBoolean();
     private final ConnectionAdapterImpl parent;
@@ -317,7 +330,9 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> 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<T extends OutboundQueueHandler> 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);