Unverified Commit 8876d264 authored by zhaozhao.zz's avatar zhaozhao.zz Committed by GitHub
Browse files

Calculate the incremental rehash time more precisely (#13063)

In the `databasesCron()`, the time consumed by
`kvstoreIncrementallyRehash()` is used to calculate the exit condition.
However, within `kvstoreIncrementallyRehash()`, the loop first checks
for timeout before performing rehashing. Therefore, the time for the
last rehash isn't accounted for, making the consumed time inaccurate. We
need to precisely calculate all the time spent on rehashing.
Additionally, the time allocated to `kvstoreIncrementallyRehash()`
should be the remaining time, which is
`INCREMENTAL_REHASHING_THRESHOLD_US` minus the already consumed
`elapsed_us`.
parent 9103ccc3
...@@ -615,16 +615,16 @@ uint64_t kvstoreIncrementallyRehash(kvstore *kvs, uint64_t threshold_us) { ...@@ -615,16 +615,16 @@ uint64_t kvstoreIncrementallyRehash(kvstore *kvs, uint64_t threshold_us) {
* after each dictionary completes rehashing, it removes itself from the list. */ * after each dictionary completes rehashing, it removes itself from the list. */
listNode *node; listNode *node;
monotime timer; monotime timer;
uint64_t elapsed_us = UINT64_MAX; uint64_t elapsed_us = 0;
elapsedStart(&timer); elapsedStart(&timer);
while ((node = listFirst(kvs->rehashing))) { while ((node = listFirst(kvs->rehashing))) {
dictRehashMicroseconds(listNodeValue(node), threshold_us - elapsed_us);
elapsed_us = elapsedUs(timer); elapsed_us = elapsedUs(timer);
if (elapsed_us >= threshold_us) { if (elapsed_us >= threshold_us) {
break; /* Reached the time limit. */ break; /* Reached the time limit. */
} }
dictRehashMicroseconds(listNodeValue(node), threshold_us - elapsed_us);
} }
assert(elapsed_us != UINT64_MAX);
return elapsed_us; return elapsed_us;
} }
......
...@@ -1093,10 +1093,10 @@ void databasesCron(void) { ...@@ -1093,10 +1093,10 @@ void databasesCron(void) {
uint64_t elapsed_us = 0; uint64_t elapsed_us = 0;
for (j = 0; j < dbs_per_call; j++) { for (j = 0; j < dbs_per_call; j++) {
redisDb *db = &server.db[rehash_db % server.dbnum]; redisDb *db = &server.db[rehash_db % server.dbnum];
elapsed_us += kvstoreIncrementallyRehash(db->keys, INCREMENTAL_REHASHING_THRESHOLD_US); elapsed_us += kvstoreIncrementallyRehash(db->keys, INCREMENTAL_REHASHING_THRESHOLD_US - elapsed_us);
if (elapsed_us >= INCREMENTAL_REHASHING_THRESHOLD_US) if (elapsed_us >= INCREMENTAL_REHASHING_THRESHOLD_US)
break; break;
elapsed_us += kvstoreIncrementallyRehash(db->expires, INCREMENTAL_REHASHING_THRESHOLD_US); elapsed_us += kvstoreIncrementallyRehash(db->expires, INCREMENTAL_REHASHING_THRESHOLD_US - elapsed_us);
if (elapsed_us >= INCREMENTAL_REHASHING_THRESHOLD_US) if (elapsed_us >= INCREMENTAL_REHASHING_THRESHOLD_US)
break; break;
rehash_db++; rehash_db++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment