Skip to content

Commit

Permalink
Add logging for Adaptive Concurrency Controller configuration event (…
Browse files Browse the repository at this point in the history
…2/2)

Summary: Adds the ability to set a callback on the AdaptiveConcurrencyController that fires when the internal Config changes (e.g. via a Configerator update). ThriftServer utilizes this callback mechanism to log a new THRIFT_SERVER_EVENT (ACC_enabled) if the AdaptiveConcurrencyController has been enabled by the Config change.

Reviewed By: ycking21

Differential Revision: D35603212

fbshipit-source-id: 3b411b79a83545d9d5c5eea53ad4218465ba7dec
  • Loading branch information
sethdelliott authored and facebook-github-bot committed Apr 19, 2022
1 parent f701cc4 commit bc3f7af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions thrift/lib/cpp2/server/AdaptiveConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ AdaptiveConcurrencyController::AdaptiveConcurrencyController(
concurrencyLimit_(config().minConcurrency) {
rttRecalcStart_ = config().isEnabled() ? Clock::now() : kZero;
enablingCallback_ = config_.addCallback([this](auto snapshot) {
if (this->configUpdateCallback_) {
this->configUpdateCallback_(snapshot);
}
rttRecalcStart_ = snapshot->isEnabled() ? Clock::now() : kZero;
// reset all the state
maxRequests_.store(0, std::memory_order_relaxed);
Expand Down Expand Up @@ -222,5 +225,11 @@ size_t AdaptiveConcurrencyController::getConcurrency() const {
return concurrencyLimit_.load(std::memory_order_relaxed);
}

void AdaptiveConcurrencyController::setConfigUpdateCallback(
std::function<void(folly::observer::Snapshot<Config>)> callback) {
callback(*config_);
configUpdateCallback_ = std::move(callback);
}

} // namespace thrift
} // namespace apache
4 changes: 4 additions & 0 deletions thrift/lib/cpp2/server/AdaptiveConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class AdaptiveConcurrencyController {
// to minConcurrency when controller is in the rtt calibration state.
size_t getConcurrency() const;

void setConfigUpdateCallback(
std::function<void(folly::observer::Snapshot<Config>)> callback);

private:
// testing helpers
friend class AdaptiveConcurrencyTestHelper;
Expand Down Expand Up @@ -148,6 +151,7 @@ class AdaptiveConcurrencyController {
folly::observer::Observer<Config> config_;
folly::observer::Observer<uint32_t> maxRequestsLimit_;
folly::observer::CallbackHandle enablingCallback_;
std::function<void(folly::observer::Snapshot<Config>)> configUpdateCallback_;

std::atomic<Duration> targetRtt_{Duration{}};
std::atomic<Duration> minRtt_{Duration{}};
Expand Down
6 changes: 6 additions & 0 deletions thrift/lib/cpp2/server/ThriftServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ ThriftServer::ThriftServer()
setMonitoringInterface(std::move(extraInterfaces.monitoring));
setStatusInterface(std::move(extraInterfaces.status));
setControlInterface(std::move(extraInterfaces.control));
getAdaptiveConcurrencyController().setConfigUpdateCallback(
[this](auto snapshot) {
if (snapshot->isEnabled()) {
THRIFT_SERVER_EVENT(ACC_enabled).log(*this);
}
});
}

ThriftServer::ThriftServer(
Expand Down

0 comments on commit bc3f7af

Please sign in to comment.