如何调整AKKA中工人发起的线程数?

时间:2014-11-25 04:26:16

标签: multithreading scala akka

我创建了一个使用Akka和RoundRobin路由器的应用程序。应用程序获取文件列表并并行处理它们。我的问题是,无论我指定的工作者数量如何,应用程序一次只处理12个文件。我需要更改某个设置吗?

   val workers = context.actorOf(Props[ItemProcessingWorker].withRouter(RoundRobinRouter(nworkers)))

更新:我试图通过编程方式发送params ..仍然无法正常工作。

    val conf1 = ConfigFactory.load(ConfigFactory.parseString("""
 akka {
  default-dispatcher {
    # Dispatcher is the name of the event-based dispatcher
    type = Dispatcher
    # What kind of ExecutionService to use
    executor = "fork-join-executor"
    # Configuration for the fork join pool
    fork-join-executor {
      # Min number of threads to cap factor-based parallelism number to
      parallelism-min = 32
      # Parallelism (threads) ... ceil(available processors * factor)
      parallelism-factor = 1.0
      # Max number of threads to cap factor-based parallelism number to
      parallelism-max = 32
    }
    # Throughput defines the maximum number of messages to be
    # processed per actor before the thread jumps to the next actor.
    # Set to 1 for as fair as possible.
    throughput = 1000
  }}

 """))
 val system = ActorSystem("MySystem2",conf1)

2 个答案:

答案 0 :(得分:0)

resources/application.conf尝试更改default-dispatcher

的值
akka {
      default-dispatcher {
        # Dispatcher is the name of the event-based dispatcher
        type = Dispatcher
        # What kind of ExecutionService to use
        executor = "fork-join-executor"
        # Configuration for the fork join pool
        fork-join-executor {
          # Min number of threads to cap factor-based parallelism number to
          parallelism-min = 16
          # Parallelism (threads) ... ceil(available processors * factor)
          parallelism-factor = 2.0
          # Max number of threads to cap factor-based parallelism number to
          parallelism-max = 32
        }
        # Throughput defines the maximum number of messages to be
        # processed per actor before the thread jumps to the next actor.
        # Set to 1 for as fair as possible.
        throughput = 20
      }
}

答案 1 :(得分:0)

好的,我解决了这个问题,我错过了一个子配置 而不是

akka {
  default-dispatcher {
    type = Dispatcher
    executor = "thread-pool-executor"
    throughput = 1000    
    fork-join-executor {
      parallelism-min = 32
      parallelism-factor = 0.5
      parallelism-max = 64
    }
  }
}

应该是

akka {
  actor{
    default-dispatcher {
      type = Dispatcher
      executor = "thread-pool-executor"
      throughput = 1000    
      fork-join-executor {
        parallelism-min = 32
        parallelism-factor = 0.5
        parallelism-max = 64
      }
    }
  }
}