incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1242388 - in /sling/trunk/bundles/engine/src: main/java/org/apache/sling/engine/impl/ test/java/org/apache/sling/engine/impl/
Date Thu, 09 Feb 2012 16:40:29 GMT
Author: justin
Date: Thu Feb  9 16:40:29 2012
New Revision: 1242388

URL: http://svn.apache.org/viewvc?rev=1242388&view=rev
Log:
SLING-2413 - internal refactoring; also fixing a divide by zero issue.

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
    sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java?rev=1242388&r1=1242387&r2=1242388&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
Thu Feb  9 16:40:29 2012
@@ -31,34 +31,34 @@ class RequestProcessorMBeanImpl extends 
     private volatile long n;
 
     // shortest request
-    private volatile long min;
+    private volatile long durationMsecMin;
 
     // longest request
-    private volatile long max;
+    private volatile long durationMsecMax;
 
     // sum of request durations
-    private volatile double sumX;
+    private volatile double durationMsecSumX;
 
     // sum of squared request durations
-    private volatile double sumX2;
+    private volatile double durationMsecSumX2;
 
     RequestProcessorMBeanImpl() throws NotCompliantMBeanException {
         super(RequestProcessorMBean.class);
         resetStatistics();
     }
 
-    synchronized void addRequestDuration(final long value) {
+    synchronized void addRequestData(final long duration) {
         this.n++;
 
-        if (value < this.min) {
-            this.min = value;
+        if (duration < this.durationMsecMin) {
+            this.durationMsecMin = duration;
         }
-        if (value > this.max) {
-            this.max = value;
+        if (duration > this.durationMsecMax) {
+            this.durationMsecMax = duration;
         }
 
-        this.sumX += value;
-        this.sumX2 += (value * value);
+        this.durationMsecSumX += duration;
+        this.durationMsecSumX2 += (duration * duration);
     }
 
     public long getRequestsCount() {
@@ -66,11 +66,11 @@ class RequestProcessorMBeanImpl extends 
     }
 
     public long getMinRequestDurationMsec() {
-        return this.min;
+        return this.durationMsecMin;
     }
 
     public long getMaxRequestDurationMsec() {
-        return this.max;
+        return this.durationMsecMax;
     }
 
     public synchronized double getStandardDeviationDurationMsec() {
@@ -78,7 +78,7 @@ class RequestProcessorMBeanImpl extends 
             // algorithm taken from
             // http://de.wikipedia.org/wiki/Standardabweichung section
             // "Berechnung für auflaufende Messwerte"
-            return Math.sqrt((this.sumX2 - this.sumX * this.sumX / this.n) / (this.n - 1));
+            return Math.sqrt((this.durationMsecSumX2 - this.durationMsecSumX * this.durationMsecSumX
/ this.n) / (this.n - 1));
         }
 
         // single data point has no deviation
@@ -86,12 +86,16 @@ class RequestProcessorMBeanImpl extends 
     }
 
     public synchronized double getMeanRequestDurationMsec() {
-        return this.sumX / this.n;
+        if (this.n > 1) {
+            return this.durationMsecSumX / this.n;
+        } else {
+            return 0;
+        }
     }
 
     public synchronized void resetStatistics() {
-        this.min = Long.MAX_VALUE;
-        this.max = 0;
+        this.durationMsecMin = Long.MAX_VALUE;
+        this.durationMsecMax = 0;
         this.n = 0;
     }
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java?rev=1242388&r1=1242387&r2=1242388&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
Thu Feb  9 16:40:29 2012
@@ -225,7 +225,7 @@ public class SlingRequestProcessorImpl i
         } finally {
             long elapsed = System.currentTimeMillis() - startTimestamp;
             if (mbean != null) {
-                mbean.addRequestDuration(elapsed);
+                mbean.addRequestData(elapsed);
             }
         }
     }

Modified: sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java?rev=1242388&r1=1242387&r2=1242388&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
(original)
+++ sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
Thu Feb  9 16:40:29 2012
@@ -39,6 +39,12 @@ public class RequestProcessorMBeanImplTe
         final SummaryStatistics mathStats = new SummaryStatistics();
         final RequestProcessorMBeanImpl bean = new RequestProcessorMBeanImpl();
 
+        assertEquals(0l, bean.getRequestsCount());
+        assertEquals(Long.MAX_VALUE, bean.getMinRequestDurationMsec());
+        assertEquals(0l, bean.getMaxRequestDurationMsec());
+        assertEquals(0.0, bean.getMeanRequestDurationMsec());
+        assertEquals(0.0, bean.getStandardDeviationDurationMsec());
+
         final Random random = new Random(System.currentTimeMillis() / 17);
         final int num = 10000;
         final int min = 85;
@@ -46,7 +52,7 @@ public class RequestProcessorMBeanImplTe
         for (int i = 0; i < num; i++) {
             final long value = min + random.nextInt(max - min);
             mathStats.addValue(value);
-            bean.addRequestDuration(value);
+            bean.addRequestData(value);
         }
 
         TestCase.assertEquals("Number of points must be the same", mathStats.getN(), bean.getRequestsCount());



Mime
View raw message