-
Notifications
You must be signed in to change notification settings - Fork 803
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
Batch adding series to query limiter to optimize locking #5505
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,18 +65,23 @@ func QueryLimiterFromContextWithFallback(ctx context.Context) *QueryLimiter { | |
return ql | ||
} | ||
|
||
// AddSeries adds the input series and returns an error if the limit is reached. | ||
func (ql *QueryLimiter) AddSeries(seriesLabels []cortexpb.LabelAdapter) error { | ||
// AddSeriesBatch adds the batch of input series and returns an error if the limit is reached. | ||
func (ql *QueryLimiter) AddSeries(series ...[]cortexpb.LabelAdapter) error { | ||
// If the max series is unlimited just return without managing map | ||
if ql.maxSeriesPerQuery == 0 { | ||
return nil | ||
} | ||
fingerprint := client.FastFingerprint(seriesLabels) | ||
fps := make([]model.Fingerprint, 0, len(series)) | ||
for _, s := range series { | ||
fps = append(fps, client.FastFingerprint(s)) | ||
} | ||
|
||
ql.uniqueSeriesMx.Lock() | ||
defer ql.uniqueSeriesMx.Unlock() | ||
for _, fp := range fps { | ||
ql.uniqueSeries[fp] = struct{}{} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am okay with this but I am also wondering if we can calculate the hashes first before we lock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did see some improvement when hashing the series outside the lock. I'll implement your suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @harry671003 Can you run the benchmark again? And let's also add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
ql.uniqueSeries[fingerprint] = struct{}{} | ||
if len(ql.uniqueSeries) > ql.maxSeriesPerQuery { | ||
// Format error with max limit | ||
return fmt.Errorf(ErrMaxSeriesHit, ql.maxSeriesPerQuery) | ||
|
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.
Just a small nit:
Can we receive an
[][]cortexpb.LabelAdapter
instaed of...[]cortexpb.LabelAdapter
to avoid copying this slice over?From go doc:
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.
Correct me if I'm wrong. The doc is saying that if we pass a slice into a variadic function, it'll not create a new array right?