The Future{blockingFunc()} takes an implicit ExecutionContext. Have an implicit var in your controller point to the specific akka threadpool. You can always pass it explicitly if needed (sometimes it's nice to know what's going on).
Jaao
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
final def apply[A](bodyParser: BodyParser[A])(block: R[A] => Result): Action[A] = async(bodyParser) { req: R[A] =>
block(req) match {
case simple: SimpleResult => Future.successful(simple)
case async: AsyncResult => async.unflatten
}
}
HTH
Christopher
Christopher
Putting the blocking DB call inside an Actor provides a nice clean model for handling timeouts & failures, setting up blocking execution contexts, and managing any state that may be associated with the service. Also Actors provide some nice patterns like the ScatterGatherFirstCompletedRouter to address simultaneous cache & db requests. But an Actor may be overkill depending on what you need.
-James
On 12/15/2013 04:51 AM, Saurabh Rawat wrote:
Hi,
Thanks Jan for the explanation, thanks Fernando for the webinar link.
In the webinar James Ward says that we should use Actors for things like
talking to the database. In the example he is using a WS call which is
nonblocking. If I were to do a db fetch while processing a message
inside an actor, would I wrap it inside a future? Because from what I
understand I should not have a blocking call inside an actor.
Now what I am confused about is, if I am making a future inside the
actor anyway, why not make a future right there in the controller def-
Action.async {
future {
blocking call
} map {
send response
}
}
Why create another level of indirection, what do I gain from that?
Regards,
Saurabh Rawat
On Sun, Dec 15, 2013 at 3:43 AM, Christopher Hunt
wrote:
As has been pointed out, actions are always executed in their own
executor. As a convenience we assume that you are not dealing with
futures within your action block, and we wrap the result with a
completed future. If you are dealing with futures (such as calling
wS), then to return a future result you use .async.
HTH
Christopher
--
You received this message because you are subscribed to the Google
Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to play-framework+unsubscribe@googlegroups.com<mailto:play-framework%2Bunsu...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to play-framework+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/WWQ0HeLDOjg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framework+unsubscribe@googlegroups.com.
That is ideal but there are times when it can't be avoided, like JDBC calls, CPU intensive operations, etc.
On 12/15/2013 01:32 PM, Jaap Taal wrote:Roland Kuhn is teaching never to block in an actor, you probably want to
take his advice!
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/WWQ0HeLDOjg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
an email to play-framework+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
In this case you probably won't get any better throughput for the requests that talk to the db. If you can only make 100 db calls per second then it doesn't matter how many incoming requests you can handle; the max number of requests per second will never be more than 100 (assuming one db request per web request). Unless you have spikes that build a backlog of pending requests which can eventually be depleted.
As James Roper says, by putting the blocking db stuff into actors you can easily create a dedicated thread pool that will help keep the rest of the system responsive.
I hope that helps.
<javascript:>>. <https://groups.google.com/groups/opt_out>.> an email to play-framewor...@googlegroups.com <javascript:>. <https://groups.google.com/groups/opt_out>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "play-framework" group.
> To unsubscribe from this group and stop receiving emails from it,
send
--
You received this message because you are subscribed to the Google
Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to play-framewor...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
Rahul
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/b56b7064-bb07-46c9-9efa-92160e629036%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.