-
Notifications
You must be signed in to change notification settings - Fork 49
Prefixed keys in session token storage #3841
Copy link
Copy link
Open
Labels
I4No visible changesNo visible changesS3Minimally significantMinimally significantU4Nothing urgentNothing urgentenhancementImproving existing functionalityImproving existing functionalityneofs-storageStorage node application issuesStorage node application issuesperformanceMore of something per secondMore of something per second
Milestone
Metadata
Metadata
Assignees
Labels
I4No visible changesNo visible changesS3Minimally significantMinimally significantU4Nothing urgentNothing urgentenhancementImproving existing functionalityImproving existing functionalityneofs-storageStorage node application issuesStorage node application issuesperformanceMore of something per secondMore of something per second
Is your feature request related to a problem? Please describe.
I'm always frustrated when
RemoveOldTokensiterates over every key in the sessions bucket and deserializes each token value to check its epoch. This becomes increasingly expensive as the number of stored sessions grows.Describe the solution you'd like
Store two keys per token in the same bucket using prefixes:
{pref_0}{acc}token data (forGetToken, O(1) lookup){pref_1}{epoch}{acc}empty value (epoch index)RemoveOldTokensthen usesSeek({pref_1})and iterates only over expired index entries. Both keys are written atomically in one transaction on save. A migration will be needed to rewrite existing entries into the new key format.Describe alternatives you've considered
Keep the current implementation as-is — simpler, but suboptimal for large numbers of sessions.
Additional context
#3817 (comment)