ZAbstractConnection Disconnect performance issue with TZDbcPooledConnection

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

ZAbstractConnection Disconnect performance issue with TZDbcPooledConnection

Post by stoffman »

Hi,
There is a performance issue and potential bug related to TZDbcPooledConnection when disconnecting a connection. I would like to propose a small change that will help a lot.
First some background: ZAbstractConnection.Disconnect has the following code:

Code: Select all

    
    try
      FConnection.Close;
      FConnection.SetOnConnectionLostErrorHandler(nil);
    finally
      FConnection := nil;
    end;
FConnection is TZDbcPooledConnection so the following happen:
1. FConnection.Close - returns the underlying connection to the connection pool.
2. FConnection.SetOnConnectionLostErrorHandler - now because it doesn't have a connection it acquires a new connection that may be unrelated to the connection that was just returned to the pool.
3. FConnection := nil - because it is an interface, it will destroy the object which in turn will return the underlying connection to the pool

The proposed change is very simple:
call FConnection.SetOnConnectionLostErrorHandler(nil); before calling FConnection.Close
I did some basic testing it looks like it doesn't affect other drivers (sqlite)

Comments?
Last edited by stoffman on 09.10.2021, 20:44, edited 1 time in total.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZAbstractConnection Disconnect performance issue with TZDbcPooledConnection

Post by marsupilami »

Hmmm - I think, it should be different. The pooled connection should remove the disconnect handler from the connection that is retuned to te pool before returning it. Also it should just do nothing if the connection is already returned to the pool.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZAbstractConnection Disconnect performance issue with TZDbcPooledConnection

Post by marsupilami »

I implemented a possible solution. Could you please check the latest svn?
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Re: ZAbstractConnection Disconnect performance issue with TZDbcPooledConnection

Post by stoffman »

For my use case it looks good. thanks.
Post Reply