memory leak PowerOfTwoBufferPool class

1,888 views
Skip to first unread message

tommy li

unread,
Dec 11, 2019, 2:44:28 PM12/11/19
to mongodb-user
Version: 3.10.2
Class:com.mongodb.internal.connection.PowerOfTwoBufferPool
Issue Type : memory leak, the memory of the object can not release.
Description: After Java application running on the server for a week, it was found that the PowerOfTwoBufferPool object occupied memory could not be released.

I use Jprofile.  attach file is Jprofile result



test.png

Kevin Adistambha

unread,
Dec 12, 2019, 6:13:54 PM12/12/19
to mongodb-user

Hi,

To investigate this issue, do you mind opening a ticket in the Java driver Jira project with all the relevant information? It would be helpful if you can also provide the code that can induce this behaviour.

Best regards,
Kevin

Kevin Adistambha

unread,
Dec 15, 2019, 7:34:16 PM12/15/19
to mongodb-user

Hi,

I did some digging about PowerOfTwoBufferPool and have found that this behaviour is expected since PowerOfTwoBufferPool is a cache. Hence it may look like a leak.

In short, the PowerOfTwoBufferPool holds a number of pools of ByteBuffer instances, each pool containing a set of equal-sized buffers. The smallest size is 1K, and the largest is 16MB, incrementing in power of two sizes from 1K to 16MB. The size of each pool of equal-sized buffers is not limited, and is determined by application usage. Once a buffer is cached in a pool, it remains pooled (or in-use) until the MongoClient is closed. As a result, it’s totally expected that during introspection of JVM state, the contents of the pools would show as a leak suspect, just as any cache would.

The PowerOfTwoBufferPool exists in order to reduce GC load. It’s fairly well known that modern garbage collectors in the JVM treat large allocations differently from smaller ones, so if an application were to not do any pooling of large objects (like these buffers) it will have the effect of increasing GC load, because the garbage collector has to do more work collecting these large objects than it does smaller ones. The cost of this is that the driver holds on to memory that could be used by other parts of the application. In particular, it holds on to enough memory to handle the largest peak load seen so far by the application.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages