simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.
https://swaydb.simer.au
Apache License 2.0
293 stars 16 forks source link

Creating Off-heap bytes and objects #284

Open simerplaha opened 4 years ago

simerplaha commented 4 years ago

Having the ability to directly allocate objects and byte-arrays off heap would be a major improvement.

If cacheSegmentBlocksOnCreate is disabled then compaction bytes can be discarded immediately skipping the JVMs GC. The same also applies to objects created during compaction.

JDK-16 has Foreign-Memory Access API but this is still far away and we need to support Java8.

simerplaha commented 3 years ago

Foreign-memory access API although in incubation is actually a well tested API since Java 14. Another option is to use sun.misc.Unsafe if Java 8 builds are important for us.

After running some tests the overall database performance would triple if moved off-heap for all byte arrays. On a very heavy & concurrent write and read workload a little over 60% of total data sitting on heap is byte[]. Moving all Slice[Byte] off-heap would be a major performance advantage.

dabayliss commented 3 years ago

Are you testing with J8 (which is EOL in 4 months) or J11 ? The J11 heap is MUCH better

simerplaha commented 3 years ago

Are you testing with J8 (which is EOL in 4 months) or J11?

J8 up until now. I didn't know about the EOL. Thanks for letting me know.

The J11 heap is MUCH better

You are right, seems like J11's heap has improved. I will run some tests on J11 soon.