simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.

Home Page:https://swaydb.simer.au

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement `BlockCacheSkipListIO`

simerplaha opened this issue · comments

commented

Overview

Currently BlockCacheIO caches byte arrays in equal sizes of blockSize/minIOSeekSize each. This provides faster HashMap inserts and lookups since keys themselves are just Long values (unique and no hash conflicts) but

  • It has the cost of needing to join multiple Array[Byte] if the required data is greater than minIOSeekSize.
  • Need multiple ConcurrentHashMap lookups if the required data is greater than minIOSeekSize.
  • Synchronised - java.nio.ScatteringByteChannel already provides an API which slices the data into smaller Array[Byte]s of minIOSeekSize each (so not in-memory slicing/copying is required) but this API still needs synchronised (blocking) access since ScatteringByteChannel mutates the position in the FileChannel.
  • Synchronised can be removed by not using ScatteringByteChannel and slicing data manually in-memory but this creates a lot more on-heap allocations which costs GC time.

Task

Another BlockCacheSkipListIO based on ConcurrentSkipList is required which allows caching randomly sized data. This will not need synchronised access and will provide easier caching but in comparison to ConcurrentHashMap, inserts and lookups will be slower which in some cases might not be noticeable since multiple lookups to join multiple byte arrays (in ConcurrentHashMap's cases) might not be required.

Configuration

Either one of the caching strategy should be configurable.