You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/12/14 00:28:49 UTC
svn commit: r356645 - in /geronimo/branches/1.0/modules/connector/src:
java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
Author: djencks
Date: Tue Dec 13 15:28:40 2005
New Revision: 356645
URL: http://svn.apache.org/viewcvs?rev=356645&view=rev
Log:
GERONIMO-1345 Improve pool resize calculations, with tests
Added:
geronimo/branches/1.0/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java (props changed)
- copied unchanged from r356367, geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
Modified:
geronimo/branches/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
Modified: geronimo/branches/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java?rev=356645&r1=356644&r2=356645&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java (original)
+++ geronimo/branches/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java Tue Dec 13 15:28:40 2005
@@ -44,6 +44,7 @@
private long idleTimeoutMilliseconds;
private IdleReleaser idleReleaser;
protected Timer timer = PoolIdleReleaserTimer.getTimer();
+ protected int maxSize = 0;
protected int minSize = 0;
protected int shrinkLater = 0;
protected volatile boolean destroyed = false;
@@ -54,6 +55,7 @@
int blockingTimeoutMilliseconds,
int idleTimeoutMinutes) {
this.next = next;
+ this.maxSize = maxSize;
this.minSize = minSize;
this.blockingTimeoutMilliseconds = blockingTimeoutMilliseconds;
setIdleTimeoutMinutes(idleTimeoutMinutes);
@@ -97,8 +99,7 @@
if (destroyed) {
try {
connectionInfo.getManagedConnectionInfo().getManagedConnection().destroy();
- }
- catch (ResourceException re) {
+ } catch (ResourceException re) {
}
return;
}
@@ -131,58 +132,90 @@
// Cancel the IdleReleaser TimerTask (fixes memory leak) and clean up the pool
public void destroy() {
- destroyed = true;
+ destroyed = true;
if (idleReleaser != null)
idleReleaser.cancel();
internalDestroy();
next.destroy();
}
-
+
public int getPartitionCount() {
return 1;
}
public abstract int getPartitionMaxSize();
- public void setPartitionMaxSize(int maxSize) throws InterruptedException {
- if (maxSize <= 0) {
- throw new IllegalArgumentException("Max size must be positive, not " + maxSize);
+ public void setPartitionMaxSize(int newMaxSize) throws InterruptedException {
+ if (newMaxSize <= 0) {
+ throw new IllegalArgumentException("Max size must be positive, not " + newMaxSize);
}
- if (maxSize != getPartitionMaxSize()) {
+ 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 = (int) permits.permits();
- shrinkLater = checkedOut - maxSize;
- if (shrinkLater < 0) {
- shrinkLater = 0;
- }
- int shrinkNow = checkedOut + connectionCount - maxSize - shrinkLater;
- if (shrinkNow < 0) {
- shrinkNow = 0;
- }
+ ResizeInfo resizeInfo = new ResizeInfo(this.minSize, (int)permits.permits(), connectionCount, newMaxSize);
+ this.shrinkLater = resizeInfo.getShrinkLater();
- permits = new FIFOSemaphore(maxSize);
- //1st example: acquire 10 (all)
- //2nd example: acquire 10 (same as in old semaphore)
- for (int i = 0; i < checkedOut - shrinkLater; i++) {
+ permits = new FIFOSemaphore(newMaxSize);
+ //pre-acquire permits for the existing checked out connections that will not be closed when they are returned.
+ for (int i = 0; i < resizeInfo.getTransferCheckedOut(); i++) {
permits.acquire();
}
- //1st example: copy 0 (none)
- //2nd example: copy 10 (all)
- transferConnections(maxSize, 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();
@@ -222,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) {
@@ -244,16 +277,16 @@
private IdleReleaser(AbstractSinglePoolConnectionInterceptor parent) {
this.parent = parent;
}
-
+
public boolean cancel() {
this.parent = null;
return super.cancel();
}
-
+
public void run() {
// protect against interceptor being set to null mid-execution
AbstractSinglePoolConnectionInterceptor interceptor = parent;
- if (interceptor == null)
+ if (interceptor == null)
return;
try {
interceptor.resizeLock.readLock().acquire();
@@ -277,8 +310,8 @@
}
- // Currently only a short-lived (10 millisecond) task.
- // So, FillTask, unlike IdleReleaser, shouldn't cause GC problems.
+ // Currently only a short-lived (10 millisecond) task.
+ // So, FillTask, unlike IdleReleaser, shouldn't cause GC problems.
protected class FillTask extends TimerTask {
private final ManagedConnectionFactory managedConnectionFactory;
private final Subject subject;
Propchange: geronimo/branches/1.0/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/branches/1.0/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/branches/1.0/modules/connector/src/test/org/apache/geronimo/connector/outbound/PoolResizeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain