From 1ef2ed07ea9d7d42963b8b2ce5e99004f6c33274 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 20 May 2015 17:53:21 +0200 Subject: [PATCH] Allow DOMNotificationRouter to be tuneable The details of how deep is the queue and how the backoff strategy is applied should be tuneable. Model them and provide the hooks. Change-Id: I6eda6bebc2cf506d627e09d3949a73e97ed866e4 Signed-off-by: Robert Varga --- .../src/main/resources/initial/01-md-sal.xml | 3 +++ .../md/sal/dom/impl/DomBrokerImplModule.java | 15 ++++++------ .../broker/impl/DOMNotificationRouter.java | 22 ++++++++++------- .../yang/opendaylight-dom-broker-impl.yang | 24 +++++++++++++++++++ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml b/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml index 0176523b86..3d66a79d7b 100644 --- a/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml +++ b/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml @@ -167,6 +167,9 @@ dom:dom-async-data-broker inmemory-data-broker + 65536 + 1 + 30 prefix:binding-data-compatible-broker diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java index 35c22a1bee..fbae80b1f9 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java @@ -7,8 +7,10 @@ */ package org.opendaylight.controller.config.yang.md.sal.dom.impl; +import com.google.common.base.Preconditions; import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.MutableClassToInstanceMap; +import java.util.concurrent.TimeUnit; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; @@ -23,9 +25,6 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.controller.sal.dom.broker.BrokerImpl; import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl; -/** -* -*/ public final class DomBrokerImplModule extends org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomBrokerImplModule { @@ -38,8 +37,10 @@ public final class DomBrokerImplModule extends org.opendaylight.controller.confi } @Override - public void validate(){ + public void validate() { super.validate(); + final long depth = getNotificationQueueDepth().getValue(); + Preconditions.checkArgument(Long.lowestOneBit(depth) == Long.highestOneBit(depth), "Queue depth %s is not power-of-two", depth); } @Override @@ -48,10 +49,8 @@ public final class DomBrokerImplModule extends org.opendaylight.controller.confi final ClassToInstanceMap services = MutableClassToInstanceMap.create(); - // TODO: retrieve from config subsystem - final int queueDepth = 1024; - - final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(queueDepth); + final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(getNotificationQueueDepth().getValue().intValue(), + getNotificationQueueSpin().longValue(), getNotificationQueuePark().longValue(), TimeUnit.MILLISECONDS); services.putInstance(DOMNotificationService.class, domNotificationRouter); services.putInstance(DOMNotificationPublishService.class, domNotificationRouter); diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouter.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouter.java index d623c3ec96..138de6b770 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouter.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouter.java @@ -81,21 +81,27 @@ public final class DOMNotificationRouter implements AutoCloseable, DOMNotificati private volatile Multimap> listeners = ImmutableMultimap.of(); private final ListenerRegistry subscriptionListeners = ListenerRegistry.create(); - private DOMNotificationRouter(final ExecutorService executor, final Disruptor disruptor) { + @SuppressWarnings("unchecked") + private DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) { this.executor = Preconditions.checkNotNull(executor); - this.disruptor = Preconditions.checkNotNull(disruptor); + + disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY, queueDepth, executor, ProducerType.MULTI, strategy); + disruptor.handleEventsWith(DISPATCH_NOTIFICATIONS); + disruptor.after(DISPATCH_NOTIFICATIONS).handleEventsWith(NOTIFY_FUTURE); + disruptor.start(); } - @SuppressWarnings("unchecked") public static DOMNotificationRouter create(final int queueDepth) { final ExecutorService executor = Executors.newCachedThreadPool(); - final Disruptor disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY, queueDepth, executor, ProducerType.MULTI, DEFAULT_STRATEGY); - disruptor.handleEventsWith(DISPATCH_NOTIFICATIONS); - disruptor.after(DISPATCH_NOTIFICATIONS).handleEventsWith(NOTIFY_FUTURE); - disruptor.start(); + return new DOMNotificationRouter(executor, queueDepth, DEFAULT_STRATEGY); + } + + public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime, final TimeUnit unit) { + final ExecutorService executor = Executors.newCachedThreadPool(); + final WaitStrategy strategy = PhasedBackoffWaitStrategy.withLock(spinTime, parkTime, unit); - return new DOMNotificationRouter(executor, disruptor); + return new DOMNotificationRouter(executor, queueDepth, strategy); } @Override diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/yang/opendaylight-dom-broker-impl.yang b/opendaylight/md-sal/sal-dom-broker/src/main/yang/opendaylight-dom-broker-impl.yang index f06ff62722..7655a921ec 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/yang/opendaylight-dom-broker-impl.yang +++ b/opendaylight/md-sal/sal-dom-broker/src/main/yang/opendaylight-dom-broker-impl.yang @@ -40,6 +40,12 @@ module opendaylight-sal-dom-broker-impl { config:java-name-prefix SchemaServiceImplSingleton; } + typedef max-queue-depth { + type uint32 { + range 1..1073741824; + } + } + augment "/config:modules/config:module/config:configuration" { case dom-broker-impl { when "/config:modules/config:module/config:type = 'dom-broker-impl'"; @@ -61,6 +67,24 @@ module opendaylight-sal-dom-broker-impl { } } } + + leaf notification-queue-depth { + description "Maximum number of elements in the notification queue, must be power-of-two."; + type max-queue-depth; + default 65536; + } + leaf notification-queue-spin { + description "Number of milliseconds notification queue should spin for new requests before parking."; + type uint16; + units milliseconds; + default 1; + } + leaf notification-queue-park { + description "Number of milliseconds notification queue should park for new requests before blocking."; + type uint16; + units milliseconds; + default 30; + } } } -- 2.36.6