Skip to content

Commit

Permalink
Fix running out of file descriptors in the WebUI (ray-project#6086)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz authored Nov 5, 2019
1 parent 043d1f4 commit fefe050
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions python/ray/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class RayletStats(threading.Thread):
def __init__(self, redis_address, redis_password=None):
self.nodes_lock = threading.Lock()
self.nodes = []
self.stubs = []
self.stubs = {}

self._raylet_stats_lock = threading.Lock()
self._raylet_stats = {}
Expand All @@ -378,13 +378,23 @@ def __init__(self, redis_address, redis_password=None):
def update_nodes(self):
with self.nodes_lock:
self.nodes = ray.nodes()
self.stubs = []
node_ids = [node["NodeID"] for node in self.nodes]

# First remove node connections of disconnected nodes.
for node_id in self.stubs.keys():
if node_id not in node_ids:
stub = self.stubs.pop(node_id)
stub.close()

# Now add node connections of new nodes.
for node in self.nodes:
channel = grpc.insecure_channel("{}:{}".format(
node["NodeManagerAddress"], node["NodeManagerPort"]))
stub = node_manager_pb2_grpc.NodeManagerServiceStub(channel)
self.stubs.append(stub)
node_id = node["NodeID"]
if node_id not in self.stubs:
channel = grpc.insecure_channel("{}:{}".format(
node["NodeManagerAddress"], node["NodeManagerPort"]))
stub = node_manager_pb2_grpc.NodeManagerServiceStub(
channel)
self.stubs[node_id] = stub

def get_raylet_stats(self) -> Dict:
with self._raylet_stats_lock:
Expand All @@ -395,7 +405,9 @@ def run(self):
while True:
time.sleep(1.0)
with self._raylet_stats_lock:
for node, stub in zip(self.nodes, self.stubs):
for node in self.nodes:
node_id = node["NodeID"]
stub = self.stubs[node_id]
reply = stub.GetNodeStats(
node_manager_pb2.NodeStatsRequest())
self._raylet_stats[node[
Expand Down

0 comments on commit fefe050

Please sign in to comment.