You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2002/03/27 17:24:50 UTC

DO NOT REPLY [Bug 7519] New: - The DBCP has a sloggy performance under a multi-thread environment

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7519>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7519

The DBCP has a sloggy performance under a multi-thread environment

           Summary: The DBCP has a sloggy performance under a multi-thread
                    environment
           Product: Commons
           Version: Nightly Builds
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Pool
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: inethui@yahoo.com


There is a problem of the current implementation of GenericObjectPool, 
especially when it is used with DBCP as the underlying connection pool 
component. The performance is really poor as the returnObject method is 
synchronized and some expensive operations are done inside this method, such as 
_factory.passivateObject(Object). In the case of JDBC connection pool, the 
passivateObject actually tries to clean the JDBC connection which is a 
relatively expensive operation. It is even worse in a multi-thread environment 
(like a heavy database application running in an application server), the 
average waiting time will be increase linearly with the number of threads (or 
currently users) accessing the database (or the pool).

The following code is my recommended solution. I moved the expensive "passivate" 
operation out of the synchronized block as it has to be done anyway.

With this solution, I experienced an up to 10 times performance enhancement.

public void returnObject(Object obj) throws Exception {

    boolean success = true;
    try {
        _factory.passivateObject(obj);
    } catch (Exception e) {
        success = false;
        ; // ignored, we're throwing it out anway
    }

    synchronized (this) {
        _numActive--;

        if ((_maxIdle > 0)
                && ((_pool.size() >= _maxIdle)
                    || (_testOnReturn &&!_factory.validateObject(obj)))) {

            _factory.destroyObject(obj);

        } else {
            if (success) {
                _pool.addFirst(new ObjectTimestampPair(obj));
            } else {
                _factory.destroyObject(obj);
            }
        }

        notifyAll(); // _numActive has changed
    }
}

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>