Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate hashTypeIterator memory allocation by assigning it on stack #1105

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

imasahiro
Copy link
Contributor

At redis/redis#11245, we provided dict iterator API to initialize/release the iterators without memory allocation. This change is for hash iterator.

The memory (de)allocation consumes 2.4% of cpu resource when we execute HGETALL command.
スクリーンショット 2024-10-02 9 27 53

For big hashtable, the impact of this change is smaller but for small hashtable, it sometimes has a positive impact

test unstable(ac569c0) rpc this patch (rpc) improvements
HGETALL h1 78192.2 79802.09 2.058888227
HGETALL h10 75075.08 74850.3 -0.29940694
HGETALL h25 68634.18 69541.03 1.321280447
HGETALL h50 60639.14 59548.62 -1.798376428
for i in `seq 1 1`; do
    ./valkey-cli -h $H -p $P hset h1 "k$i" "v$i" > /dev/null
done
for i in `seq 1 10`; do
    ./valkey-cli -h $H -p $P hset h10 "k$i" "v$i" > /dev/null
done
for i in `seq 1 25`; do
    ./valkey-cli -h $H -p $P hset h25 "k$i" "v$i" > /dev/null
done
for i in `seq 1 50`; do
    ./valkey-cli -h $H -p $P hset h50 "k$i" "v$i" > /dev/null
done
./valkey-benchmark --csv -n 1000000 -r 1000000 -h $H -p $P HGETALL h1
./valkey-benchmark --csv -n 1000000 -r 1000000 -h $H -p $P HGETALL h10
./valkey-benchmark --csv -n 1000000 -r 1000000 -h $H -p $P HGETALL h25
./valkey-benchmark --csv -n 1000000 -r 1000000 -h $H -p $P HGETALL h50

At redis/redis#11245, we provided dict iterator API
to initialize/release the iterators without memory allocation.
This change is for hash iterator.

| test        |  unstable(ac569c0) rpc | this patch (rpc) | improvements |
| ----------- | ------------------------- | ---------------- | ------------ |
| HGETALL h1  | 78192.2                   | 79802.09         |  2.058888227 |
| HGETALL h10 | 75075.08                  | 74850.3          | -0.29940694  |
| HGETALL h25 | 68634.18                  | 69541.03         |  1.321280447 |
| HGETALL h50 | 60639.14                  | 59548.62         | -1.798376428 |

Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.61%. Comparing base (ac569c0) to head (50c8df6).
Report is 2 commits behind head on unstable.

Files with missing lines Patch % Lines
src/aof.c 71.42% 2 Missing ⚠️
src/t_hash.c 97.14% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1105      +/-   ##
============================================
+ Coverage     70.57%   70.61%   +0.03%     
============================================
  Files           114      114              
  Lines         61695    61695              
============================================
+ Hits          43544    43567      +23     
+ Misses        18151    18128      -23     
Files with missing lines Coverage Δ
src/debug.c 53.71% <100.00%> (+0.04%) ⬆️
src/server.h 100.00% <ø> (ø)
src/t_hash.c 95.85% <97.14%> (-0.01%) ⬇️
src/aof.c 80.08% <71.42%> (ø)

... and 15 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant