Akka-java.util.concurrent.timeoutexception-线程池频繁超时

时间:2018-06-22 06:35:52

标签: java oracle akka microservices

当我在使用akka sync actor的API上运行负载测试(使用20秒超时的询问模式,下面的代码段)时,该API会调用一个微服务,该微服务与Oracle DB进行交互以进行get操作。

但是在负载测试期间(每秒100个请求),我看到很多超时异常,并且在外部微服务和Oracle中都没有看到任何错误。 使用fork join executor时,失败非常少,但是使用线程池执行程序,我会看到频繁的失败。

代码段:

Timeout timeout = new Timeout(Duration.create(interaction.getActorTimeOut(), TimeUnit.SECONDS));
Future<Object> future = Patterns.ask(ipsActorSystem.synchronousActor, interactionRequest, timeout);
Object result =  Await.result(future, timeout.duration());

akka配置(叉加入执行器):

    "default-dispatcher": {
      "attempt-teamwork": "on",
      "default-executor": {
      "fallback": "fork-join-executor"
    },
    "executor": "fork-join-executor",
    "fork-join-executor": {
      "parallelism-factor": 50,
      "parallelism-max": 100,
      "parallelism-min": 10,
      "task-peeking-mode": "FIFO"
    },
    "mailbox-requirement": "",
    "shutdown-timeout": "1s",
    "throughput": 100,
    "throughput-deadline-time": "0ms",
    "type": "Dispatcher"
  },

线程池执行程序:

 "default-dispatcher": {
      "attempt-teamwork": "on",
      "default-executor": {
      "fallback": "thread-pool-executor"
    },
    "executor": "thread-pool-executor",
    "thread-pool-executor": {
        "fixed-pool-size" : 10
    },
    "mailbox-requirement": "",
    "shutdown-timeout": "1s",
    "throughput": 10,
    "throughput-deadline-time": "0ms",
    "type": "Dispatcher"
  },

1 个答案:

答案 0 :(得分:0)

据我了解,对于阻塞操作,您需要具有吞吐量为1的固定线程池。如果要并行执行此操作,则可以配置具有多个子actor的Robin Robin池路由器。 像这样

val synchronousActor: ActorRef =  context.actorOf(RoundRobinPool(numOfInstances).props(SynchronousActor.props(
config)), SynchronousActor.name)

您可以这样称呼

val reqF = (synchronousActor ? InteractionRequest).mapTo[ReturnType]
val result = Await.result(reqF, timeout)

或者您可以使用此人的建议 (https://github.com/alexandru/scala-best-practices/blob/master/sections/4-concurrency-parallelism.md#46-should-use-a-separate-thread-pool-for-blocking-io