-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stats report daemon to Velox (#9653)
Summary: The stats report daemon is used for periodically exporting velox metrics. Current supported metrics are memory related metrics. There will be followups for additional metrics. Pull Request resolved: #9653 Reviewed By: xiaoxmeng Differential Revision: D56690811 Pulled By: tanjialiang fbshipit-source-id: e6f7236df9ea1445355f72b6f94b52704e0e1f4e
- Loading branch information
1 parent
15780e0
commit ebcbec7
Showing
10 changed files
with
286 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/common/base/PeriodicStatsReporter.h" | ||
#include "velox/common/base/Counters.h" | ||
#include "velox/common/base/StatsReporter.h" | ||
#include "velox/common/memory/Memory.h" | ||
|
||
namespace facebook::velox { | ||
|
||
namespace { | ||
#define REPORT_IF_NOT_ZERO(name, counter) \ | ||
if ((counter) != 0) { \ | ||
RECORD_METRIC_VALUE((name), (counter)); \ | ||
} | ||
} // namespace | ||
|
||
PeriodicStatsReporter::PeriodicStatsReporter( | ||
const velox::memory::MemoryArbitrator* arbitrator, | ||
const Options& options) | ||
: arbitrator_(arbitrator), options_(options) {} | ||
|
||
void PeriodicStatsReporter::start() { | ||
LOG(INFO) << "Starting PeriodicStatsReporter with options " | ||
<< options_.toString(); | ||
addTask( | ||
"report_arbitrator_stats", | ||
[this]() { reportArbitratorStats(); }, | ||
options_.arbitratorStatsIntervalMs); | ||
} | ||
|
||
void PeriodicStatsReporter::stop() { | ||
LOG(INFO) << "Stopping PeriodicStatsReporter"; | ||
scheduler_.stop(); | ||
} | ||
|
||
void PeriodicStatsReporter::reportArbitratorStats() { | ||
if (arbitrator_ == nullptr) { | ||
return; | ||
} | ||
|
||
const auto stats = arbitrator_->stats(); | ||
RECORD_METRIC_VALUE( | ||
kMetricArbitratorFreeCapacityBytes, | ||
stats.freeCapacityBytes + stats.freeReservedCapacityBytes); | ||
RECORD_METRIC_VALUE( | ||
kMetricArbitratorFreeReservedCapacityBytes, | ||
stats.freeReservedCapacityBytes); | ||
} | ||
|
||
} // namespace facebook::velox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <folly/experimental/ThreadedRepeatingFunctionRunner.h> | ||
#include "velox/common/memory/MemoryArbitrator.h" | ||
|
||
namespace folly { | ||
class CPUThreadPoolExecutor; | ||
} | ||
|
||
namespace facebook::velox { | ||
|
||
namespace memory { | ||
class MemoryAllocator; | ||
} | ||
|
||
namespace cache { | ||
class AsyncDataCache; | ||
} | ||
|
||
/// Manages a background daemon thread to report stats through 'StatsReporter'. | ||
class PeriodicStatsReporter { | ||
public: | ||
struct Options { | ||
Options() {} | ||
|
||
uint64_t arbitratorStatsIntervalMs{60'000}; | ||
|
||
std::string toString() const { | ||
return fmt::format( | ||
"arbitratorStatsIntervalMs:{}", arbitratorStatsIntervalMs); | ||
} | ||
}; | ||
|
||
PeriodicStatsReporter( | ||
const velox::memory::MemoryArbitrator* arbitrator, | ||
const Options& options = Options()); | ||
|
||
/// Invoked to start the report daemon in background. | ||
void start(); | ||
|
||
/// Invoked to stop the report daemon in background. | ||
void stop(); | ||
|
||
private: | ||
// Add a task to run periodically. | ||
template <typename TFunc> | ||
void addTask(const std::string& taskName, TFunc&& func, size_t intervalMs) { | ||
scheduler_.add( | ||
taskName, | ||
[taskName, | ||
intervalMs, | ||
func = std::forward<TFunc>(func)]() mutable noexcept { | ||
try { | ||
func(); | ||
} catch (const std::exception& e) { | ||
LOG(ERROR) << "Error running periodic task " << taskName << ": " | ||
<< e.what(); | ||
} | ||
return std::chrono::milliseconds(intervalMs); | ||
}); | ||
} | ||
|
||
void reportArbitratorStats(); | ||
|
||
const velox::memory::MemoryArbitrator* const arbitrator_{nullptr}; | ||
const Options options_; | ||
|
||
folly::ThreadedRepeatingFunctionRunner scheduler_; | ||
}; | ||
} // namespace facebook::velox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.