Author: challngr Date: Thu Jun 20 19:32:58 2013 New Revision: 1495143 URL: http://svn.apache.org/r1495143 Log: UIMA-3011 Set "health" indicator for UIMA-AS service based on queue depth.
Modified: uima/sandbox/uima-ducc/trunk/src/main/resources/ducc.properties uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/UimaAsServiceMonitor.java uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/UimaAsPing.java Modified: uima/sandbox/uima-ducc/trunk/src/main/resources/ducc.properties URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/resources/ducc.properties?rev=1495143&r1=1495142&r2=1495143&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/src/main/resources/ducc.properties (original) +++ uima/sandbox/uima-ducc/trunk/src/main/resources/ducc.properties Thu Jun 20 19:32:58 2013 @@ -151,6 +151,7 @@ ducc.sm.instance.falure.max = 5 ducc.sm.http.port=19989 ducc.sm.http.node=${ducc.head} ducc.sm.default.linger=300000 +ducc.sm.max.queue.depth = 0 # === END == Service Manager Configuration block ========== # ========== Orchestrator Configuration block ========== Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/UimaAsServiceMonitor.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/UimaAsServiceMonitor.java?rev=1495143&r1=1495142&r2=1495143&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/UimaAsServiceMonitor.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/UimaAsServiceMonitor.java Thu Jun 20 19:32:58 2013 @@ -60,6 +60,10 @@ public class UimaAsServiceMonitor boolean healthy = false; + public long getQueueSize() + { + return queueSize; + } public UimaAsServiceMonitor(String qname, String broker_host, int broker_port) { @@ -70,20 +74,20 @@ public class UimaAsServiceMonitor } - public ServiceStatistics getStatistics() - { - try { - collect(); - qstats.setAlive(true); // if we don't croak gathering stuff, we're not dead - qstats.setHealthy(true); - qstats.setInfo(format()); - } catch ( Throwable t ) { - qstats.setAlive(false); // if we don't croak gathering stuff, we're not dead - qstats.setHealthy(false); - qstats.setInfo(t.getMessage()); - } - return qstats; - } +// public ServiceStatistics getStatistics() +// { +// try { +// collect(); +// qstats.setAlive(true); // if we don't croak gathering stuff, we're not dead +// qstats.setHealthy(true); +// qstats.setInfo(format()); +// } catch ( Throwable t ) { +// qstats.setAlive(false); // if we don't croak gathering stuff, we're not dead +// qstats.setHealthy(false); +// qstats.setInfo(t.getMessage()); +// } +// return qstats; +// } /** * Connect to ActiveMq and find the mbean for the queue we're trying to monitor @@ -156,7 +160,22 @@ public class UimaAsServiceMonitor } } - private String format() + public ServiceStatistics getStatistics() + { + try { + collect(); + qstats.setAlive(true); // if we don't croak gathering stuff, we're not dead + qstats.setHealthy(true); + qstats.setInfo(format()); + } catch ( Throwable t ) { + qstats.setAlive(false); // if we don't croak gathering stuff, we're not dead + qstats.setHealthy(false); + qstats.setInfo(t.getMessage()); + } + return qstats; + } + + public String format() { return "AveNQ[" + new DecimalFormat("####.##").format(enqueueTime) + "] Consum[" + consumerCount @@ -174,7 +193,7 @@ public class UimaAsServiceMonitor } - private void collect() + public void collect() throws Throwable { // String methodName = "collect"; Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/UimaAsPing.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/UimaAsPing.java?rev=1495143&r1=1495142&r2=1495143&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/UimaAsPing.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/UimaAsPing.java Thu Jun 20 19:32:58 2013 @@ -20,6 +20,8 @@ import org.apache.uima.util.Level; public class UimaAsPing extends AServicePing { + static final int QUEUE_SIZE_WINDOW = 3; + int queue_threshold = 0; String ep; @@ -32,7 +34,10 @@ public class UimaAsPing boolean connected; UimaAsServiceMonitor monitor; DuccLogger logger = null; - + + int[] queueSizeWindow = new int[QUEUE_SIZE_WINDOW]; + int queueCursor = 0; + UimaAsPing() { this.logger = null; @@ -75,6 +80,8 @@ public class UimaAsPing broker_jmx_port = SystemPropertyResolver.getIntProperty("ducc.sm.meta.jmx.port", 1099); this.monitor = new UimaAsServiceMonitor(endpoint, broker_host, broker_jmx_port); + queue_threshold = SystemPropertyResolver.getIntProperty("ducc.sm.max.queue.depth", 500); + //UIMAFramework.getLogger(BaseUIMAAsynchronousEngineCommon_impl.class).setLevel(Level.OFF); //UIMAFramework.getLogger(BaseUIMAAsynchronousEngine_impl.class).setLevel(Level.OFF); // there are a couple junky messages that slip by the above configurations. turn the whole danged thing off. @@ -96,6 +103,36 @@ public class UimaAsPing } } + void evaluatePing(UimaAsServiceMonitor mon, ServiceStatistics stats) + { + String methodName = "evaluatePing"; + try { + mon.collect(); + + if ( queue_threshold > 0 ) { // only do this if a threshold is set + // if the last 'n' q depths are > threshold, mark the service unhealthy + // primitive, but maybe an OK first guess + queueSizeWindow[queueCursor++ % QUEUE_SIZE_WINDOW] = (int)monitor.getQueueSize(); + int sum = 0; + for ( int i = 0; i < QUEUE_SIZE_WINDOW; i++ ) { + sum += queueSizeWindow[i]; + } + sum = sum / QUEUE_SIZE_WINDOW; + stats.setHealthy( sum < queue_threshold ? true : false); + // logger.debug(methodName, null, "EVAL: Q depth", monitor.getQueueSize(), "window", sum, "health", stats.isHealthy()); + } else { + stats.setHealthy(true); + } + + stats.setAlive(true); + stats.setInfo(monitor.format()); + } catch ( Throwable t ) { + stats.setAlive(false); + stats.setHealthy(false); + stats.setInfo(t.getMessage()); + } + } + public ServiceStatistics getStatistics() { String methodName = "getStatistics"; @@ -110,12 +147,10 @@ public class UimaAsPing try { // this sends GetMeta request and blocks waiting for a reply - statistics = monitor.getStatistics(); uimaAsEngine.initialize(appCtx); + evaluatePing(monitor, statistics); // if we get here, the get-meta worked well enough statistics.setAlive(true); - statistics.setHealthy(true); - // System.out.println("getMeta ok: " + ep); } catch( ResourceInitializationException e) { doLog(methodName, "Cannot issue getMeta to: " + endpoint + ":" + broker);