bah.database and threads

BlitzMax Forums/Brucey's Modules/bah.database and threads

Mahan(Posted 2008) [#1]
Hi! I just wanted to check if anyone has tried using the bah.database and some specific bah.db* together with threading?

In my game-server I'm just about to add some persistance and now that threads have arrived to BlitzMax I started thinking about having a fast non-blocking main-thread serviceing client-requests and then spawn threads from it when something needs to be persisted (i.e. updated in DB)

So to boil it down: Has anyone tried asynchronus updates (from several threads) in bah.database and especially bah.dbmysql or bah.postgresql?


Brucey(Posted 2008) [#2]
Has anyone tried asynchronus updates...

Heh... not yet.

All the objects are reasonably separated, so for instance, you should, in theory, be able two TDatabaseQuery object running concurrently.

However, the native connection may not like this. I know for a fact that the Oracle JDBC driver (as an example) does not support asynchronous requests on the same connection - it works, but only one at a time.

The error reporting stuff in DBConnection is not thread-safe : meaning, Thread A could populate it, and Thread B could clear it before your code in Thread A can check the status.

Of course, I don't see any reason why you couldn't run multiple DBConnections. It would make more sense anyway (rather than trying to share a single connection), and is more likely to be supported by the native database drivers.
This way, you might want to have some kind of connection pooling thing going on. Where a thread can request a connection from the pool when required. The pool either hands it a vacant one, or creates a new one.


Mahan(Posted 2008) [#3]
Yes in that case pooling several connections (and implicitly queueing updates with FIFO) makes a lot of sence.

Comming from Java i think something like BlockingQueue would be nice to have in the pub.threads. Ofc. it's not very hard to write one but it's "general purposed" enough to be part of the lib.

I think I'll look into this later today, after work. Seems like fun :)