-
Notifications
You must be signed in to change notification settings - Fork 796
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
Implement per-user rate limits #251
Conversation
This is the simplest version for now, just based on flag-configured rate limits per distributor process and no knowledge about total (cross-distributor rates) yet. Fixes #128
The |
@@ -320,6 +338,19 @@ func (d *Distributor) Push(ctx context.Context, req *remote.WriteRequest) (*cort | |||
return &cortex.WriteResponse{}, nil | |||
} | |||
|
|||
func (d *Distributor) getOrCreateIngestLimiter(userID string) *rate.Limiter { | |||
d.ingestLimitersMtx.Lock() |
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.
Note I'm intentionally just going for a normal mutex here because I figured an RWLock didn't really matter in this path (access once per HTTP request).
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.
I'd have probably gone with a RWMutex, I expecting each ingester to be able to handle ~1million samples/s, or 10k http requests a second. Right now they're only doing ~100 req/s, so its not a big deal. We can change later.
I see https://godoc.org/golang.org/x/time/rate post-dates our own token bucket implementation in Weave Net that we did in weaveworks/weave#1124. |
@rade Ah, didn't know about Weave's implemenation. Anyways, this one here seems to be the current Go way to do it (plus the Weave one doesn't have a non-blocking method yet). Could make sense to switch the other one too. |
Indeed. That's why I mentioned it :) |
You've pre-guessed my only comment, so LGTM! |
This is the simplest version for now, just based on flag-configured
rate limits per distributor process and no knowledge about total
(cross-distributor rates) yet.
Fixes #128