FB3 Threading and Connections

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

FB3 Threading and Connections

Post by FredS » Wed 06 Jul 2016 00:11

Hi,

I ran into this, from: http://www.mail-archive.com/firebird-su ... 14625.html
Both engine and remote layer doesn't allow to run more than one thread per connection at the same time.
So now I have to ask, what happens when we set the same connection string to threaded TUniConnections?
From: viewtopic.php?f=28&t=32233#p111360
the correct solution will be to use a separate connection (the TUniConnection component) in each thread.
Is FB3 serialized or threaded? And if serialized how do I force a new connection from a thread with the same ConnectionString?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: FB3 Threading and Connections

Post by ViktorV » Thu 07 Jul 2016 13:58

Please clarify your question. If you are interested in specificities of Firebird 3 functioning, please forward your question to Firebird technical support. If you are interested in UniDAC usage when working with Firebird in multi-threaded applications, then you have got a right answer: to create a thread-safe application, you should create a separate TUniConnection component in each thread and set the same connection string for each TUniConnection instance.

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: FB3 Threading and Connections

Post by FredS » Thu 07 Jul 2016 19:30

ViktorV wrote:Please clarify your question.
Resource Monitor shows no additional threads being run by a local FB3 server when my app starts four new threads are using the same ConnectionString.

The Q:
How do I force a new FB3 (threaded on the Server side) connection from a thread using the same ConnectionString in UniDAC?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: FB3 Threading and Connections

Post by ViktorV » Fri 08 Jul 2016 11:08

If you mean usage of server in a multi-threaded mode, then usage of this mode depends on Firebird 3 configuration. For concurrent DB usage with creating a thread for each incoming connection, you can use Superclassic Server Mode. See more detailed information about Firebird 3 Server Modes at: http://firebirdsql.org/file/documentati ... kStart.pdf You can choose Server Mode during installation of Firebird 3. You can also change Server Mode at any time in the firebird.conf file (the ServerMode variable) and restart the process.
If you mean UniDAC usage for creating multi-threaded applications, then you can create such applications. The only limitation is that you can't use a single connection (the TUniConnection component) in several threads. Therefore you should use a separate connection in each thread, not depending on the Firebird version.

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: FB3 Threading and Connections

Post by FredS » Fri 08 Jul 2016 19:14

ViktorV wrote:The only limitation is that you can't use a single connection (the TUniConnection component) in several threads. Therefore you should use a separate connection in each thread, not depending on the Firebird version.
I already did that but wasn't sure if that translated to multiple connections in FB3.
After setting up Tracing I can verify that it does. However while looking at the Attachments/Connections change in the trace data I wondered about using connection Pooling.

When I turn on Connection Pooling and run I get an exception in TGDS.LoadGDS: Cannot load client DLL

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: FB3 Threading and Connections

Post by ViktorV » Wed 13 Jul 2016 09:43

To solve the issue, please try to explicitly specify the path to the Firebird 3 client library in the TUniConnection.SpecificOptions.Values['Clientlibrary'] property.
If this doesn't help solve the issue, please compose a small sample reproducing the described behavior and send it to viktorv*devart*com , including scripts for database objects creating.

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: FB3 Threading and Connections

Post by FredS » Wed 13 Jul 2016 17:01

ViktorV wrote:To solve the issue, please try to explicitly specify the path to the Firebird 3 client library in the TUniConnection.SpecificOptions.Values['Clientlibrary'] property
This is already there, the app runs fine when Pooling is Off.
Tracing through your code it appears that the Clientlibrary value is never used. Adding the Clientlibrary dir to the path allowed me to test "Pooling" but it won't take the value from SpecificOptions when Pooling is ON.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: FB3 Threading and Connections

Post by ViktorV » Thu 14 Jul 2016 10:23

Thank you for the information. We have reproduced and fixed the issue. The fix will be included in the next build of UniDAC.

Post Reply