From 363db9925a2cf6960e25de278e1e438b738c39f8 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Fri, 12 Apr 2024 13:30:26 +0200 Subject: [PATCH] * use ip instead of hostname in examples (#230) * decrease default budget to 1 --- examples/outbound_tester.py | 8 +++++++- examples/simple-actor.py | 8 +++++++- examples/simple-task.py | 8 +++++++- golem-cluster.yaml | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/outbound_tester.py b/examples/outbound_tester.py index b57e9554..f3adaf8e 100644 --- a/examples/outbound_tester.py +++ b/examples/outbound_tester.py @@ -33,6 +33,12 @@ ray.init() +def get_own_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("192.168.0.1", 1)) + return s.getsockname()[0] + + @dataclass class UrlResult: node_ip: str @@ -54,7 +60,7 @@ def exc_causes(e: BaseException): @ray.remote def get_url_len(url: str, num_attempts: int, timeout: int, keep_alive: bool) -> UrlResult: - node_ip = socket.gethostbyname(socket.gethostname()) + node_ip = get_own_ip() start = datetime.now() def seconds(): diff --git a/examples/simple-actor.py b/examples/simple-actor.py index f65c2e17..92f9a5a0 100644 --- a/examples/simple-actor.py +++ b/examples/simple-actor.py @@ -7,6 +7,12 @@ ray.init() +def get_own_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("192.168.0.1", 1)) + return s.getsockname()[0] + + @ray.remote class CounterActor: def __init__(self): @@ -17,7 +23,7 @@ def increment(self): time.sleep(0.5) self.value += 1 - node_ip = socket.gethostname() + node_ip = get_own_ip() self.node_ips.append(node_ip) return node_ip diff --git a/examples/simple-task.py b/examples/simple-task.py index 0aed8364..600aa2f7 100644 --- a/examples/simple-task.py +++ b/examples/simple-task.py @@ -8,6 +8,12 @@ ray.init() +def get_own_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("192.168.0.1", 1)) + return s.getsockname()[0] + + def output_cluster_info(): print( """This cluster consists of @@ -28,7 +34,7 @@ def output_cluster_info(): def f(): time.sleep(0.5) - return socket.gethostname() + return get_own_ip() # get the number of remote calls from the command line diff --git a/golem-cluster.yaml b/golem-cluster.yaml index adea28a8..fc140a0d 100644 --- a/golem-cluster.yaml +++ b/golem-cluster.yaml @@ -26,7 +26,7 @@ provider: #payment_network: "polygon" # Maximum amount of GLMs that's going to be spent for the whole cluster - total_budget: 5 + total_budget: 1 # Common parameters for all node types. Can be overridden in available_node_types node_config: