Tuesday, January 9, 2018

Actors vs Futures - reference

https://www.chrisstucchio.com/blog/2013/actors_vs_futures.html

https://www.reddit.com/r/scala/comments/5kk9bc/my_problems_with_akka/#bottom-comments

Before I respond to your post, I'd like to say the following:
Don't use Spray. Use Akka-HTTP. Spray is effectively obsolete. You want Akka-HTTP 10.x, which is just as fast and has Akka Streams built in. Streams uses Actors under the hood, but gives you an abstraction that lets you focus on the elements.
If you want to use Akka testing, you need akka-testkit, which is fairly low level. For streams, you want akka-stream-testkit, which is easier. http://doc.akka.io/docs/akka/2.4.9/scala/stream/stream-testkit.html
The example you're using is quite old as well -- for an example of an akka-http project using Guice and slick, see:
https://github.com/kgoralski/akka-http-slick-guice
Now to your points:
You want to use Actors when you want to hold state, and you want to use them when you need to handle failure -- that is, an exception from several child actors that manage database operations can propagate up to a parent actor which acts as a supervisor and can determine more complex failures and define a failure hierarchy. This is more difficult to manage than Future, which does have recover / Try etc but doesn't have the same supervisor capabilities. Read Jamie Allen's book for more details.
For a REST service with DB persistence layer, you should be using Slick with HikariDB, and size the thread pool according to http://slick.lightbend.com/doc/3.1.0/database.html#database-thread-pool -- you don't want to just throw 10 threads at a DB and hope for the best, you have to actually size it according to performance tests and work out the queueSize.
If you want HTTP inside a dependency injection framework using Akka with a testing framework and Guice DI and no complicated bits unless you want them, then you want Play. Play is all of those things put together.
Here are the example projects:
And there are more projects here: https://playframework.com/download
We're aiming to integrate Akka-HTTP as the default HTTP engine for Play 2.6.x, and there's an experimental version of the engine in 2.5.x, but for now the core engine is handled by Netty, with Akka Streams are used internally to communicate with Netty.

No comments:

Post a Comment