Page 1 of 1
ThradSafe connection
Posted: Mon 13 Dec 2010 15:00
by imeyer
Hello
i got a problem i am running an applikation in which i do connections and sending sql's in a thread. So it is possible for several clients to connect and have there sql statmens setup for each sql statment from each client in an own thread als well having an own connection to this statment and after this closing the connection in the same thread.
But now after updating to the new Version i have got the big problem that when i run one client and doing a hughe sql statment (means a lot of data's to collect) the other client stucks until the first one is finished. And i do not change anything in my applikation (checked it with SVN ). I only uninstall the old IBDAC Version from 3.5.0.17 and install the newest one.
seems to be that there is a problem in the threading method. I am sorry to could not get an example an i compared both IBDAC sources but i was not able to find the diffrent !
Posted: Tue 14 Dec 2010 09:18
by AndreyZ
Hello,
The point is that we implemented the restriction of execution of several statements at once. It was done because the Firebird/Interbase dll isn't threadsafe and it doesn't allow several API calls at once. To bypass this restriction you can set the ThreadSafetyClientLibrary variable of the IBCCall unit to False. This variable is available starting with IBDAC 3.50.0.19.
Posted: Wed 15 Dec 2010 07:23
by tsteinmaurer
Hello,
we also have a multi-threaded application based on IBDAC accessing Firebird 2.5. Even if each thread has its own connection, transactions, queries etc., do we have to use that boolean variable? If so, this breaking change isn't documented in the revision history.
Thanks!
Thomas
Posted: Wed 15 Dec 2010 08:38
by MatthiasR
Same question here regarding UniDAC accessing a PostgreSQL-database. Is it necessary to use a separate connection within a thread or is it possible to share the already existing and opened connection of the main thread without any problems?
Thanks for your help!
Posted: Wed 15 Dec 2010 11:55
by AndreyZ
to tsteinmaurer: In this case you don't have to use the ThreadSafetyClientLibrary variable.
Posted: Fri 17 Dec 2010 07:38
by MatthiasR
And what about me?!?
Posted: Fri 17 Dec 2010 09:29
by AlexP
Hello,
MatthiasR: The best way to work with Postgres in a multithread application is to create a new connection for each thread, but you can use single connection for all threads; in this case you should set the Connection property in the thread.
Posted: Fri 17 Dec 2010 10:26
by MatthiasR
Thank you Alex, in this case I will take your advice and create a separate connection in each thread that needs access to the data.
Posted: Tue 21 Dec 2010 11:25
by imeyer
According to the answer of "tsteinmaurer" question
in my application i do the same i have a connection, a query an a transaction for each thread. But if i use the newer version even with the ThreadSafetyClientLibrary on false the appications stucks until getting a response if i run to of them
Posted: Wed 22 Dec 2010 13:04
by AndreyZ
I cannot reproduce the problem. Please specify the exact Firebird version you are using. Also try composing a small sample to demonstrate the problem and send it to andreyz*devart*com.
Posted: Wed 29 Dec 2010 19:13
by banita
firebird 2.5 is thread safe so I must set ThreadSafetyClientLibrary varialbe or not?
from fb 2.5 release note:
The client libraries, including the embedded one, can now be used in multi-threaded applications without any
application-level synchronization.
Posted: Thu 30 Dec 2010 09:10
by AndreyZ
The default value of the ThreadSafetyClientLibrary variable is set to True. It means that IBDAC is trying to implement thread safety by itself. If the client library is threadsafe (like in Firebird 2.5), thread safety is implemented both by IBDAC and Firebird. You can turn off the thread safety provided by IBDAC by setting the ThreadSafetyClientLibrary variable to False. In this case thread safety will be provided only by Firebird.
Posted: Mon 14 Feb 2011 09:42
by Dimon
Starting from IBDAC version 3.50.0.20 the ThreadSafetyClientLibrary global variable is set to False by default.
IBDAC implements thread safety by itself only for non threadsafe client library. For threadsafe client library (like in Firebird 2.5) IBDAC doesn't use implementation of thread safety.
If you need, you can turn on thread safety provided by IBDAC for any client libraries by setting ThreadSafetyClientLibrary to True.
Posted: Wed 23 Mar 2011 19:48
by tsteinmaurer
Hello,
so, for a properly designed multi-threaded application, with a connection per thread etc., with 3.50.0.20 and higher I don't have to change this boolean variable to get the same behavior and possibly performance as with older IBDAC version? E.g. V3.10 series. If so, excellent!
Thanks!
Thomas
Posted: Thu 24 Mar 2011 08:38
by AndreyZ
If you are using Firebird 2.5 with IBDAC 3.50.0.20 (or higher), you don't have to use the ThreadSafetyClientLibrary library. And you will have the same behaviour as in older IBDAC versions.