1、WriteOptions如何设置写性能才高?
在写入数据时,即调用Put和Delete接口时,我们需要传入一个WriteOptions类型的参数,例如Put接口如下:
Status Put(const WriteOptions& options, const Slice& key, const Slice& value);
WriteOptions参数该如何设置呢?我们看它的定义:
// Options that control write operations
struct LEVELDB_EXPORT WriteOptions {
WriteOptions() = default;
// If true, the write will be flushed from the operating system
// buffer cache (by calling WritableFile::Sync()) before the write
// is considered complete. If this flag is true, writes will be
// slower.
//
// If this flag is false, and the machine crashes, some recent
// writes may be lost. Note that if it is just the process that
// crashes (i.e., the machine does not reboot), no writes will be
// lost even if sync==false.
//
// In other words, a DB write with sync==false has similar
// crash semantics as the