akka/akka-core

akka io DirectByteBufferPool improvements

Aberta

#25.356 aberto em 16 de jul. de 2018

 (8 comentários) (0 reação) (0 responsável)Scala (3.547 forks)batch import
1 - triagedhelp wantednice-to-have (low-prio)t:coret:remoting:artery

Métricas do repositório

Stars
 (13.277 estrelas)
Métricas de merge de PR
 (Mesclagem média 8d 19h) (10 fundiu PRs em 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

Guia do colaborador