使用缓冲式IO的时候,数据会在存储介质和内存间被缓存和拷贝两次
- 使用直接IO:
//struct DBOptions
// Use O_DIRECT for user reads
// Default: false
bool use_direct_reads = false;
// Use O_DIRECT for both reads and writes in background flush and compactions
// When true, we also force new_table_reader_for_compaction_inputs to true.
// Default: false
bool use_direct_io_for_flush_and_compaction = false;
- 其它选项来优化直接IO的性能:
// options.h
// Option to enable readahead in compaction
// If not set, it will be set to 2MB internally
size_t compaction_readahead_size = 2 * 1024 * 1024; // recommend at least 2MB
// Option to tune write buffer for direct writes
size_t writable_file_max_buffer_size = 1024 * 1024; // 1MB by default
- 用户API还是同步的,但是在使用Iterator或者MultiGet方法时,后台线程异步预取数据,减小后续的读取延迟
ReadOptions opts;
opts.async_io = true;
- 在用户调用Next时,由FilePrefetchBuffer来控制预取数据,在第三次读取同一SST文件开始,初始预取大小为8KB,在每次读取时将其加倍,最大可达256KB。
- compaction_readahead_size: SSD盘建议设置为2097152