Hi
New to akka and actor systems in general. I see this in the best
practices section:
"The blocking operations should be done in some special-cased thread
which sends messages to the actors which shall act on them."
On Friday, April 27, 2012 6:08:31 AM UTC+2, Jason Mason wrote:Hi
New to akka and actor systems in general. I see this in the best
practices section:
"The blocking operations should be done in some special-cased thread
which sends messages to the actors which shall act on them."
I simply wrap blocking IO in a Future.
This works, and I hope its correct.
The only problem I have is getting to the ExecutorService which Future needs.
This should be available from the actor system somehow (I read somewhere), but I could not find it yet.
Now I intialize my own outside of akka.
def receive = {
case DoBlocking => {
Future {
val result = doblocking()
sender ! result
}(ExecutionContext.fromExecutorService(executorService))
Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn
Hi Ido,On Apr 27, 2012, at 15:34 , ido wrote:On Friday, April 27, 2012 6:08:31 AM UTC+2, Jason Mason wrote:Hi
New to akka and actor systems in general. I see this in the best
practices section:
"The blocking operations should be done in some special-cased thread
which sends messages to the actors which shall act on them."
I simply wrap blocking IO in a Future.
This works, and I hope its correct.
The only problem I have is getting to the ExecutorService which Future needs.
This should be available from the actor system somehow (I read somewhere), but I could not find it yet.
Now I intialize my own outside of akka.
def receive = {
case DoBlocking => {
Future {
val result = doblocking()Assuming that this is some externally required blocking API, right? If you have a choice, always prefer non-blocking APIs. But even then it might well be better to do the blocking within the actor (Future and Actor are executed in the same way, so blocking is exactly equally bad in both cases), because your code will queue up blocking tasks without bound, and if the underlying resource uses synchronization then you block even more uselessly.sender ! resultThis will not reply to the right sender, because you are closing over a mutable entity. I know that we’d all like the compiler to flag this as an error, but unfortunately this feature is just being developed and might (with luck) end up in 2.10.
}(ExecutionContext.fromExecutorService(executorService))
This is rather wasteful, depending on what your “executorService” does. Why not simply “import context.dispatcher”? Then you can configure it as described in the docs.
Let’s make a superficially recursively paradox statement: the only general statement about solutions to the Blocking Problem is that no such statement can be made ;-)If you must use blocking, this must always be carefully planned (how many in parallel, given the characteristics of the API, on which thread pool, what about interruption, …)Regards,Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Happy hAkking!
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/IkkVYx83HnsJ.