commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r156695 - in jakarta/commons/sandbox/benchmark/trunk/src: java/org/apache/commons/benchmark/Benchmark.java java/org/apache/commons/benchmark/BenchmarkTracker.java test/org/apache/commons/benchmark/Test1.java
Date Wed, 09 Mar 2005 22:01:34 GMT
Author: burton
Date: Wed Mar  9 14:01:29 2005
New Revision: 156695

URL: http://svn.apache.org/viewcvs?view=rev&rev=156695
Log:
We were ALWAYS resetting the last metric which was really stupid...

Modified:
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
    jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java

Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java?view=diff&r1=156694&r2=156695
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
Wed Mar  9 14:01:29 2005
@@ -157,7 +157,7 @@
      *
      */
     public BenchmarkTracker getTracker1() {
-        return tracker1.resetWhenNecessary();
+        return tracker1.rolloverWhenNecessary();
     }
 
     /**
@@ -165,7 +165,7 @@
      *
      */
     public BenchmarkTracker getTracker5() {
-        return tracker5.resetWhenNecessary();
+        return tracker5.rolloverWhenNecessary();
     }
 
     /**
@@ -173,7 +173,7 @@
      *
      */
     public BenchmarkTracker getTracker15() {
-        return tracker15.resetWhenNecessary();
+        return tracker15.rolloverWhenNecessary();
     }
 
     /**

Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java?view=diff&r1=156694&r2=156695
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
Wed Mar  9 14:01:29 2005
@@ -64,13 +64,18 @@
         this.parent = parent;
     }
 
-    BenchmarkTracker reset( long currentTimeMillis ) {
+    /**
+     * Do a physical rollover from now to -> last .
+     *
+     * @author <a href="mailto:burton@rojo.com">Kevin A. Burton</a>
+     */
+    BenchmarkTracker rollover( long currentTimeMillis ) {
 
         //need to perform a swap and save the current benchmark.
         last = now;
 
         //if we've slept for too long we have to start fresh
-        if ( currentTimeMillis - last.timestamp > interval ) {
+        if ( currentTimeMillis - last.timestamp > (interval*2) ) {
             last.reset();
         } 
 
@@ -86,15 +91,15 @@
     }
     
     /**
-     * Reset stats if necessary.
+     * Rollover stats if necessary.
      */
-    BenchmarkTracker resetWhenNecessary() {
+    BenchmarkTracker rolloverWhenNecessary() {
 
         long currentTimeMillis = System.currentTimeMillis();
 
         if ( currentTimeMillis - now.timestamp > interval ) {
-            
-            reset( currentTimeMillis );
+
+            rollover( currentTimeMillis );
             
         }
 
@@ -113,7 +118,7 @@
         //threads this is important.
         synchronized( MUTEX ) {
 
-            resetWhenNecessary();
+            rolloverWhenNecessary();
             ++now.started;
 
             doLocalStart();
@@ -129,7 +134,7 @@
 
         synchronized( MUTEX ) {
 
-            resetWhenNecessary();
+            rolloverWhenNecessary();
             ++now.completed;
 
             doLocalCompleted();

Modified: jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java?view=diff&r1=156694&r2=156695
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
Wed Mar  9 14:01:29 2005
@@ -40,6 +40,10 @@
      */
     public void testXmlrpc() throws Exception {
 
+        Benchmark.INTERVAL_1 =   1000;
+        Benchmark.INTERVAL_5 =   5000;
+        Benchmark.INTERVAL_15 = 15000;
+
         WebServer webserver = new WebServer ( 2048 );
 
         webserver.addHandler( "benchmark",
@@ -63,7 +67,12 @@
 
         assertEquals( 1, b.getTracker1().now.completed );
 
-        b.getTracker1().reset( System.currentTimeMillis() );
+        //this should sleep long enough to rollover interval1
+
+        System.out.println( "going to sleep" );
+        Thread.sleep( 1500 );
+
+        //b.getTracker1().reset( System.currentTimeMillis() );
 
         //FIXME: this isn't working.
         assertEquals( 0, b.getTracker1().now.completed );
@@ -249,7 +258,7 @@
         }
 
         //now call the tracker to force a reset
-        benchmark.getTracker().reset( System.currentTimeMillis() );
+        benchmark.getTracker().rollover( System.currentTimeMillis() );
 
         assertEquals( benchmark.getTracker1().getNow().getStarted(), 0 );
         assertEquals( benchmark.getTracker1().getNow().getCompleted(), 0 );
@@ -261,6 +270,19 @@
     
     public static void main(String args[]) {
 
+        try { 
+            
+            Test1 test = new Test1( null );
+            test.testXmlrpc();
+            
+        } catch ( Throwable t ) {
+            
+            t.printStackTrace();
+            
+        }
+
+        System.exit( 0 );
+        
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message