This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
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.
Add available resources to global state (ray-project#2501)
- Loading branch information
1 parent
611259b
commit 5da6e78
Showing
6 changed files
with
196 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import time | ||
|
||
import ray | ||
|
||
|
||
def setup_module(): | ||
if not ray.worker.global_worker.connected: | ||
ray.init(num_cpus=1) | ||
|
||
# Finish initializing Ray. Otherwise available_resources() does not | ||
# reflect resource use of submitted tasks | ||
ray.get(cpu_task.remote(0)) | ||
|
||
|
||
@ray.remote(num_cpus=1) | ||
def cpu_task(seconds): | ||
time.sleep(seconds) | ||
|
||
|
||
class TestAvailableResources(object): | ||
timeout = 10 | ||
|
||
def test_no_tasks(self): | ||
cluster_resources = ray.global_state.cluster_resources() | ||
available_resources = ray.global_state.cluster_resources() | ||
assert cluster_resources == available_resources | ||
|
||
def test_replenish_resources(self): | ||
cluster_resources = ray.global_state.cluster_resources() | ||
|
||
ray.get(cpu_task.remote(0)) | ||
start = time.time() | ||
resources_reset = False | ||
|
||
while not resources_reset and time.time() - start < self.timeout: | ||
resources_reset = ( | ||
cluster_resources == ray.global_state.available_resources()) | ||
|
||
assert resources_reset | ||
|
||
def test_uses_resources(self): | ||
cluster_resources = ray.global_state.cluster_resources() | ||
task_id = cpu_task.remote(1) | ||
start = time.time() | ||
resource_used = False | ||
|
||
while not resource_used and time.time() - start < self.timeout: | ||
available_resources = ray.global_state.available_resources() | ||
resource_used = available_resources[ | ||
"CPU"] == cluster_resources["CPU"] - 1 | ||
|
||
assert resource_used | ||
|
||
ray.get(task_id) # clean up to reset resources |
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