Blocking IO in Akka
Tag : scala , By : Michael T.
Date : March 29 2020, 07:55 AM
wish of those help Doing blocking IO is a bad idea in general, and in a reactive multithreaded environment in particular, so your first step is to try to avoid it alltogether, that means looking into using AsyncHttpClient or HttpAsyncClient. If that does not work, you can at least mitigate the risks by giving the blocking actors their own threads. This will of course be costly and you still risk filling up their mailboxes, but such is the choice of using blocking IO.
|
Deliberate Blocking in Akka Actors
Date : March 29 2020, 07:55 AM
this one helps. I would take approach 1. It should be noted though that actors do not have a dedicated thread by default but they share a thread pool (the so called dispatcher, see: http://doc.akka.io/docs/akka/2.3.6/scala/dispatchers.html). This means that blocking is inherently dangerous because it exhausts the threads of the pool not letting other non-blocked actors to run (since the blocked actors do not put the thread back into the pool). Therefore you should separate blocking calls into a fixed size pool of dedicated actors, and you should assign these actors a PinnedDispatcher. This latter step ensures that these actors do not interfere with each other (they each have a dedicated thread) and ensures that these actors do not interfere with the rest of the system (all of the other actors will run on another dispatchers, usually on default-dispatcher). Be sure though to limit the number of actors running on the PinnedDispatcher since the number of used threads will grow with the number of actors on that dispatcher.
|
How to use the Akka ask pattern without blocking
Tag : scala , By : user183442
Date : March 29 2020, 07:55 AM
Any of those help You don't want to block, by waiting on the response of the actor, so you are using Future correctly. The code in the onComplete function is executed, when your actor responds with the list. And since you don't want to block and handle it asynchronously, your last println statement is executed while your actor has not yet responded. object Test extends App{
val system = ActorSystem("testing")
val MyActor = system.actorOf(Props[MyActor], name = "InstitutionUserSuggestion")
implicit val timeout = Timeout(15 seconds)
val future: Future[List[Int]] = ask(MyActor,"returnAlist").mapTo[List[Int]]
future.onComplete {
case Success(result)=>
println("returned list size is " + result.size +" and its contents" + result)
case Failure(e)=>
println("in failure")
e.printStackTrace()
}
}
|
Akka and blocking operations
Date : March 29 2020, 07:55 AM
hope this fix your issue The Akka project is very supportive of the Reactive Manifesto. The documentation assumes that by using Akka you are also interested in building a system according to the Reactive Manifesto. A key part of the Reactive Manifesto is that systems should remain responsive at all times. If you used the same dispatcher/thread pool for the blocking DB operations as for your main Akka routing infrastructure, it is possible that all the Akka threads could be occupied by the DB operations, and your system would effectively be deadlocked until one of the DB operations completes. This might not be a problem for a simple system on a single JVM that only performs this task, but it's easy to think of new features that would make this a problem:
|
Blocking calls in Akka Actors
Date : March 29 2020, 07:55 AM
|