How to solve OutOfMemoryError: Direct buffer memory




I’m using AsyncClient for inserting data into aerospike ( concurrent records - 1000 ) and after inserting some records im getting below error java.lang.OutOfMemoryError: Direct buffer memory at java.nio.Bits.reserveMemory( at java.nio.DirectByteBuffer.( at java.nio.ByteBuffer.allocateDirect( at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.( at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.( at com.aerospike.client.async.AsyncCluster.( at com.aerospike.client.async.AsyncClient.( at com.aerospike.client.async.AsyncClient.(

Can any one help me how to solve above error and what all client configuration needs to solve this problem? muraliewn


AsyncClient allocates a command buffer for each concurrent command. The jvm is apparently unable find any more contiguous system memory blocks for these buffers. First some questions:

  1. How many times are you instantiating AsyncClient? Multiple instances of AsyncClient will allocate multiple sets of command buffers which will use too much memory. AsyncClient should be instantiated only once and the instance should be shared across threads.

  2. What is the size of the records you are inserting? The command buffers will be resized to fit the record. Large records will consume large amounts of memory.

Other comments:

  1. asyncMaxCommands (1000) is very high. I suggest setting asyncMaxCommands to 50 until memory is under control.

  2. Since these buffers are DirectByteBuffer (OS level memory), it’s possible they are not getting released promptly by the OS after dropping out of scope in the java program. This combined with 1) or 2) is probably the source of your problem.


Hi Thank you very much, its working fine.