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

Merged
merged 3 commits into from
Oct 6, 2024

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 92.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 70.61%. Comparing base (ac569c0) to head (a319d43).
Report is 17 commits behind head on unstable.

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

... and 17 files with indirect coverage changes

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

src/t_hash.c Outdated Show resolved Hide resolved
src/t_hash.c Outdated Show resolved Hide resolved
imasahiro and others added 2 commits October 3, 2024 09:35
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Masahiro Ide <imasahiro9@gmail.com>
Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zuiderkwast zuiderkwast merged commit b5eb793 into valkey-io:unstable Oct 6, 2024
47 checks passed
@imasahiro imasahiro deleted the hti branch October 7, 2024 00:49
naglera pushed a commit to naglera/placeholderkv that referenced this pull request Oct 10, 2024
…valkey-io#1105)

Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Signed-off-by: Masahiro Ide <imasahiro9@gmail.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Signed-off-by: naglera <anagler123@gmail.com>
SoftlyRaining pushed a commit to SoftlyRaining/valkey that referenced this pull request Oct 11, 2024
…valkey-io#1105)

Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Signed-off-by: Masahiro Ide <imasahiro9@gmail.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
eifrah-aws pushed a commit to eifrah-aws/valkey that referenced this pull request Oct 20, 2024
…valkey-io#1105)

Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Signed-off-by: Masahiro Ide <imasahiro9@gmail.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
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.

3 participants