Skip to content

Commit b0ecae0

Browse files
committed
python: improve resource.status with many drained ranks
Problem: The ResourceStatus class performs a couple unnecessary idset set operations for each drain entry in the resource.status response object. When there are many entries, these set operations perform a lot of unnecesary work and slow down the _recalcultate() method. Build the set of drained ranks in the loop (which should be fast), and delay splitting the set into drained and draining after the loop.
1 parent 0766987 commit b0ecae0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/bindings/python/flux/resource/status.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ def _recalculate(self, include_ranks=None):
112112
ranks = IDset(drain_ranks)
113113
if include_ranks is not None:
114114
ranks = ranks.intersect(include_ranks)
115-
self.drained += ranks - self.allocated
116-
self.draining += ranks - self.drained
115+
self.drained += ranks
117116
info = DrainInfo(ranks, entry["timestamp"], entry["reason"])
118117
self.drain_info.append(info)
119118

119+
# create the set of draining ranks as the intersection of
120+
# drained and allocated
121+
self.draining = self.drained & self.allocated
122+
self.drained -= self.draining
123+
120124
# available: all ranks not excluded or drained/draining
121125
self.avail = self.all - self.get_idset("exclude", "drained", "draining")
122126

0 commit comments

Comments
 (0)