akka/akka-core

akka io DirectByteBufferPool improvements

Open

#25,356 opened on Jul 16, 2018

View on GitHub
 (8 comments) (0 reactions) (0 assignees)Scala (3,547 forks)batch import
1 - triagedhelp wantednice-to-have (low-prio)t:coret:remoting:artery

Repository metrics

Stars
 (13,277 stars)
PR merge metrics
 (Avg merge 8d 19h) (10 merged PRs in 30d)

Description

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

Contributor guide