简体   繁体   English

并行执行方法

[英]Parallel execution of methods

I have an application that sends multiple request to my spray-can 1.3.1 server. 我有一个将多个请求发送到我的spray-can 1.3.1服务器的应用程序。

FireBug shows me, that these requests are triggered in parallel. FireBug向我展示了这些请求是并行触发的。

However, on the server these request are handled strictly serially. 但是,在服务器上,这些请求将严格按顺序处理。

I think I need to somehow configure the spray server to handle multiple requests in parallel - but how? 我想我需要以某种方式配置Spray Server来并行处理多个请求-但是如何?

The server is started like that: 这样启动服务器:

object Server extends SimpleRoutingApp{  
  def main(args: Array[String]): Unit = {
    implicit val system = ActorSystem()
    startServer("0.0.0.0", port = 8080) {
      get{
        pathSingleSlash {
          complete{
            HttpEntity(
              MediaTypes.`text/html`,
              Template.txt
            )
....

As Spray routing is synchronous in an actor, you will need to do something else to make it handle multiple requests in parallel. 由于Spray路由在actor中是同步的,因此您将需要执行其他操作以使其并行处理多个请求。

  1. Using the Detach directive : This directive will spawn a new actor to process that request. 使用Detach指令 :该指令将产生一个新的actor来处理该请求。
  2. Using an actor-per-request 使用每个请求actor

You can also find other links in SO about it. 您也可以在SO中找到与此有关的其他 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM