分析了下mongodb的BsonChunkPool占用了大量内存,
找到一篇文章
The BsonChunkPool
exists so that large memory buffers (chunks) can be reused, thus easing the amount of work the garbage collector has to do.
Initially the pool is empty, but as buffers are returned to the pool the pool is no longer empty. Whatever memory is held in the pool will not be garbage collected. This is by design. That memory is intended to be reused. This is not a memory leak.
The default configuration of the BsonChunkPool
is such that it can hold a maximum of 8192 chunks of 64KB each, so if the pool were to grow to its maximum size it would use 512MB of memory (even more than the 7 or 35 MB you are observing).
If for some reason you don‘t want the BsonChunkPool
to use that much memory, you can configure it differently by putting the following statement at the beginning of your application:
BsonChunkPool.Default = new BsonChunkPool(16, 64 * 1024); // e.g. max 16 chunks of 64KB each, for a total of 1MB
We haven‘t experimented with different values for chunk counts and sizes so if you do decide to change the default BsonChunkPool
configuration you should do some benchmarking and verify that it doesn‘t have an adverse impact on your performance.
From jira: BsonChunkPool and memory leak