forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Trigger global gc when plasma store is under pressure. (ray-pr…
- Loading branch information
Showing
10 changed files
with
188 additions
and
17 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
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
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,52 @@ | ||
// Copyright 2017 The Ray Authors. | ||
// | ||
// 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:https://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 <functional> | ||
#include <iostream> | ||
#include "absl/time/clock.h" | ||
namespace ray { | ||
|
||
class Throttler { | ||
public: | ||
explicit Throttler(int64_t interval_ns, std::function<int64_t()> now = nullptr) | ||
: last_run_ns_(0), interval_ns_(interval_ns), now_(now) {} | ||
|
||
bool AbleToRun() { | ||
auto now = Now(); | ||
if (now - last_run_ns_ >= interval_ns_) { | ||
last_run_ns_ = now; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void RunNow() { last_run_ns_ = Now(); } | ||
|
||
private: | ||
int64_t Now() { | ||
if (now_) { | ||
return now_(); | ||
} else { | ||
return absl::GetCurrentTimeNanos(); | ||
} | ||
} | ||
|
||
uint64_t last_run_ns_; | ||
uint64_t interval_ns_; | ||
std::function<int64_t()> now_; | ||
}; | ||
|
||
} // namespace ray |
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,35 @@ | ||
// Copyright 2017 The Ray Authors. | ||
// | ||
// 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:https://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 "gtest/gtest.h" | ||
|
||
#include <cstdlib> | ||
#include <thread> | ||
|
||
#include "ray/util/throttler.h" | ||
|
||
TEST(ThrottlerTest, BasicTest) { | ||
int64_t now = 100; | ||
ray::Throttler throttler(5, [&now] { return now; }); | ||
EXPECT_TRUE(throttler.AbleToRun()); | ||
now += 5; | ||
EXPECT_TRUE(throttler.AbleToRun()); | ||
now += 1; | ||
EXPECT_FALSE(throttler.AbleToRun()); | ||
now += 4; | ||
throttler.RunNow(); | ||
EXPECT_FALSE(throttler.AbleToRun()); | ||
now += 5; | ||
EXPECT_TRUE(throttler.AbleToRun()); | ||
} |