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?
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.
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.
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.
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.
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.
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.
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