SwayDB
SwayDB copied to clipboard
Use ScatterByteChannel's read when reading files from BlockCache
Overview
The amount of bytes read per disk seek can be configured with blockSize which defaults to 4098 bytes.
If more than 4098 bytes are required by a read request then 4098 * n are read where n is an Int >= 1.
Issue & Solution
Currently all bytes are read into a single ByteBuffer and then an in-memory split is performed by the BlockCache to divide the bytes into the configured blockSize sized chunks. This adds extra step for each read which is unnecessary because java.nio.ScatterByteChannel already provides an API to read chunked ByteBuffers.
Advantage
Reduces GC allocations for read IO.