Created
September 12, 2025 13:30
-
-
Save delagoya/e551e5e81a1d1b41a2d9016baf834634 to your computer and use it in GitHub Desktop.
Ray Scripts
This file contains hidden or 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
| #!/usr/bin/env python | |
| from collections import Counter | |
| import socket | |
| import time | |
| import ray | |
| ray.init() | |
| print('''This cluster consists of | |
| {} nodes in total | |
| {} CPU resources in total | |
| '''.format(len(ray.nodes()), ray.cluster_resources()['CPU'])) | |
| @ray.remote | |
| def f(): | |
| time.sleep(0.001) | |
| # Return IP address. | |
| return socket.gethostbyname("localhost") | |
| object_ids = [f.remote() for _ in range(10000)] | |
| ip_addresses = ray.get(object_ids) | |
| print('Tasks executed') | |
| for ip_address, num_tasks in Counter(ip_addresses).items(): | |
| print(' {} tasks on {}'.format(num_tasks, ip_address)) |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import ray | |
| from time import sleep | |
| import platform | |
| import logging | |
| ray.init() | |
| logger = logging.getLogger("ray.worker") | |
| logger.setLevel(logging.DEBUG) | |
| @ray.remote | |
| def hello_world(): | |
| return "Hello from Worker %s" % platform.node() | |
| for x in range(50): | |
| print(ray.get(hello_world.remote()), flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment