Closed liran-funaro closed 2 years ago
Excuse me. I have some questions about the oak shared config. I used to think that all oakMaps created by one OakMapBuilder could share the same BlockMempryAllocator, but the current design doesn't. I think that current design brings a probelm. When I use the same OakMapBuilder to create thousands of OakMaps in a multi-threaded environment, the BlockMemoryAllocator will be instantiated multiple times. At the same time, the problem is that thousands of 128M Block will be created in multi-threaded environment, and soon the memory is exhausted.
Could all oakMap created by one OakMapBuilder share the same BlockMempryAllocator? Because in real production, it is quit frequent to create thousands of OakMaps in a multi-threaded environment.
Hi @fujian-zfj
Thanks for your valuable suggestion. Indeed, we currently have one NativeMemoryAllocator
per OakHash
or OakMap
instance. All memory allocators are using off-heap memory blocks from the same pool. It is possible to make the Oak instances to share same NativeMemoryAllocator
(which is multi-threaded), but code needs to be upfated during closing, so closing one Oak instance doesn't close allocator for all others. Also too many Oak instances per memory allocator can cause threads contention and decrease the performance.
Anyway, in your case, a possible solution can be to decrease the block size. Use builder.setPreferredBlockSize()
before any Oak instance is initiated.
Alternatively, if you would like to contribute some code to Oak, we can guide you to make the change yourself. You can get direct and clear instructions what needs to be done, code review and etc. This is also a possibility :)
fixes #194
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.