commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r640126 - in /commons/sandbox/performance/trunk/src: java/org/apache/commons/performance/pool/ test/org/apache/commons/performance/pool/
Date Sun, 23 Mar 2008 00:20:23 GMT
Author: psteitz
Date: Sat Mar 22 17:20:22 2008
New Revision: 640126

URL: http://svn.apache.org/viewvc?rev=640126&view=rev
Log:
Capture pool statistics using configurable sampling rate.

Modified:
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-abandoned.xml
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java?rev=640126&r1=640125&r2=640126&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
Sat Mar 22 17:20:22 2008
@@ -25,6 +25,7 @@
 import org.apache.commons.pool.KeyedObjectPool;
 import org.apache.commons.math.random.RandomData;
 import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
 import org.apache.commons.performance.ClientThread;
 import org.apache.commons.performance.Statistics;
 
@@ -40,7 +41,10 @@
     private KeyedObjectPool keyedPool;
     private boolean keyed;
     private List<Integer> keys;
-    private RandomData randomData;
+    private RandomData randomData = new RandomDataImpl();
+    private SummaryStatistics numActiveStats = new SummaryStatistics();
+    private SummaryStatistics numIdleStats = new SummaryStatistics();
+    private double samplingRate = 0;
      
     /**
      * Create a pool client thread for an ObjectPool.
@@ -61,13 +65,14 @@
     public PoolClientThread(long iterations, long minDelay, long maxDelay,
             double sigma, String delayType, long rampPeriod, long peakPeriod,
             long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, ObjectPool pool) {
+            Statistics stats, ObjectPool pool, double samplingRate) {
         
         super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
                 peakPeriod, troughPeriod, cycleType,rampType, logger, 
                 stats); 
         this.pool = pool;
         this.keyed = false;
+        this.samplingRate = samplingRate;
     }
     
     /**
@@ -89,7 +94,7 @@
     public PoolClientThread(long iterations, long minDelay, long maxDelay,
             double sigma, String delayType, long rampPeriod, long peakPeriod,
             long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, KeyedObjectPool keyedPool) {
+            Statistics stats, KeyedObjectPool keyedPool, double samplingRate) {
         
         super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
                 peakPeriod, troughPeriod, cycleType,rampType, logger, 
@@ -97,6 +102,7 @@
         
         this.keyedPool = keyedPool;
         this.keyed = true;
+        this.samplingRate = samplingRate;
         keys = new ArrayList<Integer>();
         for (int i = 0; i < 20; i++) { //TODO: make number of keys configurable
             keys.add(new Integer(i));
@@ -119,10 +125,23 @@
     }
     
     protected void cleanUp() throws Exception {
-         // Capture pool metrics here periodically
+        // Capture pool metrics 
+        if (randomData.nextUniform(0, 1) < samplingRate) {
+            if (keyed) {
+                numIdleStats.addValue(keyedPool.getNumIdle());
+                numActiveStats.addValue(keyedPool.getNumActive());
+            } else {
+                numIdleStats.addValue(pool.getNumIdle());
+                numActiveStats.addValue(pool.getNumActive());
+            }
+        }
     }
     
     protected void finalize() throws Exception {
-        // Add pool metrics statistics to stats
+        // Add pool metrics to stats
+        stats.addStatistics(
+                numIdleStats, Thread.currentThread().getName(), "numIdle");
+        stats.addStatistics(
+                numActiveStats, Thread.currentThread().getName(), "numActive");
     }
 }

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java?rev=640126&r1=640125&r2=640126&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
Sat Mar 22 17:20:22 2008
@@ -65,6 +65,7 @@
     private boolean testWhileIdle;
     private AbandonedConfig abandonedConfig = new AbandonedConfig();
     private boolean lifo;
+    private double samplingRate;
     
     // WaiterFactory properties
     private long activateLatency;
@@ -95,7 +96,7 @@
         digester.addCallParam(
                 "configuration/factory/waiter-latency", 5);   
         digester.addCallMethod("configuration/pool", 
-                "configurePool", 14);
+                "configurePool", 15);
         digester.addCallParam(
                 "configuration/pool/max-active", 0);
         digester.addCallParam(
@@ -124,6 +125,8 @@
                 "configuration/pool/lifo", 12);
         digester.addCallParam(
                 "configuration/pool/type", 13);
+        digester.addCallParam(
+                "configuration/pool/sampling-rate", 14);
         digester.addCallMethod("configuration/abandoned-config",
                 "configureAbandonedConfig", 3);
         digester.addCallParam(
@@ -241,31 +244,32 @@
         if (poolType.equals("GenericObjectPool")) {
             return new PoolClientThread(iterations, minDelay, maxDelay,
                     sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats, genericObjectPool);
+                    cycleType, rampType, logger, stats, genericObjectPool, 
+                    samplingRate);
         }
         if (poolType.equals("GenericKeyedObjectPool")) {
             return new PoolClientThread(iterations, minDelay, maxDelay,
                     sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
                     cycleType, rampType, logger, stats,
-                    genericKeyedObjectPool);
+                    genericKeyedObjectPool, samplingRate);
         }
         if (poolType.equals("StackKeyedObjectPool")) {
             return new PoolClientThread(iterations, minDelay, maxDelay,
                     sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
                     cycleType, rampType, logger, stats,
-                    stackKeyedObjectPool);
+                    stackKeyedObjectPool, samplingRate);
         }
         if (poolType.equals("StackObjectPool")) {
             return new PoolClientThread(iterations, minDelay, maxDelay,
                     sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
                     cycleType, rampType, logger, stats,
-                    stackObjectPool);
+                    stackObjectPool, samplingRate);
         }
         if (poolType.equals("SoftReferenceObjectPool")) {
             return new PoolClientThread(iterations, minDelay, maxDelay,
                     sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
                     cycleType, rampType, logger, stats,
-                    softReferenceObjectPool);
+                    softReferenceObjectPool, samplingRate);
         }
         return null;
     }
@@ -291,7 +295,7 @@
             String exhaustedAction, String testOnBorrow,
             String testOnReturn, String timeBetweenEvictions,
             String testsPerEviction, String idleTimeout, 
-            String testWhileIdle, String lifo, String type)
+            String testWhileIdle, String lifo, String type, String samplingRate)
         throws ConfigurationException { 
         this.maxActive = Integer.parseInt(maxActive);
         this.maxActivePerKey = Integer.parseInt(maxActivePerKey);
@@ -316,7 +320,8 @@
             throw new ConfigurationException(
             "Bad configuration setting for exhausted action: "
                     + exhaustedAction); 
-        }           
+        }  
+        this.samplingRate = Double.parseDouble(samplingRate);
     }
     
     public void configureAbandonedConfig(String logAbandoned,

Modified: commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-abandoned.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-abandoned.xml?rev=640126&r1=640125&r2=640126&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-abandoned.xml
(original)
+++ commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-abandoned.xml
Sat Mar 22 17:20:22 2008
@@ -48,6 +48,7 @@
     <lifo>false</lifo>
     <!-- Ignored unless pool type a KeyedObjectPool -->
     <max-active-per-key>10</max-active-per-key>
+    <sampling-rate>0.1</sampling-rate>
   </pool>
   
   <!-- Ignored unless pool type is AbandonedObjectPool -->

Modified: commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml?rev=640126&r1=640125&r2=640126&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml
(original)
+++ commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml
Sat Mar 22 17:20:22 2008
@@ -48,6 +48,7 @@
     <lifo>false</lifo>
     <!-- Ignored unless pool type a KeyedObjectPool -->
     <max-active-per-key>10</max-active-per-key>
+    <sampling-rate>0.1</sampling-rate>
   </pool>
   
   <!-- Ignored unless pool type is AbandonedObjectPool -->



Mime
View raw message