2021-07-30 10:20:19 -07:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import ray
|
2021-08-18 20:56:33 -07:00
|
|
|
import ray._private.test_utils as test_utils
|
2021-07-30 10:20:19 -07:00
|
|
|
import time
|
|
|
|
import tqdm
|
|
|
|
|
|
|
|
if "SMOKE_TEST" in os.environ:
|
|
|
|
MAX_ACTORS_IN_CLUSTER = 100
|
|
|
|
else:
|
|
|
|
MAX_ACTORS_IN_CLUSTER = 10000
|
|
|
|
|
|
|
|
|
|
|
|
def test_max_actors():
|
|
|
|
# TODO (Alex): Dynamically set this based on number of cores
|
|
|
|
cpus_per_actor = 0.25
|
|
|
|
|
|
|
|
@ray.remote(num_cpus=cpus_per_actor)
|
|
|
|
class Actor:
|
|
|
|
def foo(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
actors = [
|
|
|
|
Actor.remote()
|
|
|
|
for _ in tqdm.trange(MAX_ACTORS_IN_CLUSTER, desc="Launching actors")
|
|
|
|
]
|
|
|
|
|
|
|
|
not_ready = [actor.foo.remote() for actor in actors]
|
|
|
|
|
|
|
|
for _ in tqdm.trange(len(actors)):
|
|
|
|
ready, not_ready = ray.wait(not_ready)
|
|
|
|
assert ray.get(*ready) is None
|
|
|
|
|
|
|
|
|
|
|
|
def no_resource_leaks():
|
2022-03-14 19:49:15 +09:00
|
|
|
return test_utils.no_resource_leaks_excluding_node_resources()
|
2021-07-30 10:20:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
ray.init(address="auto")
|
|
|
|
|
|
|
|
test_utils.wait_for_condition(no_resource_leaks)
|
2021-12-15 18:31:38 +09:00
|
|
|
monitor_actor = test_utils.monitor_memory_usage()
|
2021-07-30 10:20:19 -07:00
|
|
|
start_time = time.time()
|
|
|
|
test_max_actors()
|
|
|
|
end_time = time.time()
|
2021-12-15 18:31:38 +09:00
|
|
|
ray.get(monitor_actor.stop_run.remote())
|
|
|
|
used_gb, usage = ray.get(monitor_actor.get_peak_memory_info.remote())
|
|
|
|
print(f"Peak memory usage: {round(used_gb, 2)}GB")
|
|
|
|
print(f"Peak memory usage per processes:\n {usage}")
|
2021-12-21 07:58:39 +09:00
|
|
|
del monitor_actor
|
2021-07-30 10:20:19 -07:00
|
|
|
test_utils.wait_for_condition(no_resource_leaks)
|
|
|
|
|
|
|
|
rate = MAX_ACTORS_IN_CLUSTER / (end_time - start_time)
|
2022-01-29 18:41:57 -08:00
|
|
|
print(
|
|
|
|
f"Success! Started {MAX_ACTORS_IN_CLUSTER} actors in "
|
|
|
|
f"{end_time - start_time}s. ({rate} actors/s)"
|
|
|
|
)
|
2021-07-30 10:20:19 -07:00
|
|
|
|
|
|
|
if "TEST_OUTPUT_JSON" in os.environ:
|
|
|
|
out_file = open(os.environ["TEST_OUTPUT_JSON"], "w")
|
|
|
|
results = {
|
|
|
|
"actors_per_second": rate,
|
|
|
|
"num_actors": MAX_ACTORS_IN_CLUSTER,
|
|
|
|
"time": end_time - start_time,
|
2021-12-15 18:31:38 +09:00
|
|
|
"success": "1",
|
|
|
|
"_peak_memory": round(used_gb, 2),
|
2022-01-29 18:41:57 -08:00
|
|
|
"_peak_process_memory": usage,
|
2021-07-30 10:20:19 -07:00
|
|
|
}
|
|
|
|
json.dump(results, out_file)
|