Reduce iterator deletion overhead

Summary:
After introducing Iterator::PinData(), we have extra overhead of deleting the pinned iterators that we track in a std::set
This patch avoid inserting to the std::set if we have only one iterator (normal use case when no iterators are pinned)

Before this change
```
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="newiterator" --db="/tmp/rocksdbtest-8616/dbbench" --use_existing_db --disable_auto_compactions
newiterator  :       1.006 micros/op 994013 ops/sec;
newiterator  :       0.994 micros/op 1006295 ops/sec;
newiterator  :       0.990 micros/op 1010422 ops/sec;
```

After change

```
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="newiterator" --db="/tmp/rocksdbtest-8616/dbbench" --use_existing_db --disable_auto_compactions
newiterator  :       0.754 micros/op 1326588 ops/sec;
newiterator  :       0.759 micros/op 1317394 ops/sec;
newiterator  :       0.691 micros/op 1446704 ops/sec;
```

Test Plan: make check -j64

Reviewers: yhchiang, rven, anthony, sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D52761
This commit is contained in:
Islam AbdelRahman 2016-01-11 16:48:15 -08:00
parent 45d794068c
commit d9bca1e14c

View File

@ -94,20 +94,9 @@ class IteratorWrapper {
return iters_pinned_ && iter_->IsKeyPinned();
}
void DeletePinnedIterators(bool is_arena_mode) {
for (auto it : pinned_iters_) {
if (!is_arena_mode) {
delete it;
} else {
it->~InternalIterator();
}
}
pinned_iters_.clear();
}
void DeleteIter(bool is_arena_mode) {
if (iter_) {
pinned_iters_.insert(iter_);
if (iter_ && pinned_iters_.find(iter_) == pinned_iters_.end()) {
DestroyIterator(iter_, is_arena_mode);
}
DeletePinnedIterators(is_arena_mode);
}
@ -132,6 +121,21 @@ class IteratorWrapper {
}
}
void DeletePinnedIterators(bool is_arena_mode) {
for (auto it : pinned_iters_) {
DestroyIterator(it, is_arena_mode);
}
pinned_iters_.clear();
}
inline void DestroyIterator(InternalIterator* it, bool is_arena_mode) {
if (!is_arena_mode) {
delete it;
} else {
it->~InternalIterator();
}
}
InternalIterator* iter_;
// If set to true, current and future iterators wont be deleted.
bool iters_pinned_;