-
Notifications
You must be signed in to change notification settings - Fork 538
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
Lua Scripting Allocation, Performance, and Correctness Improvements #882
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…d to upstream some KeraLua additions; also horribly broken
…e can't really do much there)
…and ARGV at start
…pt may not be viable... but was worth experimenting with
…s; fix some ZADD scripting tests; special err response stuff can't be done on the Lua side, remove it
…unning; all tests passing again
…ponse directly to network stream
…ots broken right now
…ing else; avoid copying regular used strings into Lua each time they're needed
…hich is odd, but easy enough to restore
…ke to double check the type
…ize stack checking, normalize assertions
…pressed - it's unclear if .NET is actually doing that today, but it's safe
… to look at removing some p/invokes
…tions where now allowed; more closely sync methods exposed in Lua to those provided by Redis
Fantastic PR, this is huge for Lua users of Garnet! |
badrishc
reviewed
Dec 16, 2024
TedHartMS
approved these changes
Dec 17, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent PR!
badrishc
approved these changes
Dec 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a big one, but kinda had to be.
At a high level this:
Lower level notes:
CallConvSuppressGCTransition
as they do no allocations or unbounded operationsThere's still more to do (offhand we need memory tracking, memory limits, and script timeouts) but this is enough to be merged.
Performance
There are now 4 relevant benchmarks, I picked and merged on top of
main
(commitf1ce0dafecaba15335e8e0767a6eeb441b72e56c
) to run these.LuaScripts
Existing benchmark, really just covers the "invoke Lua"-case.
Roughly allocation free, and the
redis.call
case is ~8x faster.main
nLuaToKeraLua
LuaScriptCacheOperations
New benchmark, covers the caching of scripts and runners.
30-50% faster for many operations, and big improvements in the "initial load into session"-case of
LoadInnerHit
.I played around a bit with improving the hash digest method, but didn't really find any wins there. It's covered by a benchmark now though.
main
nLuaToKeraLua
LuaRunnerOperations
New benchmark, covers various operations on LuaRunner. Notably I put a real-ish UDF in here, with non-trivial logic and two
redis.call
s.Basic operations are all faster, and very low or no-allocation now. The most common (resetting parameters before running the script) is ~70x faster. Construction (setting up the initial environment) and compilation are modestly (maybe 30%) faster.
main
nLuaToKeraLua
Note the above is is ns not us.
ScriptOperations
Existing benchmark, but expanded with more realistic UDF (the same as in LuaRunnerOperations). As before I'm only reporting the None set, as ACL disables most code and AOF isn't relevant here.
There's a throughput loss in ScriptLoad (~23%) but improvements everywhere else - this is probably due to more being in the initial environment definition. Improvements range from ~15% in the LargeScript case to ~75% in the SmallScript case.
Additionally, allocations are basically removed from all paths except ScriptLoad, where they're reduced.
main
nLuaToKeraLua
Correctness
Various fixes added:
ok
anderr
special cases match Redis behaviorredis.call
matches Redis behaviorlong
s1
andnil
And probably some more I'm forgetting.