jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1221486 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/math/ test/src/org/apache/jorphan/math/ xdocs/
Date Tue, 20 Dec 2011 20:50:29 GMT
Author: sebb
Date: Tue Dec 20 20:50:28 2011
New Revision: 1221486

URL: http://svn.apache.org/viewvc?rev=1221486&view=rev
Log:
Bug 52339 - JMeter Statistical mode in distributed testing shows wrong response time<

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java
    jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java?rev=1221486&r1=1221485&r2=1221486&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java Tue Dec 20 20:50:28
2011
@@ -95,7 +95,7 @@ public abstract class StatCalculator<T e
 
     public void addAll(StatCalculator<T> calc) {
         for(Entry<T, MutableLong> ent : calc.valuesMap.entrySet()) {
-            addValue(ent.getKey(), ent.getValue().longValue());
+            addEachValue(ent.getKey(), ent.getValue().longValue());
         }
     }
 
@@ -197,23 +197,64 @@ public abstract class StatCalculator<T e
 
     protected abstract T divide(T val, int n);
 
-    public void addValue(T val, long sampleCount) {
+    protected abstract T divide(T val, long n);
+
+    /**
+     * Update the calculator with the values for a set of samples.
+     * 
+     * @param val the common value, normally the elapsed time
+     * @param sampleCount the number of samples with the same value
+     */
+    void addEachValue(T val, long sampleCount) {
         count += sampleCount;
         double currentVal = val.doubleValue();
-        sum += currentVal * sampleCount; 
+        sum += currentVal * sampleCount;
         // For n same values in sum of square is equal to n*val^2
         sumOfSquares += currentVal * currentVal * sampleCount;
         updateValueCount(val, sampleCount);
+        calculateDerivedValues(val);
+    }
+
+    /**
+     * Update the calculator with the value for an aggregated sample.
+     * 
+     * @param val the aggregate value, normally the elapsed time
+     * @param sampleCount the number of samples contributing to the aggregate value
+     */
+    public void addValue(T val, long sampleCount) {
+        count += sampleCount;
+        double currentVal = val.doubleValue();
+        sum += currentVal;
+        T actualValue = val;
+        if (sampleCount > 1){
+            // For n values in an aggregate sample the average value = (val/n)
+            // So need to add n * (val/n) * (val/n) = val * val / n
+            sumOfSquares += currentVal * currentVal / sampleCount;
+            actualValue = divide(val, sampleCount);
+        } else { // no need to divide by 1
+            sumOfSquares += currentVal * currentVal;
+        }
+        updateValueCount(actualValue, sampleCount);
+        calculateDerivedValues(actualValue);
+    }
+
+    private void calculateDerivedValues(T actualValue) {
         mean = sum / count;
         deviation = Math.sqrt((sumOfSquares / count) - (mean * mean));
-        if (val.compareTo(max) > 0){
-            max=val;
+        if (actualValue.compareTo(max) > 0){
+            max=actualValue;
         }
-        if (val.compareTo(min) < 0){
-            min=val;
+        if (actualValue.compareTo(min) < 0){
+            min=actualValue;
         }
     }
 
+    /**
+     * Add a single value (normally elapsed time)
+     * 
+     * @param val the value to add, which should correspond with a single sample
+     * @ss {@link #addValue(Number, long)}
+     */
     public void addValue(T val) {
         addValue(val, 1L);
     }

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java?rev=1221486&r1=1221485&r2=1221486&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java Tue Dec 20
20:50:28 2011
@@ -31,6 +31,12 @@ public class StatCalculatorInteger exten
         super.addValue(Integer.valueOf(val));
     }
 
+    /**
+     * Update the calculator with the value for an aggregated sample.
+     * 
+     * @param val the aggregate value
+     * @param sampleCount the number of samples contributing to the aggregate value
+     */
     public void addValue(int val, int sampleCount){
         super.addValue(Integer.valueOf(val), sampleCount);
     }
@@ -39,4 +45,9 @@ public class StatCalculatorInteger exten
     protected Integer divide(Integer val, int n) {
         return Integer.valueOf(val.intValue() / n);
     }
+
+    @Override
+    protected Integer divide(Integer val, long n) {
+        return Integer.valueOf((int) (val.intValue() / n));
+    }
 }

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java?rev=1221486&r1=1221485&r2=1221486&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java Tue Dec 20 20:50:28
2011
@@ -27,10 +27,21 @@ public class StatCalculatorLong extends 
         super(Long.valueOf(0L), Long.valueOf(Long.MIN_VALUE), Long.valueOf(Long.MAX_VALUE));
     }
 
+    /**
+     * Add a single value (normally elapsed time)
+     * 
+     * @param val the value to add, which should correspond with a single sample
+     */
     public void addValue(long val){
         super.addValue(Long.valueOf(val));
     }
 
+    /**
+     * Update the calculator with the value for an aggregated sample.
+     * 
+     * @param val the aggregate value, normally the elapsed time
+     * @param sampleCount the number of samples contributing to the aggregate value
+     */
     public void addValue(long val, int sampleCount){
         super.addValue(Long.valueOf(val), sampleCount);
     }
@@ -39,4 +50,9 @@ public class StatCalculatorLong extends 
     protected Long divide(Long val, int n) {
         return Long.valueOf(val.longValue() / n);
     }
+
+    @Override
+    protected Long divide(Long val, long n) {
+        return Long.valueOf(val.longValue() / n);
+    }
 }

Modified: jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java?rev=1221486&r1=1221485&r2=1221486&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java (original)
+++ jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java Tue Dec 20 20:50:28
2011
@@ -120,7 +120,18 @@ public class TestStatCalculator extends 
         calc.addValue(1L);
         calc.addValue(2L);
         calc.addValue(3L);
-        calc.addValue(2L, 3);
+        calc.addEachValue(2L, 3);
+        assertEquals(6, calc.getCount());
+        assertEquals(12.0, calc.getSum());
+        assertEquals(0.5773502691896255, calc.getStandardDeviation());
+    }
+
+    @SuppressWarnings("boxing")
+    public void testBug52125_2A(){ // as above, but with aggregate sample instead
+        calc.addValue(1L);
+        calc.addValue(2L);
+        calc.addValue(3L);
+        calc.addValue(6L, 3);
         assertEquals(6, calc.getCount());
         assertEquals(12.0, calc.getSum());
         assertEquals(0.5773502691896255, calc.getStandardDeviation());

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1221486&r1=1221485&r2=1221486&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Dec 20 20:50:28 2011
@@ -148,6 +148,7 @@ This behaviour can be changed with prope
 <li>Bug 51733 - SyncTimer is messed up if you a interrupt a test plan</li>
 <li>Bug 52118 - New toolbar : shutdown and stop buttons not disabled when no test is
running</li>
 <li>Bug 52125 - StatCalculator.addAll(StatCalculator calc) joins incorrect if there
are more samples with the same response time in one of the TreeMap</li>
+<li>Bug 52339 - JMeter Statistical mode in distributed testing shows wrong response
time</li>
 <li>Bug 52215 - Confusing synchronization in StatVisualizer, SummaryReport ,Summariser
and issue in StatGraphVisualizer</li>
 <li>Bug 52216 - TableVisualizer : currentData field is badly synchronized</li>
 <li>Bug 52217 - ViewResultsFullVisualizer : Synchronization issues on root and treeModel</li>



Mime
View raw message