Skip to content

Commit

Permalink
Add credits_available quantile counter (p1, p50, p99)
Browse files Browse the repository at this point in the history
Summary: Add quantile counter (p1, p50, and p99) for number of stream credits the server currently has. The value is updated each time the server receives more credits or if it runs out of credits.

Reviewed By: praihan

Differential Revision: D68467565

fbshipit-source-id: ecc316562572badf057b94fb460af4164e6c4f4b
  • Loading branch information
Akrama Baig Mirza authored and facebook-github-bot committed Feb 6, 2025
1 parent 98aafec commit 4da2793
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions thrift/lib/cpp2/server/metrics/StreamMetricCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class StreamMetricCallback {
virtual void onStreamCancel(std::string_view /* methodName */) = 0;
virtual void onStreamRequestN(
std::string_view /* methodName */, uint32_t /* credits */) = 0;
virtual void recordCreditsAvailable(
std::string_view /* methodName */, uint32_t /* creditsAvailable */) = 0;
};

class NoopStreamMetricCallback final : public StreamMetricCallback {
Expand All @@ -41,6 +43,7 @@ class NoopStreamMetricCallback final : public StreamMetricCallback {
void onStreamComplete(std::string_view) override {}
void onStreamCancel(std::string_view) override {}
void onStreamRequestN(std::string_view, uint32_t) override {}
void recordCreditsAvailable(std::string_view, uint32_t) override {}
};

} // namespace apache::thrift
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ bool RocketStreamClientCallback::request(uint32_t tokens) {
}

cancelTimeout();
tokens_ += tokens;
streamMetricCallback_.recordCreditsAvailable(rpcMethodName_, tokens_);
streamMetricCallback_.onStreamRequestN(rpcMethodName_, tokens);
tokens_ += tokens;
return serverCallback()->onStreamRequestN(tokens);
}

Expand Down Expand Up @@ -292,6 +293,7 @@ void RocketStreamClientCallback::scheduleTimeout() {
timeoutCallback_ = std::make_unique<TimeoutCallback>(*this);
}
connection_.scheduleStreamTimeout(timeoutCallback_.get());
streamMetricCallback_.recordCreditsAvailable(rpcMethodName_, tokens_);
}

void RocketStreamClientCallback::cancelTimeout() {
Expand Down

0 comments on commit 4da2793

Please sign in to comment.