Skip to content

Commit

Permalink
Merge pull request #5865 from grondo/flux-resource-fixups
Browse files Browse the repository at this point in the history
fix more performance issues in `flux resource`
  • Loading branch information
mergify[bot] committed Apr 7, 2024
2 parents 0766987 + d933e82 commit 42fdaaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/bindings/python/flux/resource/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,21 @@ def _recalculate(self, include_ranks=None):

# drain_info: ranks, timestamp, reason tuples for all drained resources
self.drain_info = []
self._drain_lookup = {}
for drain_ranks, entry in self.rstatus["drain"].items():
ranks = IDset(drain_ranks)
if include_ranks is not None:
ranks = ranks.intersect(include_ranks)
self.drained += ranks - self.allocated
self.draining += ranks - self.drained
self.drained += ranks
info = DrainInfo(ranks, entry["timestamp"], entry["reason"])
self.drain_info.append(info)
for rank in ranks:
self._drain_lookup[rank] = info

# create the set of draining ranks as the intersection of
# drained and allocated
self.draining = self.drained & self.allocated
self.drained -= self.draining

# available: all ranks not excluded or drained/draining
self.avail = self.all - self.get_idset("exclude", "drained", "draining")
Expand All @@ -142,7 +149,7 @@ def get_drain_info(self, rank):
"""
if rank not in self.all:
raise ValueError("invalid rank {rank}")
return next((i for i in self.drain_info if rank in i.ranks), None)
return self._drain_lookup.get(rank)


class ResourceStatusRPC:
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/flux-resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ def propertiesx(self):
def queue(self):
queues = ""
if self.flux_config and "queues" in self.flux_config:
if not self.ranks:
return ""
properties = json.loads(self.get_properties())
for key, value in self.flux_config["queues"].items():
if not self.rlist:
continue
if "requires" not in value or set(value["requires"]).issubset(
set(properties)
):
Expand Down

0 comments on commit 42fdaaa

Please sign in to comment.