commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1595711 - in /commons/proper/pool/trunk/src: changes/ main/java/org/apache/commons/pool2/impl/ test/java/org/apache/commons/pool2/impl/
Date Mon, 19 May 2014 01:15:23 GMT
Author: psteitz
Date: Mon May 19 01:15:23 2014
New Revision: 1595711

URL: http://svn.apache.org/r1595711
Log:
Made wait time stats accurate when pool is configured to block indefinitely. JIRA: POOL-259.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1595711&r1=1595710&r2=1595711&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Mon May 19 01:15:23 2014
@@ -49,6 +49,11 @@ The <action> type attribute can be add,u
       Improve performance of statistics collection for pools that extend
       BaseGenericObjectPool.
     </action>
+    <action dev="psteitz" type="fix" issue="POOL-259">
+      Made client wait time statistics accurate when pools are configured to
+      block indefinitely.  Also modified computation to include latency clients
+      experience due to waiting on factory methods.
+    </action>
   </release>
   <release version="2.2" date="2014-02-24" description=
 "This is a maintenance release that adds a new testOnCreate configuration option

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1595711&r1=1595710&r2=1595711&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Mon May 19 01:15:23 2014
@@ -343,7 +343,7 @@ public class GenericKeyedObjectPool<K,T>
         boolean blockWhenExhausted = getBlockWhenExhausted();
 
         boolean create;
-        long waitTime = 0;
+        long waitTime = System.currentTimeMillis();
         ObjectDeque<T> objectDeque = register(key);
 
         try {
@@ -359,10 +359,8 @@ public class GenericKeyedObjectPool<K,T>
                         if (borrowMaxWaitMillis < 0) {
                             p = objectDeque.getIdleObjects().takeFirst();
                         } else {
-                            waitTime = System.currentTimeMillis();
                             p = objectDeque.getIdleObjects().pollFirst(
                                     borrowMaxWaitMillis, TimeUnit.MILLISECONDS);
-                            waitTime = System.currentTimeMillis() - waitTime;
                         }
                     }
                     if (p == null) {
@@ -434,7 +432,7 @@ public class GenericKeyedObjectPool<K,T>
             deregister(key);
         }
 
-        updateStatsBorrow(p, waitTime);
+        updateStatsBorrow(p, System.currentTimeMillis() - waitTime);
 
         return p.getObject();
     }

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1595711&r1=1595710&r2=1595711&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Mon May 19 01:15:23 2014
@@ -423,7 +423,7 @@ public class GenericObjectPool<T> extend
         boolean blockWhenExhausted = getBlockWhenExhausted();
 
         boolean create;
-        long waitTime = 0;
+        long waitTime = System.currentTimeMillis();
 
         while (p == null) {
             create = false;
@@ -437,10 +437,8 @@ public class GenericObjectPool<T> extend
                     if (borrowMaxWaitMillis < 0) {
                         p = idleObjects.takeFirst();
                     } else {
-                        waitTime = System.currentTimeMillis();
                         p = idleObjects.pollFirst(borrowMaxWaitMillis,
                                 TimeUnit.MILLISECONDS);
-                        waitTime = System.currentTimeMillis() - waitTime;
                     }
                 }
                 if (p == null) {
@@ -509,7 +507,7 @@ public class GenericObjectPool<T> extend
             }
         }
 
-        updateStatsBorrow(p, waitTime);
+        updateStatsBorrow(p, System.currentTimeMillis() - waitTime);
 
         return p.getObject();
     }

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1595711&r1=1595710&r2=1595711&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Mon May 19 01:15:23 2014
@@ -1484,6 +1484,26 @@ public class TestGenericKeyedObjectPool 
         }
         Assert.assertEquals(nIterations, pool.getDestroyedCount());
     }
+    
+    // POOL-259
+    @Test
+    public void testClientWaitStats() throws Exception {
+        SimpleFactory<String> factory = new SimpleFactory<String>();
+        // Give makeObject a little latency
+        factory.setMakeLatency(100);
+        final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<String,
String>(
+                factory, new GenericKeyedObjectPoolConfig());
+        String s = pool.borrowObject("one");
+        // First borrow waits on create, so wait time should be at least 100 ms
+        Assert.assertTrue(pool.getMaxBorrowWaitTimeMillis() >= 100);
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() >= 100);
+        pool.returnObject("one", s);
+        pool.borrowObject("one");
+        // Second borrow does not have to wait on create, average should be about 50
+        Assert.assertTrue(pool.getMaxBorrowWaitTimeMillis() >= 100);
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() < 60);  
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() > 40);  
+    }
 
     /**
      * Attempts to invalidate an object, swallowing IllegalStateException.
@@ -1663,6 +1683,7 @@ public class TestGenericKeyedObjectPool 
             if (exceptionOnCreate) {
                 throw new Exception();
             }
+            doWait(makeLatency);
             String out = null;
             synchronized(this) {
                 activeCount++;
@@ -1713,6 +1734,9 @@ public class TestGenericKeyedObjectPool 
         public void setDestroyLatency(long destroyLatency) {
             this.destroyLatency = destroyLatency;
         }
+        public void setMakeLatency(long makeLatency) {
+            this.makeLatency = makeLatency;
+        }
         public void setValidationEnabled(boolean b) {
             enableValidation = b;
         }
@@ -1745,6 +1769,7 @@ public class TestGenericKeyedObjectPool 
         boolean oddValid = true;
         boolean enableValidation = false;
         long destroyLatency = 0;
+        long makeLatency = 0;
         volatile int maxTotalPerKey = Integer.MAX_VALUE;
         boolean exceptionOnPassivate = false;
         boolean exceptionOnActivate = false;

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1595711&r1=1595710&r2=1595711&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
Mon May 19 01:15:23 2014
@@ -2274,6 +2274,26 @@ public class TestGenericObjectPool exten
         Assert.assertEquals(0, pool.getNumActive());
         Assert.assertEquals(1, pool.getNumIdle());
     }
+    
+    // POOL-259
+    @Test
+    public void testClientWaitStats() throws Exception {
+        SimpleFactory factory = new SimpleFactory();
+        // Give makeObject a little latency
+        factory.setMakeLatency(100);
+        final GenericObjectPool<String> pool = new GenericObjectPool<String>(
+                factory, new GenericObjectPoolConfig());
+        String s = pool.borrowObject();
+        // First borrow waits on create, so wait time should be at least 100 ms
+        Assert.assertTrue(pool.getMaxBorrowWaitTimeMillis() >= 100);
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() >= 100);
+        pool.returnObject(s);
+        pool.borrowObject();
+        // Second borrow does not have to wait on create, average should be about 50
+        Assert.assertTrue(pool.getMaxBorrowWaitTimeMillis() >= 100);
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() < 60);  
+        Assert.assertTrue(pool.getMeanBorrowWaitTimeMillis() > 40);  
+    }
 
     private static final class DummyFactory
             extends BasePooledObjectFactory<Object> {



Mime
View raw message