This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 46862ea5 Avoid Write calls when SIADD added_cnt is 0 (#1577)
46862ea5 is described below
commit 46862ea559976d50ba6996942f2c962774dfc5e9
Author: Binbin <[email protected]>
AuthorDate: Wed Jul 12 10:29:00 2023 +0800
Avoid Write calls when SIADD added_cnt is 0 (#1577)
This may improve performance by 40% in certain cases.
Simple benchmarks:
```
src/redis-benchmark -p 6666 -P 100 -n 100000 siadd key 1 2 3
```
Before is 95057.03 requests per second.
After is 135135.14 requests per second.
---
src/types/redis_sortedint.cc | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/types/redis_sortedint.cc b/src/types/redis_sortedint.cc
index 5c7883a7..ab8b8a2d 100644
--- a/src/types/redis_sortedint.cc
+++ b/src/types/redis_sortedint.cc
@@ -57,12 +57,13 @@ rocksdb::Status Sortedint::Add(const Slice &user_key, const
std::vector<uint64_t
batch->Put(sub_key, Slice());
*added_cnt += 1;
}
- if (*added_cnt > 0) {
- metadata.size += *added_cnt;
- std::string bytes;
- metadata.Encode(&bytes);
- batch->Put(metadata_cf_handle_, ns_key, bytes);
- }
+
+ if (*added_cnt == 0) return rocksdb::Status::OK();
+
+ metadata.size += *added_cnt;
+ std::string bytes;
+ metadata.Encode(&bytes);
+ batch->Put(metadata_cf_handle_, ns_key, bytes);
return storage_->Write(storage_->DefaultWriteOptions(),
batch->GetWriteBatch());
}