Skip to content
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

Optimize distributor push on error #3990

Merged

Conversation

pracucci
Copy link
Contributor

What this PR does:
Following up the work done in ingesters to optimize the unhappy path (#3969 #3971 #3973), in this PR I'm introducing a benchmark for the Distributor.Push() on validation error and optimizing it.

Contrary to the ingester, for the distributor I didn't pick the path of returning static errors from ValidateLabels() and ValidateSample() and then offer a function to format them because the formatting function ended up to replicate the validation logic too. What I'm proposing in this PR is returning a ValidationError which can be converted to HTTPGRPC error. We still have 1 allocation for each series/sample but, as you can see from the benchmark, the impact is minimal: the real optimization is not having to format an httpgrpc error each time.

Benchmark:

Distributor_PushOnError/max_label_name_length_limit_reached-12     15.8ms ± 0%     5.0ms ± 1%  -68.46%  (p=0.016 n=4+5)
Distributor_PushOnError/max_label_value_length_limit_reached-12    35.9ms ± 1%     3.0ms ± 0%  -91.75%  (p=0.016 n=5+4)
Distributor_PushOnError/timestamp_too_old-12                       2.37ms ± 0%    1.03ms ± 1%  -56.72%  (p=0.016 n=4+5)
Distributor_PushOnError/timestamp_too_new-12                       2.37ms ± 1%    1.03ms ± 2%  -56.60%  (p=0.016 n=4+5)
Distributor_PushOnError/ingestion_rate_limit_reached-12             877µs ± 0%     869µs ± 0%   -0.91%  (p=0.029 n=4+4)
Distributor_PushOnError/too_many_labels_limit_reached-12           19.6ms ± 0%     1.3ms ± 1%  -93.44%  (p=0.008 n=5+5)

name                                                             old alloc/op   new alloc/op   delta
Distributor_PushOnError/max_label_name_length_limit_reached-12     11.2MB ± 0%     0.1MB ± 0%  -98.85%  (p=0.008 n=5+5)
Distributor_PushOnError/max_label_value_length_limit_reached-12    13.3MB ± 0%     0.1MB ± 0%  -99.03%  (p=0.008 n=5+5)
Distributor_PushOnError/timestamp_too_old-12                        824kB ± 0%     118kB ± 0%  -85.71%  (p=0.008 n=5+5)
Distributor_PushOnError/timestamp_too_new-12                        824kB ± 0%     118kB ± 0%  -85.72%  (p=0.008 n=5+5)
Distributor_PushOnError/ingestion_rate_limit_reached-12            85.2kB ± 0%    85.3kB ± 0%     ~     (p=0.056 n=5+5)
Distributor_PushOnError/too_many_labels_limit_reached-12           10.1MB ± 0%     0.1MB ± 0%  -99.07%  (p=0.008 n=5+5)

name                                                             old allocs/op  new allocs/op  delta
Distributor_PushOnError/max_label_name_length_limit_reached-12      58.1k ± 0%      3.1k ± 0%  -94.69%  (p=0.008 n=5+5)
Distributor_PushOnError/max_label_value_length_limit_reached-12     59.1k ± 0%      3.1k ± 0%  -94.79%  (p=0.008 n=5+5)
Distributor_PushOnError/timestamp_too_old-12                        19.0k ± 0%      5.0k ± 0%  -73.56%  (p=0.008 n=5+5)
Distributor_PushOnError/timestamp_too_new-12                        19.0k ± 0%      5.0k ± 0%  -73.56%  (p=0.008 n=5+5)
Distributor_PushOnError/ingestion_rate_limit_reached-12             4.03k ± 0%     4.03k ± 0%     ~     (p=0.167 n=5+5)
Distributor_PushOnError/too_many_labels_limit_reached-12             114k ± 0%        3k ± 0%  -97.26%  (p=0.008 n=5+5)

No optimization to ingestion rate limit but added to the benchmark to measure it too.

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (with few non-blocking nits), nice improvement!

error

// ToHTTPGRPCError returns the httpgrpc version of the error.
ToHTTPGRPCError() error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It would be nicer if ValidationError interface was not defined in terms of specific transport mechanism. Instead it could simply have a method IsValidationError() bool [or some other that makes sense]. Call to httpgrpc.Errorf could then be done in distributor, by using message from err.Error() function, which would do the formatting. Duplicity in that all validation errors return same StatusBadRequest code would be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds a good idea. Done!

// error format only contains the cause and the series.
type genericValidationError struct {
message string
cause string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming confused me... cause is simply the first formatting-argument for message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point but I can't get a better idea for naming, so I just used cause which was the variable name already used in ValidateLabels().

@pstibrany
Copy link
Contributor

Conflicts with change in #3982.

Signed-off-by: Marco Pracucci <[email protected]>
Signed-off-by: Marco Pracucci <[email protected]>
Signed-off-by: Marco Pracucci <[email protected]>
@pracucci pracucci force-pushed the optimize-distributor-push-on-error branch from 4ee375a to 7a83bb5 Compare March 23, 2021 08:38
@pracucci pracucci merged commit 8a2e2c1 into cortexproject:master Mar 23, 2021
@pracucci pracucci deleted the optimize-distributor-push-on-error branch March 23, 2021 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants