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

gRPC server: add ability to reject methods early, before reading the request into memory #377

Merged
merged 6 commits into from
Sep 20, 2023

Conversation

pstibrany
Copy link
Member

@pstibrany pstibrany commented Sep 14, 2023

What this PR does:

This PR introduces adds a way to reject calls to gRPC methods early, right after gRPC server receives request headers, but before reading the request body and starting a goroutine.

This PR is generalization of Mimir's grafana/mimir#5976. Description in that PR explains this approach and why it works.

Checklist

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

@pracucci pracucci self-requested a review September 18, 2023 15:41
server/limits.go Outdated Show resolved Hide resolved
server/server.go Outdated
@@ -118,6 +118,7 @@ type Config struct {
GRPCServerTimeout time.Duration `yaml:"grpc_server_keepalive_timeout"`
GRPCServerMinTimeBetweenPings time.Duration `yaml:"grpc_server_min_time_between_pings"`
GRPCServerPingWithoutStreamAllowed bool `yaml:"grpc_server_ping_without_stream_allowed"`
GRPCServerMaxInflightRequests int `yaml:"grpc_server_max_inflight_requests"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not super convinced of having a global config. I think in practice it's more useful to let the upstream project to have control over it (e.g. limit only specific methods). Have you considered designing so that we just configure a set of 0+ limiters, each limiter being able to limit a configurable set of methods? I'm asking because in Mimir ingester I would like to limit only the push gRPC and not every gRPC call with a "global" limiter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have you considered designing so that we just configure a set of 0+ limiters, each limiter being able to limit a configurable set of methods? I'm asking because in Mimir ingester I would like to limit only the push gRPC and not every gRPC call with a "global" limiter.

This PR allows you to do exactly that already. There's global inflight limit, which I think can be useful but can also be disabled, and there's also a possibility to limit specific methods by using GrpcMethodLimiter. I imagine that Mimir would install its own GrpcMethodLimiter to implement ingesters's inflight limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just remove the global one and let the upstream project to control it via GrpcMethodLimiter. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would just remove the global one and let the upstream project to control it via GrpcMethodLimiter. WDYT?

OK, let's do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed support for max inflight requests in gRPC server, and only added limiting via GrpcInflightMethodLimiter. Please take a look again.

@pstibrany pstibrany changed the title Add grpc-server inflight request limit, and support for limiting specific methods gRPC server: add ability to reject methods early, before reading the request into memory Sep 20, 2023
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback. LGTM!

@pstibrany pstibrany merged commit 98f431c into main Sep 20, 2023
3 checks passed
@pstibrany pstibrany deleted the grpc-inflight-limit branch September 20, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants