I'm thinking about changing some of my code in my multi threaded application to use pooling + disconnected mode, instead of one unique connection in each thread - just to keep number of concurrent connections to a minimal.
First of all, if I configure pooling + disconnected mode, will this be 100% thread safe, and will it mean that the connection actually stays connected within the pool, and that the thread will get/return the connection only during the actual database communication stage?
Secondly, if I really want to do several queries to the database within one thread, and make sure to keep the same connection, is StartTransaction/Commit the only way to keep it like that, or is there another way? I have some SQL queries using some specific locking code etc, and I'm not sure starting a transaction there is the best solution.
Regards,
Peter Olsson
Questions about pooling + disconnected mode
-
AndreyZ
Hello,
1) Connection pooling cannot guarantee you that your application will be thread-safe, because several threads still can use the same connection simultaneously in this case. Using disconnected mode with pooling doesn't make your application thread-safe either. The only thing that makes your application thread-safe is using different connection for each thread.
2) Because you will be using different connections in each thread, you can be sure that all queries in the thread use the same connection.
1) Connection pooling cannot guarantee you that your application will be thread-safe, because several threads still can use the same connection simultaneously in this case. Using disconnected mode with pooling doesn't make your application thread-safe either. The only thing that makes your application thread-safe is using different connection for each thread.
2) Because you will be using different connections in each thread, you can be sure that all queries in the thread use the same connection.
Ok, thanks for the answer!
What is the intended usage of pooling then? If it's not thread safe it can only be used from one thread at the same time, so more that one connection should never be needed? Is the only reason for the pool to keep the connection open when working in disconnected mode?
Regards,
Peter Olsson
What is the intended usage of pooling then? If it's not thread safe it can only be used from one thread at the same time, so more that one connection should never be needed? Is the only reason for the pool to keep the connection open when working in disconnected mode?
Regards,
Peter Olsson
-
AndreyZ
Connection pooling enables an application to use a connection from a pool of connections that do not need to be reestablished for each use. Once a connection has been created and placed in a pool, an application can reuse this connection without performing complete connection process. Using a pooled connection can result in significant performance gains, because applications can save the overhead involved in making a connection. This can be particularly significant for middle-tier applications that connect over a network, or for applications that connect and disconnect repeatedly, such as Internet applications. If you have several connections in one thread, you can use connection pooling to get higher performance.
It is recommended to use connection pooling with the DisconnectMode option of the TUniConnection component set to True. In this case internal connections can be shared between TUniConnection components. When some operation is performed with the TUniConnection component (for example, an execution of SQL statement), this component will connect using pooled connection, and after performing operation it will disconnect. When an operation is performed with another TUniConnection component, it can use the same connection from the pool.
It is recommended to use connection pooling with the DisconnectMode option of the TUniConnection component set to True. In this case internal connections can be shared between TUniConnection components. When some operation is performed with the TUniConnection component (for example, an execution of SQL statement), this component will connect using pooled connection, and after performing operation it will disconnect. When an operation is performed with another TUniConnection component, it can use the same connection from the pool.