Summary: This diff added an option to control the incremenal sync frequency. db_bench has a new flag bytes_per_sync for easy tuning exercise.
Test Plan: make check; db_bench
Reviewers: dhruba
CC: leveldb
Differential Revision: https://reviews.facebook.net/D11295
static auto FLAGS_use_adaptive_mutex =
leveldb::Options().use_adaptive_mutex;
+// Allows OS to incrementally sync files to disk while they are being
+// written, in the background. Issue one request for every bytes_per_sync
+// written. 0 turns it off.
+static auto FLAGS_bytes_per_sync =
+ leveldb::Options().bytes_per_sync;
+
namespace leveldb {
// Helper for quickly generating random data.
options.access_hint_on_compaction_start = FLAGS_compaction_fadvice;
options.use_adaptive_mutex = FLAGS_use_adaptive_mutex;
+ options.bytes_per_sync = FLAGS_bytes_per_sync;
Status s;
if(FLAGS_read_only) {
} else if (sscanf(argv[i], "--keys_per_multiget=%d%c",
&n, &junk) == 1) {
FLAGS_keys_per_multiget = n;
+ } else if (sscanf(argv[i], "--bytes_per_sync=%ld%c", &l, &junk) == 1) {
+ FLAGS_bytes_per_sync = l;
} else {
fprintf(stderr, "Invalid flag '%s'\n", argv[i]);
exit(1);
// If true, set the FD_CLOEXEC on open fd.
bool set_fd_cloexec;
+ // Allows OS to incrementally sync files to disk while they are being
+ // written, in the background. Issue one request for every bytes_per_sync
+ // written. 0 turns it off.
+ // Default: 0
+ uint64_t bytes_per_sync;
+
};
class Env {
// Default: false
bool use_adaptive_mutex;
+ // Allows OS to incrementally sync files to disk while they are being
+ // written, asynchronously, in the background.
+ // Issue one request for every bytes_per_sync written. 0 turns it off.
+ // Default: 0
+ uint64_t bytes_per_sync;
+
};
// Options that control read operations
env_options->use_mmap_reads = options.allow_mmap_reads;
env_options->use_mmap_writes = options.allow_mmap_writes;
env_options->set_fd_cloexec = options.is_fd_close_on_exec;
+ env_options->bytes_per_sync = options.bytes_per_sync;
}
}
bool pending_sync_;
bool pending_fsync_;
uint64_t last_sync_size_;
+ uint64_t bytes_per_sync_;
public:
PosixWritableFile(const std::string& fname, int fd, size_t capacity,
filesize_(0),
pending_sync_(false),
pending_fsync_(false),
- last_sync_size_(0) {
+ last_sync_size_(0),
+ bytes_per_sync_(options.bytes_per_sync) {
assert(!options.use_mmap_writes);
}
}
cursize_ = 0;
- // sync OS cache to disk for every 2MB written
- if (filesize_ - last_sync_size_ >= 2 * 1024 * 1024) {
+ // sync OS cache to disk for every bytes_per_sync_
+ // TODO: give log file and sst file different options (log
+ // files could be potentially cached in OS for their whole
+ // life time, thus we might not want to flush at all).
+ if (bytes_per_sync_ &&
+ filesize_ - last_sync_size_ >= bytes_per_sync_) {
RangeSync(last_sync_size_, filesize_ - last_sync_size_);
last_sync_size_ = filesize_;
}
block_size_deviation (10),
advise_random_on_open(true),
access_hint_on_compaction_start(NORMAL),
- use_adaptive_mutex(false) {
+ use_adaptive_mutex(false),
+ bytes_per_sync(0) {
}
static const char* const access_hints[] = {
access_hints[access_hint_on_compaction_start]);
Log(log," Options.use_adaptive_mutex: %d",
use_adaptive_mutex);
+ Log(log," Options.bytes_per_sync: %ld",
+ bytes_per_sync);
} // Options::Dump
//