[DO NOT MERGE] Explore consistency and performance frameworks for writing responses#1781
Draft
kevin-montrose wants to merge 16 commits intomainfrom
Draft
[DO NOT MERGE] Explore consistency and performance frameworks for writing responses#1781kevin-montrose wants to merge 16 commits intomainfrom
kevin-montrose wants to merge 16 commits intomainfrom
Conversation
…'s an equivalent version in RespServerSessionOutput.cs
This file contains hidden or 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
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.
For discussion and PoC purposes, explore adding some analyzers to make use consistent in how we deal with RESP output.
This PR is not intended to be merged, though the analyzers might be salvageable.
The primary motivation is correctness, but there might be some performance improvements to be had as well.
Analyzers
Motivating incident is #1776 where we were incorrectly handling large outputs.
Introduces 7 diagnostics over 3 analyzers in Garnet.server:
libs\server\Resp\RespServerSessionOutput.csLargeoverrides with variable size responsesLargeoverrides for variable size responsesCmdStringsCmdStringsCmdStringsconstant too largeCmdStrings.MaximumConstantSizeLargeoverrides for themCmdStringsargumentsWriteXXXmethods) and runtime work of things likeNumDigits(...) andSendAndReset()These analyzers are quick and dirty so they fit our current coding practices, but could certainly be made more robust to future changes.
Other Work Not Explored
To really adopt/benefit from all this we'd also want to:
AbortXXXhelpers, directly using theWriteXXXmethods everywhereWriteLargeXXXcalls and move those that are probably bounded to normalWritecalls (presumably with aDebug.Assertabout the expected maximum length)Garnet.cluster&Garnet.common, probably after refactoring some things to moveCmdStringsand theWriteXXXhelpers a toGarnet.commonCmdStrings.MaximumConstantSizePotential Optimizations
These are not implemented, but are possible if we pursue this work:
[MethodImpl(MethodImplOptions.NoInlining)]on uncommon helpers (presumably all error paths)SendAndReset()for non-WriteLargeXXXmethodsNumUtils.CountDigitswhen using non-WriteLargeXXXmethodsif(TryWriteXXX(...)) { SendAndReset(); WriteXXXUnlikely(...); }whereTryWriteXXXandSendAndReset()are aggressively inlined andWriteXXXUnlikelyis no inlinedThere's also potential waaaay down the line to look at Interceptors to clean all this up - in particular we could remove
CmdStringsin its entirety, and automate the collapsing of repeated constant calls.