Silences: Optimize incremental mutes queries via a silence version index#4723
Merged
SuperQ merged 5 commits intoprometheus:mainfrom Nov 12, 2025
Merged
Silences: Optimize incremental mutes queries via a silence version index#4723SuperQ merged 5 commits intoprometheus:mainfrom
SuperQ merged 5 commits intoprometheus:mainfrom
Conversation
siavashs
approved these changes
Nov 11, 2025
Contributor
siavashs
left a comment
There was a problem hiding this comment.
LGTM, left a minor comment.
SuperQ
approved these changes
Nov 12, 2025
Member
|
This needs a rebase. |
| newVersionIndex.add(s.version+1, e.Silence.Id) | ||
| } | ||
| } | ||
| s.mtx.Lock() |
Contributor
There was a problem hiding this comment.
This is unrelated to your change. However, I'm wondering if this lock is necessary because it appears loadSnapshot is only called during construction of new Silences type.
Contributor
Author
There was a problem hiding this comment.
Indeed, it's probably unnecessary. But also harmless as at construction there's no contention.
added 4 commits
November 12, 2025 10:55
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
…new silences that have been added since the last version we saw Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Contributor
rajagopalanand
left a comment
There was a problem hiding this comment.
LGTM. Had one question about lock acquisition in the loadSnapshot method
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
c4cecac to
00dedba
Compare
rajagopalanand
approved these changes
Nov 12, 2025
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.
Currently Mutes is optimized for when the global silences haven't changed at all, and either our label set had zero or a few silences. When even a single silence has been added to the state though, the entire state needs to be scanned to find any match.
Since we know that existing silences cannot start matching without being re-added to the state, and we have a state version at which we are "caught up" available, we can optimize the code path when a few silences have been added to the state by:
This trades some memory, with a greatly increased performance for the situation when we have a lot of silences, and only a few have been added to the state since we last queried.
The GC is able to keep the state and indices up to date, in place, and reallocate the index to shed memory load when the set of silences has stably halved.
There is an increase in memory usage in MutesIncremental, which we could potentially mitigate in the future allowing QSince and QIDS queries in the same call, or allowing query types which return IDs instead of silence lists. The cost is still worth it as it's only in the case of massive silence loads that would make alertmanager nowadays fail, and is minimal compared to the current size of servers.
GC is not substantially slower, and only spends more memory when it needs to free up memory after a downsize of more than 50%, doing one more allocation then.