[docs] Add example showing how to use Ray on Kubernetes. (#3126)

Closes #1353.
This commit is contained in:
jhpenger
2019-01-13 13:56:47 -08:00
committed by Richard Liaw
parent 8674606e26
commit 3adffe6a4e
6 changed files with 358 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from collections import Counter
import socket
import sys
import time
import ray
if __name__ == "__main__":
ray.init(redis_address="{}:6379".format(socket.gethostbyname("ray-head")))
# Wait for all 4 nodes to join the cluster.
while True:
num_nodes = len(ray.global_state.client_table())
if num_nodes < 4:
print("{} nodes have joined so far. Waiting for more."
.format(num_nodes))
sys.stdout.flush()
time.sleep(1)
else:
break
@ray.remote
def f(x):
time.sleep(0.01)
return x + (ray.services.get_node_ip_address(), )
# Check that objects can be transferred from each node to each other node.
for i in range(100):
print("Iteration {}".format(i))
sys.stdout.flush()
print(Counter(ray.get([f.remote(f.remote(())) for _ in range(10000)])))
sys.stdout.flush()
print("Success!")
sys.stdout.flush()