【问题标题】:Akka - java.util.concurrent.timeoutexception - frequent timeouts with thread poolAkka - java.util.concurrent.timeoutexception - 线程池频繁超时
【发布时间】:2018-12-01 13:57:44
【问题描述】:

当我在使用 akka 同步参与者的 API 上运行负载测试时(使用超时 20 秒的询问模式,代码如下 sn-p),API 调用一个微服务,该微服务与 Oracle DB 交互以进行获取操作。

但是在负载测试期间(每秒 100 个请求)我看到很多超时异常,并且在外部微服务和 Oracle 中都没有看到任何错误。 使用 fork join 执行器时,故障很少,但使用线程池执行器时,我看到经常发生故障。

代码sn-p:

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 config(Fork 加入执行器):

    "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"
  },

【问题讨论】:

标签: java oracle akka microservices


【解决方案1】:

根据我对阻塞操作的理解,您需要具有吞吐量为 1 的固定线程池。如果您想并行执行此操作,那么您可以配置一个带有多个子角色的 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)

【讨论】:

    猜你喜欢
    • 2011-10-14
    • 2018-08-29
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 2013-08-08
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多