In migrating from Firebird 2.5 to 5, I've noticed that just
connecting to the database takes longer.
I wrote a simple Python program to make 1000 connections to the server, then ran it with the v2.5 and v5.0 fbclient libraries, connecting to a v2.5 and v5.0 server all running on localhost:
import fdb
import sys
from timeit import timeit
def test():
con = fdb.connect(dsn=sys.argv[1])
cur = con.cursor()
con.close()
print(timeit('test()', setup="from __main__ import test", number=1000))
Then run it with: bench.py localhost/<port>:/path/to/db.fdb
Most of the delay was due to the different server, though the newer client also slowed things down slightly connecting to v2.5:
Configuration Time for 1000 connects
2.5 client, 2.5 server 4.97s
5.0 client, 2.5 server 5.954s
2.5 client, 5.0 server 21.04s
5.0 client, 5.0 server 26.857s
The extra time seems to be spent at the Firebird server, which
uses a lot of CPU while the test runs.
My server is running SuperServer, configuration is from the
ib-aid configuration generator at
https://cc.ib-aid.com/democalc.html. I tried turning off WireCrypt
and it made a tiny bit of difference but not much. I tried using
127.0.0.1 instead of localhost to ensure it's not a network issue
(noting that 2.5 had no IPv6 support and 5 does) but that also
changed nothing.
Is there anything else I should tweak or check?
Thanks
Hamish
I tried Srp256 and Legacy_Auth alone and also the default and it didn't
make more than 1 second difference in 25. Also tried connecting to an
empty database and that saved a few seconds, but it is still about 22ms
per connection, which is quite a lot I think.
I tried Srp256 and Legacy_Auth alone and also the default and it didn't
make more than 1 second difference in 25. Also tried connecting to an
empty database and that saved a few seconds, but it is still about 22ms
per connection, which is quite a lot I think.
Just for note - test includes disconnect time too.
Why it is a problem for you ? Does your apps creates a lot of short-lived (<= 50ms) connections ?
My unittests were making a new connection for each test, and were
significantly slower with Firebird 5 as a result. I've changed
them to reuse the connections and now they're actually faster than
when run against 2.5.
Anyway, I doubt they are not overlapped in time - and it is very important for such kind of "testing".
Try to retain at least one alive separate connection during such test or set database linger - it allowsto retain many "heavy" structures in memory and avoid perf penalty on connect. Of course, it worksfor SuperServer only.
Indeed, if I keep a master connection open then open/close 1000 more, those run very quickly.
My application has hundreds of databases so it's not feasible to
connect to them all in advance, and latency is important, but I
keep a connection after the first use so only the first connection
is slower. This is unavoidable.
Thanks
Hamish