On Tue, 23 Oct 2012 23:01:06 -0400, Nick Sabalausky wrote:
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.
At least at PostgreSQL driver libpq does not allow this behaviour and it is need organize queue.
In my application I am create one non shared connection in app.d static constructor, and just use it it thread. For two threads constructor creates two connections automatically (this assumption, I have not tested it)