akka/akka-core

akka io DirectByteBufferPool improvements

开放

#25,356 创建于 2018年7月16日

 (8 条评论) (0 个反应) (0 位负责人)Scala (3,547 个派生)batch import
1 - triagedhelp wantednice-to-have (low-prio)t:coret:remoting:artery

仓库指标

星标
 (13,277 个星标)
PR 合并指标
 (平均合并 8天 19小时) (30 天内合并 10 个 PR)

描述

When putting under heavy network load the akka io stack, profiling shows that quite some time is lost blocking into the akka.io.DirectByteBufferPool class especially these blocks of code :

private final def takeBufferFromPool(): ByteBuffer = {
    val buffer = pool.synchronized {
      if (buffersInPool > 0) {
        buffersInPool -= 1
        pool(buffersInPool)
      } else null
    }
...
  }
private final def offerBufferToPool(buf: ByteBuffer): Unit = {
    val clean =
      pool.synchronized {
        if (buffersInPool < maxPoolEntries) {
          pool(buffersInPool) = buf
          buffersInPool += 1
          false
        } else {
     ...
        }
  }

The locks over the pool array on borrow and return are causing this problem and secondly. A more efficient almost lock free implementation could be done, I'm not unfortunatly coding scala but would do it easily in java. Another nice improvement would be to provide also a configuration option in akka.io to instruct each io connection to uses its own bytes buffer pool instead of the shared one, it would allow a complete lock free implementation since no concurrent access would be done trough the tcp connection io actor. Finally another configuration option to implement your own direct byte buffer pool implementation would also be a nice feature (to implement shared buffers pools with other libs such as netty when both are running in the same jvm)

Regards

Cedric

贡献者指南