I am currently working with a very large database (>50GB) and trying to understand the most efficient, usable approach that plays well with Akka's inherent threading.
Regarding the "wrapping everything inside withSession{ }" approach, while this would be an easier fix, I am concerned that this would restrict Akka's threading between actors. I am not that knowledgeable on how Akka's threading works, and how wrapping an entire actor system inside of withSession would effect it.
Another approach is to call withSession whenever the database is accessed, which is too inefficient. The "withSession {" code segment takes ~6ms to execute, and we are making millions of queries.
Essentially: what is the best way to rapidly access a database with Slick and Akka without breaking threading?
I have heard of approaches using implicit sessions and transactions, but I am struggling to find documentation on either of these.
Better late than never:
The recommended way is using a jdbc connection pool (e.g. c3p0). You need to make sure a session is acquired and returned from and in between kept on the same thread. withSession
lazily acquires a connection from the pool and returns it at the end of the scope. Quickly acquire connections when you need them and return them to the pool immediately after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With