ThradSafe connection

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
imeyer
Posts: 9
Joined: Mon 01 Mar 2010 16:24

ThradSafe connection

Post by imeyer » Mon 13 Dec 2010 15:00

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 !

AndreyZ

Post by AndreyZ » Tue 14 Dec 2010 09:18

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.

tsteinmaurer
Posts: 52
Joined: Thu 17 Dec 2009 08:25

Post by tsteinmaurer » Wed 15 Dec 2010 07:23

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

MatthiasR
Posts: 3
Joined: Wed 15 Dec 2010 08:27

Post by MatthiasR » Wed 15 Dec 2010 08:38

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!

AndreyZ

Post by AndreyZ » Wed 15 Dec 2010 11:55

to tsteinmaurer: In this case you don't have to use the ThreadSafetyClientLibrary variable.

MatthiasR
Posts: 3
Joined: Wed 15 Dec 2010 08:27

Post by MatthiasR » Fri 17 Dec 2010 07:38

And what about me?!?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Fri 17 Dec 2010 09:29

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.

MatthiasR
Posts: 3
Joined: Wed 15 Dec 2010 08:27

Post by MatthiasR » Fri 17 Dec 2010 10:26

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.

imeyer
Posts: 9
Joined: Mon 01 Mar 2010 16:24

Post by imeyer » Tue 21 Dec 2010 11:25

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

AndreyZ

Post by AndreyZ » Wed 22 Dec 2010 13:04

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.

banita
Posts: 29
Joined: Fri 19 Jun 2009 14:31

Post by banita » Wed 29 Dec 2010 19:13

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.

AndreyZ

Post by AndreyZ » Thu 30 Dec 2010 09:10

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.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 14 Feb 2011 09:42

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.

tsteinmaurer
Posts: 52
Joined: Thu 17 Dec 2009 08:25

Post by tsteinmaurer » Wed 23 Mar 2011 19:48

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

AndreyZ

Post by AndreyZ » Thu 24 Mar 2011 08:38

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.

Post Reply