Reduce active defrag test latency by lowering hit threshold#2553
Conversation
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #2553 +/- ##
============================================
+ Coverage 72.04% 72.23% +0.19%
============================================
Files 126 126
Lines 70615 70619 +4
============================================
+ Hits 50872 51015 +143
+ Misses 19743 19604 -139
🚀 New features to boost your workflow:
|
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
JimB123
left a comment
There was a problem hiding this comment.
Looks good. I agree that we should check the time after every defrag hit. The time check is negligible in cost, and is small compared with the defragmentation itself - which is variable depending on block size.
In any case, it's worth noting that the old logic is strange. It allowed for 512 actual defragmentations, while only allowing for 64 scans (a check without defragmentation).
re: lowering the latency check back to 5ms. If we see additional failures, we should consider that they might be due to OS scheduling. We can consider checking the main-thread's CPU time rather than elapsed clock time.
JimB123
left a comment
There was a problem hiding this comment.
(note we need to address the compilation issue)
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
zuiderkwast
left a comment
There was a problem hiding this comment.
LGTM!
To check if it gets flaky with 5 ms, I kicked off a daily job for this PR: https://github.com/valkey-io/valkey/actions/runs/17310428082
…o#2553) Changed the defrag hit threshold from 512 to 1 in the `defragLaterStep` & `defragStageKvstoreHelper` function to reduce defrag latency. (idea from Jim) 1. Previously, the defrag loop would continue processing up to 512 successful defragmentations before checking if the time limit was exceeded. Now it checks after every single successful allocation move. 2. The trade-off is slightly more frequent time checks, but the time check (~19ns) is negligible compared to the actual defragmentation work (even a single 8-byte reallocation takes ~43ns and the allocatorShouldDefrag function call takes ~49ns per block). This overhead is minimal compared to the latency improvement gained from better time management during active defragmentation. 3. Also revert the change from https://github.com/valkey-io/valkey/pull/2421/files to test. 4. Solved compilation issue with unsigned by changing the type of the local variable `prev_defragged `to match the type of `server.stat_active_defrag_hits` Closes valkey-io#2444 --------- Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
…40 (valkey-io#2574) Delete the out-of-date comment explaining why changed latency from 5 to 40 in valkey-io#2421 , which is a leftover of valkey-io#2553 Signed-off-by: Alina Liu <liusalisa6363@gmail.com>
Changed the defrag hit threshold from 512 to 1 in the `defragLaterStep` & `defragStageKvstoreHelper` function to reduce defrag latency. (idea from Jim) 1. Previously, the defrag loop would continue processing up to 512 successful defragmentations before checking if the time limit was exceeded. Now it checks after every single successful allocation move. 2. The trade-off is slightly more frequent time checks, but the time check (~19ns) is negligible compared to the actual defragmentation work (even a single 8-byte reallocation takes ~43ns and the allocatorShouldDefrag function call takes ~49ns per block). This overhead is minimal compared to the latency improvement gained from better time management during active defragmentation. 3. Also revert the change from https://github.com/valkey-io/valkey/pull/2421/files to test. 4. Solved compilation issue with unsigned by changing the type of the local variable `prev_defragged `to match the type of `server.stat_active_defrag_hits` Closes #2444 --------- Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
…o#2553) Changed the defrag hit threshold from 512 to 1 in the `defragLaterStep` & `defragStageKvstoreHelper` function to reduce defrag latency. (idea from Jim) 1. Previously, the defrag loop would continue processing up to 512 successful defragmentations before checking if the time limit was exceeded. Now it checks after every single successful allocation move. 2. The trade-off is slightly more frequent time checks, but the time check (~19ns) is negligible compared to the actual defragmentation work (even a single 8-byte reallocation takes ~43ns and the allocatorShouldDefrag function call takes ~49ns per block). This overhead is minimal compared to the latency improvement gained from better time management during active defragmentation. 3. Also revert the change from https://github.com/valkey-io/valkey/pull/2421/files to test. 4. Solved compilation issue with unsigned by changing the type of the local variable `prev_defragged `to match the type of `server.stat_active_defrag_hits` Closes valkey-io#2444 --------- Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Signed-off-by: Harkrishn Patro <harkrisp@amazon.com>
…40 (valkey-io#2574) Delete the out-of-date comment explaining why changed latency from 5 to 40 in valkey-io#2421 , which is a leftover of valkey-io#2553 Signed-off-by: Alina Liu <liusalisa6363@gmail.com> Signed-off-by: Harkrishn Patro <harkrisp@amazon.com>
Changed the defrag hit threshold from 512 to 1 in the
defragLaterStep&defragStageKvstoreHelperfunction to reduce defrag latency. (idea from Jim)prev_defraggedto match the type ofserver.stat_active_defrag_hitsCloses #2444