mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
[core] memory monitor to use the event loop from node manager
The objects accessed by the memory monitor callback are not thread-safe. The node manager runs on a specific event loop and this PR changes the memory monitor to share that same event loop similar to the rest of the components executed under the node manager. Signed-off-by: Clarence Ng <clarence.wyng@gmail.com>
This commit is contained in:
parent
f9d767b67d
commit
a5693a2334
1 changed files with 23 additions and 2 deletions
|
@ -17,13 +17,29 @@
|
|||
#include <sys/sysinfo.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ray/common/asio/instrumented_io_context.h"
|
||||
#include "ray/util/process.h"
|
||||
|
||||
namespace ray {
|
||||
class MemoryMonitorTest : public ::testing::Test {};
|
||||
class MemoryMonitorTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
thread_ = std::make_unique<std::thread>([this]() {
|
||||
boost::asio::io_context::work work(io_context_);
|
||||
io_context_.run();
|
||||
});
|
||||
}
|
||||
void TearDown() override {
|
||||
io_context_.stop();
|
||||
thread_->join();
|
||||
}
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
instrumented_io_context io_context_;
|
||||
};
|
||||
|
||||
TEST_F(MemoryMonitorTest, TestThresholdZeroMonitorAlwaysAboveThreshold) {
|
||||
MemoryMonitor monitor(
|
||||
MemoryMonitorTest::io_context_,
|
||||
0 /*usage_threshold*/,
|
||||
0 /*refresh_interval_ms*/,
|
||||
[](bool is_usage_above_threshold,
|
||||
|
@ -34,6 +50,7 @@ TEST_F(MemoryMonitorTest, TestThresholdZeroMonitorAlwaysAboveThreshold) {
|
|||
|
||||
TEST_F(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold) {
|
||||
MemoryMonitor monitor(
|
||||
MemoryMonitorTest::io_context_,
|
||||
1 /*usage_threshold*/,
|
||||
0 /*refresh_interval_ms*/,
|
||||
[](bool is_usage_above_threshold,
|
||||
|
@ -44,6 +61,7 @@ TEST_F(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold) {
|
|||
|
||||
TEST_F(MemoryMonitorTest, TestUsageAtThresholdReportsTrue) {
|
||||
MemoryMonitor monitor(
|
||||
MemoryMonitorTest::io_context_,
|
||||
0.5 /*usage_threshold*/,
|
||||
0 /*refresh_interval_ms*/,
|
||||
[](bool is_usage_above_threshold,
|
||||
|
@ -57,6 +75,7 @@ TEST_F(MemoryMonitorTest, TestUsageAtThresholdReportsTrue) {
|
|||
TEST_F(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive) {
|
||||
{
|
||||
MemoryMonitor monitor(
|
||||
MemoryMonitorTest::io_context_,
|
||||
0 /*usage_threshold*/,
|
||||
0 /*refresh_interval_ms*/,
|
||||
[](bool is_usage_above_threshold,
|
||||
|
@ -71,6 +90,7 @@ TEST_F(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive) {
|
|||
TEST_F(MemoryMonitorTest, TestGetNodeTotalMemoryEqualsFreeOrCGroup) {
|
||||
{
|
||||
MemoryMonitor monitor(
|
||||
MemoryMonitorTest::io_context_,
|
||||
0 /*usage_threshold*/,
|
||||
0 /*refresh_interval_ms*/,
|
||||
[](bool is_usage_above_threshold,
|
||||
|
@ -103,7 +123,8 @@ TEST_F(MemoryMonitorTest, TestMonitorPeriodSetCallbackExecuted) {
|
|||
std::condition_variable callback_ran;
|
||||
std::mutex callback_ran_mutex;
|
||||
|
||||
MemoryMonitor monitor(1 /*usage_threshold*/,
|
||||
MemoryMonitor monitor(MemoryMonitorTest::io_context_,
|
||||
1 /*usage_threshold*/,
|
||||
1 /*refresh_interval_ms*/,
|
||||
[&callback_ran](bool is_usage_above_threshold,
|
||||
MemorySnapshot system_memory,
|
||||
|
|
Loading…
Add table
Reference in a new issue