Repository navigation
perf: Skip session work that is only needed when a session is logged - #6005
Open
abdelaziz-mahdy wants to merge 1 commit into
Open
abdelaziz-mahdy wants to merge 1 commit into
abdelaziz-mahdy wants to merge 1 commit into
Conversation
A method call created a secure-random session id, a session log open event and, when a session was emitted, VM service log events, even when nothing used them: - Session.sessionId is generated on first access. - SessionLogManager builds its open event on first use. - VmServiceSessionLogWriter returns early while nothing listens to the extension stream, as in production, instead of building events that postEvent drops. Under overload every session is slow and gets logged, so this work grew exactly when the server had no time for it.
1 task done
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.
Every method call did this, even though nothing used the result:
CryptoRNG);sessionId.hashCode);stack trace strings), which
postEventdrops when there's no VM service,as in production.
The last one matters under overload. Once latency passes the 1 s
slow-session threshold, every session and query is logged. In an overload
profile, building these events took ~16% of CPU, making the overload worse.
Changes:
Session.sessionIdis generated on first access;SessionLogManagerbuilds its open event on first use;VmServiceSessionLogWriterreturns early whiledeveloper.extensionStreamHasListeneris false.Part of #6002
Measurements
AOT, macOS arm64, retired CPU instructions per request, mean of 3 shuffled
runs:
findByIdfind, 20 rowsinsertRowBold: every run below every run of
main. The DB requests change by aboutas much in absolute terms; it's a smaller share of a larger request.
Tests
Full Serverpod test run on the combined branch (the PR branches are subsets): unit tests of serverpod, serverpod_serialization, serverpod_shared and serverpod_database pass; integration tests 1,683 (serial) + 529 (
util/run_tests_integration_concurrently) pass;dart analyzeis clean on this branch.How it was measured: the app is compiled AOT and run natively; for each request type, k6 sends 15 s at 1,000 req/s, and the server process's retired instructions (
proc_pid_rusage(RUSAGE_INFO_V4)) before and after are divided by the number of requests. Builds ofmainand this PR were run alternately in shuffled order. I can share the scripts.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.Breaking changes
None.
sessionIdis still a non-nullUuidValue, now created when firstread.