Signed-off-by: Clarence Ng <clarence.wyng@gmail.com>
This commit is contained in:
Clarence Ng 2022-08-29 10:10:46 -07:00
parent e7d386865a
commit a7869a3545
3 changed files with 16 additions and 3 deletions

View file

@ -72,7 +72,7 @@ bool MemoryMonitor::IsUsageAboveThreshold(MemorySnapshot system_memory) {
return false; return false;
} }
float usage_fraction = static_cast<float>(used_memory_bytes) / total_memory_bytes; float usage_fraction = static_cast<float>(used_memory_bytes) / total_memory_bytes;
bool is_usage_above_threshold = usage_fraction > usage_threshold_; bool is_usage_above_threshold = usage_fraction >= usage_threshold_;
if (is_usage_above_threshold) { if (is_usage_above_threshold) {
RAY_LOG_EVERY_MS(INFO, kLogIntervalMs) RAY_LOG_EVERY_MS(INFO, kLogIntervalMs)
<< "Node memory usage above threshold, used: " << used_memory_bytes << "Node memory usage above threshold, used: " << used_memory_bytes

View file

@ -101,6 +101,7 @@ class MemoryMonitor {
private: private:
FRIEND_TEST(MemoryMonitorTest, TestThresholdZeroMonitorAlwaysAboveThreshold); FRIEND_TEST(MemoryMonitorTest, TestThresholdZeroMonitorAlwaysAboveThreshold);
FRIEND_TEST(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold); FRIEND_TEST(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold);
FRIEND_TEST(MemoryMonitorTest, TestUsageAtThresholdReportsTrue);
FRIEND_TEST(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive); FRIEND_TEST(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive);
FRIEND_TEST(MemoryMonitorTest, TestGetNodeTotalMemoryEqualsFreeOrCGroup); FRIEND_TEST(MemoryMonitorTest, TestGetNodeTotalMemoryEqualsFreeOrCGroup);

View file

@ -29,7 +29,7 @@ TEST_F(MemoryMonitorTest, TestThresholdZeroMonitorAlwaysAboveThreshold) {
[](bool is_usage_above_threshold, [](bool is_usage_above_threshold,
MemorySnapshot system_memory, MemorySnapshot system_memory,
float usage_threshold) { FAIL() << "Expected monitor to not run"; }); float usage_threshold) { FAIL() << "Expected monitor to not run"; });
ASSERT_TRUE(monitor.IsUsageAboveThreshold()); ASSERT_TRUE(monitor.IsUsageAboveThreshold({1, 10}));
} }
TEST_F(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold) { TEST_F(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold) {
@ -39,7 +39,19 @@ TEST_F(MemoryMonitorTest, TestThresholdOneMonitorAlwaysBelowThreshold) {
[](bool is_usage_above_threshold, [](bool is_usage_above_threshold,
MemorySnapshot system_memory, MemorySnapshot system_memory,
float usage_threshold) { FAIL() << "Expected monitor to not run"; }); float usage_threshold) { FAIL() << "Expected monitor to not run"; });
ASSERT_FALSE(monitor.IsUsageAboveThreshold()); ASSERT_FALSE(monitor.IsUsageAboveThreshold({9, 10}));
}
TEST_F(MemoryMonitorTest, TestUsageAtThresholdReportsTrue) {
MemoryMonitor monitor(
0.5 /*usage_threshold*/,
0 /*refresh_interval_ms*/,
[](bool is_usage_above_threshold,
MemorySnapshot system_memory,
float usage_threshold) { FAIL() << "Expected monitor to not run"; });
ASSERT_FALSE(monitor.IsUsageAboveThreshold({4, 10}));
ASSERT_TRUE(monitor.IsUsageAboveThreshold({5, 10}));
ASSERT_TRUE(monitor.IsUsageAboveThreshold({6, 10}));
} }
TEST_F(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive) { TEST_F(MemoryMonitorTest, TestGetNodeAvailableMemoryAlwaysPositive) {