geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r356367 - in /geronimo/trunk/modules/connector/src: java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
Date Mon, 12 Dec 2005 20:23:21 GMT
Author: djencks
Date: Mon Dec 12 12:23:13 2005
New Revision: 356367

URL: http://svn.apache.org/viewcvs?rev=356367&view=rev
Log:
GERONIMO-1345 Improve pool resize calculations, with tests

Added:
    geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
  (with props)
Modified:
    geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java

Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java?rev=356367&r1=356366&r2=356367&view=diff
==============================================================================
--- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
(original)
+++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
Mon Dec 12 12:23:13 2005
@@ -99,8 +99,7 @@
         if (destroyed) {
             try {
                 connectionInfo.getManagedConnectionInfo().getManagedConnection().destroy();
-            }
-            catch (ResourceException re) {
+            } catch (ResourceException re) {
             }
             return;
         }
@@ -153,40 +152,70 @@
         if (newMaxSize != getPartitionMaxSize()) {
             resizeLock.writeLock().acquire();
             try {
-                //example: old maxsize 40, permits 20, connection count 20
-                //new maxSize 10
-                //shrinkLater is 10
-                //shrinkNow is 20
-                //2nd example: old maxsize 30, permits 10, connection count 10
-                //new maxSize 40
-                //shrinkLater and shrinkNow are 0.
-                int checkedOut = this.maxSize - (int) permits.permits();
-                shrinkLater = checkedOut - newMaxSize;
-                if (shrinkLater < 0) {
-                    shrinkLater = 0;
-                }
-                int shrinkNow = checkedOut + connectionCount - newMaxSize - shrinkLater;
-                if (shrinkNow < 0) {
-                    shrinkNow = 0;
-                }
+                ResizeInfo resizeInfo = new ResizeInfo(this.minSize, (int)permits.permits(),
connectionCount, newMaxSize);
+                this.shrinkLater = resizeInfo.getShrinkLater();
 
                 permits = new FIFOSemaphore(newMaxSize);
-                //1st example: acquire 10 (all)
-                //2nd example: acquire 10 (same as in old semaphore)
-
                 //pre-acquire permits for the existing checked out connections that will
not be closed when they are returned.
-                for (int i = 0; i < checkedOut - shrinkLater; i++) {
+                for (int i = 0; i < resizeInfo.getTransferCheckedOut(); i++) {
                     permits.acquire();
                 }
-                //1st example: copy 0 (none)
-                //2nd example: copy 10 (all)
-                transferConnections(newMaxSize, shrinkNow);
+                //transfer connections we are going to keep
+                transferConnections(newMaxSize, resizeInfo.getShrinkNow());
+                this.minSize = resizeInfo.getNewMinSize();
             } finally {
                 resizeLock.writeLock().release();
             }
         }
     }
 
+
+    static final class ResizeInfo {
+
+        private final int newMinSize;
+        private final int shrinkNow;
+        private final int shrinkLater;
+        private final int transferCheckedOut;
+
+        ResizeInfo(final int oldMinSize, final int oldPermitsAvailable, final int oldConnectionCount,
final int newMaxSize) {
+            final int checkedOut = oldConnectionCount - oldPermitsAvailable;
+            int shrinkLater = checkedOut - newMaxSize;
+            if (shrinkLater < 0) {
+                shrinkLater = 0;
+            }
+            this.shrinkLater = shrinkLater;
+            int shrinkNow = oldConnectionCount - newMaxSize - shrinkLater;
+            if (shrinkNow < 0) {
+                shrinkNow = 0;
+            }
+            this.shrinkNow = shrinkNow;
+            if (newMaxSize >= oldMinSize) {
+                newMinSize = oldMinSize;
+            } else {
+                newMinSize = newMaxSize;
+            }
+            this.transferCheckedOut = checkedOut - shrinkLater;
+        }
+
+        public int getNewMinSize() {
+            return newMinSize;
+        }
+
+        public int getShrinkNow() {
+            return shrinkNow;
+        }
+
+        public int getShrinkLater() {
+            return shrinkLater;
+        }
+
+        public int getTransferCheckedOut() {
+            return transferCheckedOut;
+        }
+
+
+    }
+
     protected abstract void transferConnections(int maxSize, int shrinkNow);
 
     public abstract int getIdleConnectionCount();
@@ -226,7 +255,7 @@
         if (idleTimeoutMinutes < 0) {
             throw new IllegalArgumentException("idleTimeoutMinutes must be positive or 0,
not " + idleTimeoutMinutes);
         }
-        if (idleReleaser!= null) {
+        if (idleReleaser != null) {
             idleReleaser.cancel();
         }
         if (idleTimeoutMinutes > 0) {

Added: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java?rev=356367&view=auto
==============================================================================
--- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
(added)
+++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
Mon Dec 12 12:23:13 2005
@@ -0,0 +1,72 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.connector.outbound;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev:  $ $Date$
+ */
+public class PoolResizeTest extends TestCase {
+
+    private final int oldCheckedOut = 20;
+    private final int oldConnectionCount = 40;
+    private final int oldPermitsAvailable = oldConnectionCount - oldCheckedOut;
+    private final int oldMaxSize = 60;
+
+    public void testOne() throws Exception {
+        int oldMinSize = 5;
+        int newMaxSize = 10;
+        AbstractSinglePoolConnectionInterceptor.ResizeInfo resizeInfo = new AbstractSinglePoolConnectionInterceptor.ResizeInfo(oldMinSize,
oldPermitsAvailable, oldConnectionCount, newMaxSize);
+        assertEquals("wrong shrinkLater", 10, resizeInfo.getShrinkLater());
+        assertEquals("wrong shrinkNow", 20, resizeInfo.getShrinkNow());
+        assertEquals("wrong newMinSize", 5, resizeInfo.getNewMinSize());
+        assertEquals("wrong transferCheckedOut", 10, resizeInfo.getTransferCheckedOut());
+    }
+
+    public void testTwo() throws Exception {
+        int oldMinSize = 5;
+        int newMaxSize = 30;
+        AbstractSinglePoolConnectionInterceptor.ResizeInfo resizeInfo = new AbstractSinglePoolConnectionInterceptor.ResizeInfo(oldMinSize,
oldPermitsAvailable, oldConnectionCount, newMaxSize);
+        assertEquals("wrong shrinkLater", 0, resizeInfo.getShrinkLater());
+        assertEquals("wrong shrinkNow", 10, resizeInfo.getShrinkNow());
+        assertEquals("wrong newMinSize", 5, resizeInfo.getNewMinSize());
+        assertEquals("wrong transferCheckedOut", 20, resizeInfo.getTransferCheckedOut());
+    }
+
+    public void testThree() throws Exception {
+        int oldMinSize = 5;
+        int newMaxSize = 50;
+        AbstractSinglePoolConnectionInterceptor.ResizeInfo resizeInfo = new AbstractSinglePoolConnectionInterceptor.ResizeInfo(oldMinSize,
oldPermitsAvailable, oldConnectionCount, newMaxSize);
+        assertEquals("wrong shrinkLater", 00, resizeInfo.getShrinkLater());
+        assertEquals("wrong shrinkNow", 0, resizeInfo.getShrinkNow());
+        assertEquals("wrong newMinSize", 5, resizeInfo.getNewMinSize());
+        assertEquals("wrong transferCheckedOut", 20, resizeInfo.getTransferCheckedOut());
+    }
+
+    public void testFour() throws Exception {
+        int oldMinSize = 5;
+        int newMaxSize = 70;
+        AbstractSinglePoolConnectionInterceptor.ResizeInfo resizeInfo = new AbstractSinglePoolConnectionInterceptor.ResizeInfo(oldMinSize,
oldPermitsAvailable, oldConnectionCount, newMaxSize);
+        assertEquals("wrong shrinkLater", 0, resizeInfo.getShrinkLater());
+        assertEquals("wrong shrinkNow", 0, resizeInfo.getShrinkNow());
+        assertEquals("wrong newMinSize", 5, resizeInfo.getNewMinSize());
+        assertEquals("wrong transferCheckedOut", 20, resizeInfo.getTransferCheckedOut());
+    }
+
+
+}

Propchange: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message