diff --git a/src/RocksDb.Extensions/RocksDbContext.cs b/src/RocksDb.Extensions/RocksDbContext.cs index ed16f9e..41a2bd2 100644 --- a/src/RocksDb.Extensions/RocksDbContext.cs +++ b/src/RocksDb.Extensions/RocksDbContext.cs @@ -45,6 +45,8 @@ public RocksDbContext(IOptions options) dbOptions.IncreaseParallelism(Math.Max(Environment.ProcessorCount, 2)); dbOptions.SetCreateIfMissing(); dbOptions.SetCreateMissingColumnFamilies(); + dbOptions.SetUseDirectReads(options.Value.UseDirectReads); + dbOptions.SetUseDirectIoForFlushAndCompaction(options.Value.UseDirectIoForFlushAndCompaction); var fOptions = new FlushOptions(); fOptions.SetWaitForFlush(true); diff --git a/src/RocksDb.Extensions/RocksDbOptions.cs b/src/RocksDb.Extensions/RocksDbOptions.cs index 3f55cf2..da9c9d3 100644 --- a/src/RocksDb.Extensions/RocksDbOptions.cs +++ b/src/RocksDb.Extensions/RocksDbOptions.cs @@ -32,4 +32,33 @@ public class RocksDbOptions public List SerializerFactories { get; } = new(); internal List ColumnFamilies { get; } = new(); + + /// + /// Enables direct I/O mode for reads, which bypasses the OS page cache. + /// + /// + /// When enabled, RocksDB will open files in “direct I/O” mode, meaning data read from disk will not be cached or buffered + /// by the operating system. This can reduce double-buffering and improve performance in specific scenarios, + /// though actual impact depends on the hardware and access patterns. + /// + /// Note that memory-mapped files are not affected by this setting. Hardware buffers may still be used. + /// + /// The default value is false. + /// + public bool UseDirectReads { get; set; } = false; + + + /// + /// Enables direct I/O mode for flush and compaction operations. + /// + /// + /// When enabled, RocksDB will open files in “direct I/O” mode during flush and compaction. + /// This means that data written to disk will bypass the OS page cache, avoiding extra buffering by the operating system. + /// This can potentially improve performance in some scenarios, especially when double-buffering is a concern. + /// + /// Memory-mapped files are not impacted by this setting. Hardware-level buffering may still apply. + /// + /// The default value is false. + /// + public bool UseDirectIoForFlushAndCompaction { get; set; } = false; } \ No newline at end of file