Create a thread in DeleteScheduler only when rate limit enabled (#6564)
Summary: Create a thread in DeleteScheduler only when delete rate limit is set because when there is no rate limit on deletion, a thread per DeleteScheduler consumes unnecessary resources. Test Plan: make -j64 check Reviewed By: riversand963 Differential Revision: D20538138 Pulled By: akankshamahajan15 fbshipit-source-id: 137499e810e817156345c30d627f8678b9adadf7
This commit is contained in:
parent
a6ce5c823b
commit
ceeca7542d
@ -32,13 +32,13 @@ DeleteScheduler::DeleteScheduler(Env* env, FileSystem* fs,
|
||||
bytes_max_delete_chunk_(bytes_max_delete_chunk),
|
||||
closing_(false),
|
||||
cv_(&mu_),
|
||||
bg_thread_(nullptr),
|
||||
info_log_(info_log),
|
||||
sst_file_manager_(sst_file_manager),
|
||||
max_trash_db_ratio_(max_trash_db_ratio) {
|
||||
assert(sst_file_manager != nullptr);
|
||||
assert(max_trash_db_ratio >= 0);
|
||||
bg_thread_.reset(
|
||||
new port::Thread(&DeleteScheduler::BackgroundEmptyTrash, this));
|
||||
MaybeCreateBackgroundThread();
|
||||
}
|
||||
|
||||
DeleteScheduler::~DeleteScheduler() {
|
||||
@ -352,6 +352,13 @@ void DeleteScheduler::WaitForEmptyTrash() {
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteScheduler::MaybeCreateBackgroundThread() {
|
||||
if(bg_thread_ == nullptr && rate_bytes_per_sec_.load() > 0) {
|
||||
bg_thread_.reset(
|
||||
new port::Thread(&DeleteScheduler::BackgroundEmptyTrash, this));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
|
||||
#endif // ROCKSDB_LITE
|
||||
|
@ -45,6 +45,7 @@ class DeleteScheduler {
|
||||
// Set delete rate limit in bytes per second
|
||||
void SetRateBytesPerSecond(int64_t bytes_per_sec) {
|
||||
rate_bytes_per_sec_.store(bytes_per_sec);
|
||||
MaybeCreateBackgroundThread();
|
||||
}
|
||||
|
||||
// Mark file as trash directory and schedule it's deletion. If force_bg is
|
||||
@ -91,6 +92,8 @@ class DeleteScheduler {
|
||||
|
||||
void BackgroundEmptyTrash();
|
||||
|
||||
void MaybeCreateBackgroundThread();
|
||||
|
||||
Env* env_;
|
||||
FileSystem* fs_;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user