Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play & Akka and blocking threads for database access

I want to make a call to a database which has lots of data and it might take a while to return.

I plan to do that work inside a call to Akka.future(f) and use an Async{} to render the response when the work is done.

Does it make sense to do that, or should I just do the long database call in the controller, without sending the work to Akka?

Or is there a way to do non blocking database access?

like image 601
John Smith Avatar asked Sep 28 '12 20:09

John Smith


People also ask

What is Google Play free?

Google Play only charges a service fee to developers who offer a paid app or sell access to in-app digital goods or services. Only 3% of developers on Google Play are subject to a service fee. The remaining 97% can distribute their apps and take advantage of all Google Play has to offer at no charge.

Is play app free?

Applications are available through Google Play either free of charge or at a cost. They can be downloaded directly on an Android device through the proprietary Google Play Store mobile app or by deploying the application to a device from the Google Play website.

Is Google Play still a thing?

Google Play Newsstand was shut down and merged into Google News in 2018, and Play Music was shut down in 2020 in favor of YouTube Music. Google Play Movies & TV seems next on the list. With the removal of purchases from the Play Store and the app from smart TVs, only the phone app is left.

How do I open the app play?

Open the Google Play Store from the All Apps screenOn the Home screen, either tap the All apps button, which is available on most Android smartphones, or swipe up to access the All Apps screen. On the All Apps screen, find the Play Store app and tap on it. Its icon looks like the symbol for Play in Google's colors.


2 Answers

If you're forced to use a blocking driver for your database (if for some reason the async driver for MySQL doesn't work out) consider setting up an Actor pool (using routing) with a PinnedDispatcher.

The PinnedDispatcher provides a thread per actor and, by setting up the router, will give you the ability to adjust the number of threads strictly responsible for handling the database calls. Easy scaling. Also, by using Actors you can structure the messages between actors (e.g. a message having the results of the database call) a little easier.

like image 177
Eric Reichert Avatar answered Oct 13 '22 19:10

Eric Reichert


You can use Akka.future(f) and provide your own Akka configuration file to get more threads to process your database accesses. Look at this config file for example.

But you pointed it out: the real problem is in using a database driver that blocks. I don't know which DB you are using, but it's worth to take a look to MongoDB with ReactiveMongo for example. With ReactiveMongo all MongoDB operations are perfectly non-blocking and asynchronous. There is a good introduction here. Moreover, it deals very well with Play Framework (check the ReactiveMongo Play Plugin).

EDIT: You can also check "Configuring Playframework's internal Akka system" to tune the worker threads number.

like image 26
Stephane Godbillon Avatar answered Oct 13 '22 19:10

Stephane Godbillon