Am 10/24/2012 5:01 AM, schrieb Nick Sabalausky:

To avoid the cost of establishing a new connection to a MySQL DB
on potentially every page request, I tried making one connection to
the DB upon startup of my vibe.d app and then use that one connection
for each request. Worked fine until I tried making concurrent page
requests, at which point I (perhaps unsurprisingly) got a message about
the wrong fiber accessing a connection and then it died with an
InvalidMemoryOperationError. (But annoyingly, I can't seem to reproduce
it now.)

So I realize that's probably not a smart thing to do anyway, to share a
single connection across fibers. But how would I go about reusing DB
connections when possible? By using ConnectionPool, maybe? But I'm not
quite sure how to use that.

In my modified version of the mysql driver there is a trivial MysqlDB
class that uses a ConnectionPool. lockConnection() returns a RAII
struct that makes sure that a single connection is not used twice.

Usually I would also mirror the methods of the Connection class for
convenience, but since I don't really use it myself, I didn't put so
much time into it yet.

https://github.com/rejectedsoftware/mysql-native/blob/master/source/mysql/db.d