2019-11-14 15:06:05 -08:00
|
|
|
import sys
|
|
|
|
import time
|
2022-06-15 11:34:45 -07:00
|
|
|
from collections import Counter
|
|
|
|
|
2019-11-14 15:06:05 -08:00
|
|
|
import ray
|
|
|
|
|
|
|
|
|
|
|
|
@ray.remote
|
2022-01-27 02:14:25 +01:00
|
|
|
def get_host_name(x):
|
2020-06-08 21:29:46 -07:00
|
|
|
import platform
|
2019-11-14 15:06:05 -08:00
|
|
|
import time
|
2022-01-29 18:41:57 -08:00
|
|
|
|
2019-11-14 15:06:05 -08:00
|
|
|
time.sleep(0.01)
|
2020-06-08 21:29:46 -07:00
|
|
|
return x + (platform.node(),)
|
2019-11-14 15:06:05 -08:00
|
|
|
|
|
|
|
|
|
|
|
def wait_for_nodes(expected):
|
|
|
|
# Wait for all nodes to join the cluster.
|
|
|
|
while True:
|
|
|
|
num_nodes = len(ray.nodes())
|
|
|
|
if num_nodes < expected:
|
|
|
|
print(
|
|
|
|
"{} nodes have joined so far, waiting for {} more.".format(
|
|
|
|
num_nodes, expected - num_nodes
|
|
|
|
)
|
2022-01-29 18:41:57 -08:00
|
|
|
)
|
2019-11-14 15:06:05 -08:00
|
|
|
sys.stdout.flush()
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
wait_for_nodes(4)
|
|
|
|
|
|
|
|
# Check that objects can be transferred from each node to each other node.
|
|
|
|
for i in range(10):
|
|
|
|
print("Iteration {}".format(i))
|
2022-01-27 02:14:25 +01:00
|
|
|
results = [get_host_name.remote(get_host_name.remote(())) for _ in range(100)]
|
2019-11-14 15:06:05 -08:00
|
|
|
print(Counter(ray.get(results)))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
print("Success!")
|
|
|
|
sys.stdout.flush()
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-07-07 13:44:41 -07:00
|
|
|
ray.init(address="localhost:6379")
|
2019-11-14 15:06:05 -08:00
|
|
|
main()
|