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

貢獻者指南