Multithreading 播放未来和网络延迟-什么块,在什么级别?

Multithreading 播放未来和网络延迟-什么块,在什么级别?,multithreading,scala,playframework,jvm,playframework-2.0,Multithreading,Scala,Playframework,Jvm,Playframework 2.0,所以我们在操作系统上有一个JVM。在JVM中,正在运行Play(scala)应用程序。此应用程序使用Futures进行三次api调用: object MyAwsomeController extends Controller { val call1:Future[T] = scala.concurrent.future { ** call out across the wire to some awesome service ** } val call2:Future[T] = sc

所以我们在操作系统上有一个JVM。在JVM中,正在运行Play(scala)应用程序。此应用程序使用Futures进行三次api调用:

object MyAwsomeController extends Controller {

  val call1:Future[T] = scala.concurrent.future { ** call out across the wire to some awesome service ** }

  val call2:Future[T] = scala.concurrent.future { ** call out across the wire to another awesome service ** }

  val call3:Future[T] = scala.concurrent.future { ** call out across the wire to yet another different awesome service ** }

  def index() = Action { implicit request => 

      for {
        res1 <- call1
        res2 <- call2
        res3 <- call3
      } yield {
        Ok(views.html.index(res1, res2, res3)
      }

  }
}
对象MyAwsomeController扩展控制器{
val call1:Future[T]=scala.concurrent.Future{**call-out-the-wire-to-some-some-some-service**}
val call2:Future[T]=scala.concurrent.Future{**跨线调用另一个很棒的服务**}
val call3:Future[T]=scala.concurrent.Future{**跨线调用另一个不同的令人敬畏的服务**}
def index()=操作{隐式请求=>
为了{

res1鉴于您提供的详细信息(事实上,您没有“问题”),我建议您阅读这篇文章,它将解释一切:

我试图在这里对整个堆栈有一个水平的理解。在某个点上,一定会有阻塞发生

不,如果您使用的是异步I/O库(如NIO或Netty),则情况并非如此。了解它们如何避免阻塞将引导您使用低级内核函数,如
select
poll
epoll
,以及中断

Wiki可能是一个很好的起点:

我写了一些关于async/await的文章。这可能会帮助您理解线程何时在等待某些东西。
for {
  res1 <- scala.concurrent.future { ** call out across the wire ** }
  res2 <- scala.concurrent.future { ** call out across the wire ** }
  res3 <- scala.concurrent.future { ** call out across the wire ** }

} ...