How to solve OutOfMemoryError: Direct buffer memory

buffer

#1

Hi,

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(Bits.java:658) at java.nio.DirectByteBuffer.(DirectByteBuffer.java:123) at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306) at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.(AsyncCluster.java:111) at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.(AsyncCluster.java:104) at com.aerospike.client.async.AsyncCluster.(AsyncCluster.java:59) at com.aerospike.client.async.AsyncClient.(AsyncClient.java:140) at com.aerospike.client.async.AsyncClient.(AsyncClient.java:112)

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


#2

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.


#3

Hi Thank you very much, its working fine.