Compare commits

..

No commits in common. "5afd66837950c63af0035e3b3f314fdaf68cab2b" and "4f035b6d5336e103b8f0e853d87657b75d09a95e" have entirely different histories.

2 changed files with 3 additions and 30 deletions

View File

@ -99,12 +99,8 @@ class ClusterCommunicationModule():
self.node_manager.status = 'none' self.node_manager.status = 'none'
print("You have leaved the cluster.") print("You have leaved the cluster.")
return False
elif command == '[START_LISTEN_TASK]':
self.client_sock.send('[START_LISTEN_TASK_CHECK] {}'.encode())
print("The master has started listening for new task from Sepolia testnet...")
return True return False
def request(self, host): # master side def request(self, host): # master side
@ -140,20 +136,6 @@ class ClusterCommunicationModule():
print("1 worker disconnnected.") print("1 worker disconnnected.")
return ans return ans
def start_listen_task(self):
disconnected_counter = 0
for conn in self.worker_conns:
try:
conn.send('[START_LISTEN_TASK] {}'.encode())
data, args = conn.recv(1024).decode().split(' ')
except:
disconnected_counter += 1
self.worker_conns.remove(conn)
if disconnected_counter != 0:
print(f'{disconnected_counter} worker disconnected.')
else:
print(f'All other {len(self.worker_conns)} workers are waiting...')
def exit(self): def exit(self):
if self.node_manager.status == 'master': if self.node_manager.status == 'master':
for conn in self.worker_conns: for conn in self.worker_conns:
@ -190,6 +172,7 @@ class ServiceExplorationModule():
while True: while True:
data, addr = self.sock.recvfrom(1024) data, addr = self.sock.recvfrom(1024)
print(self.node_manager.status)
if self.node_manager.status == 'none': if self.node_manager.status == 'none':
if data.decode() == '[EXPLORE]': if data.decode() == '[EXPLORE]':
self.sock.sendto(self.host.encode(), addr) self.sock.sendto(self.host.encode(), addr)

View File

@ -3,8 +3,6 @@ from src.communication import ServiceExplorationModule, ClusterCommunicationModu
import torch import torch
import time import time
import docker import docker
from web3 import Web3
from src.scheduler import Scheduler
class NodeManager(): class NodeManager():
def __init__(self, host, port): def __init__(self, host, port):
@ -27,9 +25,6 @@ class NodeManager():
# docker client # docker client
self.docker_client = docker.from_env() self.docker_client = docker.from_env()
# web3 provider
self.w3 = Web3(Web3.HTTPProvider('https://eth-sepolia.g.alchemy.com/v2/'+ALCHEMY_KEY))
time.sleep(2) time.sleep(2)
def get_GPU_info(self): def get_GPU_info(self):
@ -64,7 +59,7 @@ class NodeManager():
self.actions = [ self.actions = [
{'explanation': 'Add another node into our cluster', 'function': 'add_node'}, {'explanation': 'Add another node into our cluster', 'function': 'add_node'},
{'explanation': 'Cluster info', 'function': 'cluster_info'}, {'explanation': 'Cluster info', 'function': 'cluster_info'},
{'explanation': 'Start waiting for the new task', 'function': 'start_listen_task'}, {'explanation': 'Start working', 'function': 'start_work'},
{'explanation': 'Exit', 'function': 'exit'}, {'explanation': 'Exit', 'function': 'exit'},
] ]
except: except:
@ -72,11 +67,6 @@ class NodeManager():
else: else:
print("No other nodes in your subnet.") print("No other nodes in your subnet.")
def start_listen_task(self):
print("Waiting for the new task from Sepolia testnet...")
self.cluster_communication_module.start_listen_task()
def cluster_info(self): def cluster_info(self):
info = self.cluster_communication_module.cluster_info() info = self.cluster_communication_module.cluster_info()
print(f"\nThere are {len(info)+1} nodes in this cluster.") print(f"\nThere are {len(info)+1} nodes in this cluster.")