Skip to content

Reduce eval related overhead introduced in v7.0 by evalCalcFunctionName#11521

Merged
oranagra merged 6 commits intoredis:unstablefrom
filipecosta90:fix.2x.evalCalcFunctionName
Nov 29, 2022
Merged

Reduce eval related overhead introduced in v7.0 by evalCalcFunctionName#11521
oranagra merged 6 commits intoredis:unstablefrom
filipecosta90:fix.2x.evalCalcFunctionName

Conversation

@filipecosta90
Copy link
Contributor

@filipecosta90 filipecosta90 commented Nov 17, 2022

As being discussed in #10981 we see a degradation in performance between v6.2 and v7.0 of Redis on the EVAL command.

After profiling the current unstable branch ( 203b12e ) we can see that we call the expensive function evalCalcFunctionName twice.
image

The current "fix" is to basically avoid calling evalCalcFunctionName and even dictFind(lua_scripts) twice for the same command.
Instead we cache the current script's dictEntry (for both Eval and Functions) in the current client so we don't have to repeat these calls.
The exception would be when doing an EVAL on a new script that's not yet in the script cache. in that case we will call evalCalcFunctionName (and even evalExtractShebangFlags) twice.

Notice that the current "fix" is still not enough to reach v6.2 numbers.
We need to improve 10% further to reach the v6.2 results ( even though we have new logic on 7.0 )

To benchmark the improvement we can do as follows with memtier:

EVALSHA

redis-cli SCRIPT load "redis.call('hset', 'h1', 'k', 'v');redis.call('hset', 'h2', 'k', 'v');return redis.call('ping')"
memtier_benchmark --command="EVALSHA 7cecb99fd9091d8e66d5cccf8979cf3aec5c4951 0"  - --hide-histogram --test-time 60 --pipeline 10 -x 1

EVAL

memtier_benchmark --command="eval \"redis.call('hset', 'h1', 'k', 'v');redis.call('hset', 'h2', 'k', 'v');return redis.call('ping')\" 0"  - --hide-histogram --test-time 60 --pipeline 10 -x 1

Results based on OSS standalone achievable ops/sec

COMMAND 6.2.6 unstable this PR % Improvement vs unstable % Drop vs 6.2.6
EVAL 223744 169767 187298 10.33% -16.29%
EVALSHA 264411 204867 207763 1.41% -21.42%

@filipecosta90 filipecosta90 added the action:run-benchmark Triggers the benchmark suite for this Pull Request label Nov 17, 2022
@filipecosta90 filipecosta90 changed the title [In-Progress] Reduce eval related overhead introduced in v7.0 Reduce eval related overhead introduced in v7.0 by evalCalcFunctionName Nov 21, 2022
Copy link
Collaborator

@sundb sundb left a comment

Choose a reason for hiding this comment

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

LGTM

@oranagra oranagra merged commit 7dfd7b9 into redis:unstable Nov 29, 2022
@filipecosta90 filipecosta90 deleted the fix.2x.evalCalcFunctionName branch November 29, 2022 12:23
@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Dec 5, 2022
@oranagra oranagra mentioned this pull request Dec 11, 2022
oranagra added a commit that referenced this pull request Dec 12, 2022
…me (#11521)

As being discussed in #10981 we see a degradation in performance
between v6.2 and v7.0 of Redis on the EVAL command.

After profiling the current unstable branch we can see that we call the
expensive function evalCalcFunctionName twice.

The current "fix" is to basically avoid calling evalCalcFunctionName and
even dictFind(lua_scripts) twice for the same command.
Instead we cache the current script's dictEntry (for both Eval and Functions)
in the current client so we don't have to repeat these calls.
The exception would be when doing an EVAL on a new script that's not yet
in the script cache. in that case we will call evalCalcFunctionName (and even
evalExtractShebangFlags) twice.

Co-authored-by: Oran Agra <[email protected]>
(cherry picked from commit 7dfd7b9)
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
…me (redis#11521)

As being discussed in redis#10981 we see a degradation in performance
between v6.2 and v7.0 of Redis on the EVAL command. 

After profiling the current unstable branch we can see that we call the
expensive function evalCalcFunctionName twice. 

The current "fix" is to basically avoid calling evalCalcFunctionName and
even dictFind(lua_scripts) twice for the same command.
Instead we cache the current script's dictEntry (for both Eval and Functions)
in the current client so we don't have to repeat these calls.
The exception would be when doing an EVAL on a new script that's not yet
in the script cache. in that case we will call evalCalcFunctionName (and even
evalExtractShebangFlags) twice.

Co-authored-by: Oran Agra <[email protected]>
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…me (redis#11521)

As being discussed in redis#10981 we see a degradation in performance
between v6.2 and v7.0 of Redis on the EVAL command. 

After profiling the current unstable branch we can see that we call the
expensive function evalCalcFunctionName twice. 

The current "fix" is to basically avoid calling evalCalcFunctionName and
even dictFind(lua_scripts) twice for the same command.
Instead we cache the current script's dictEntry (for both Eval and Functions)
in the current client so we don't have to repeat these calls.
The exception would be when doing an EVAL on a new script that's not yet
in the script cache. in that case we will call evalCalcFunctionName (and even
evalExtractShebangFlags) twice.

Co-authored-by: Oran Agra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action:run-benchmark Triggers the benchmark suite for this Pull Request release-notes indication that this issue needs to be mentioned in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants