From: Maciej S. <pr...@ms...> - 2007-09-06 19:49:19
|
Yves Roy wrote: > Actually, we are using SOCI in a multithreaded environment, and most of > the time no SOCI exceptions are raised and thousands > of connections to the database are created without any problem. Is it possible that some server-side limit is exhausted this way? Creating thousands of connections sounds like a challenge for the server. > And so I have 3 related questions: > > 1- Is SOCI thread-safe ? SOCI is thread-safe in the sense that each separate session and all its dependent objects (statements, iterators, etc.) should be used by a single thread in any given moment (not necessarily the same thread all the time), but there is nothing that would prevent you from creating many sessions and using each of them from many, but separate threads. If I had to compare it to some other well-known examples, I think that analogy with STL containers would be the most exact. Having said that, it's important to state also that the multithreading support in SOCI is *conditional* and depends on whether the actual backend access library supports it. We don't know of any problems with the native libraries that we use and if they are implemented reasonably, there is absolutely no difference between creating many sessions in separate threads and in doing the same in separate processes. > Any history of such connection problems in a > multithreaded applications ? No problems reported before. > 2- If SOCI is not thread-safe, do you know any other similar database > access library for C++ which is ? Yes, there are some other libraries, but they are not similar. ;-) Note that if for some particular server SOCI is not thread-safe due to the native library limitations, then any other high-level library built on top of the same native one will not work with many threads anyway. > 3- Is there a way to maintain a count of the opened/closed connections ? No, SOCI does not maintain any counter on its own. Each session object is just a separate object. > is there a way to "ask" SOCI of the number of connections currently open > by my application? No, there is no way. It is guaranteed that destructor of the session object physically closes the connection. Regards, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ |