Skip to content

Commit 31c498d

Browse files
author
Laura Flores
committed
mgr/balancer: optimize 'balancer status detail'
Before, we were updating the balancer status by iterating through all pg upmap entires. This was affecting the loading time of other mgr modules on clusters with a large number of pgs (600+). This can be optimized by simply pulling from the incremental. Fixes: https://tracker.ceph.com/issues/68657 Signed-off-by: Laura Flores <[email protected]>
1 parent 4b3747a commit 31c498d

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/pybind/mgr/balancer/module.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,10 @@ class Module(MgrModule):
339339
no_optimization_needed = False
340340
success_string = 'Optimization plan created successfully'
341341
in_progress_string = 'in progress'
342-
last_pg_upmap: List[Dict[str, Any]] = []
343342
pg_upmap_items_added: List[Dict[str, Any]] = []
344343
pg_upmap_items_removed: List[Dict[str, Any]] = []
345-
last_pg_upmap_primaries: List[Dict[str, Any]] = []
346344
pg_upmap_primaries_added: List[Dict[str, Any]] = []
347-
pg_upmap_activity_initalized = False
345+
pg_upmap_primaries_removed: List[Dict[str, Any]] = []
348346

349347
def __init__(self, *args: Any, **kwargs: Any) -> None:
350348
super(Module, self).__init__(*args, **kwargs)
@@ -665,7 +663,7 @@ def plan_execute(self, plan: str) -> Tuple[int, str, str]:
665663
if not plan_:
666664
return (-errno.ENOENT, '', f'plan {plan} not found')
667665
r, detail = self.execute(plan_)
668-
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
666+
self.update_pg_upmap_activity(plan_) # update pg activity in `balancer status detail`
669667
self.plan_rm(plan)
670668
return (r, '', detail)
671669

@@ -757,7 +755,7 @@ def serve(self) -> None:
757755
self.execute(plan)
758756
else:
759757
self.optimize_result = detail
760-
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
758+
self.update_pg_upmap_activity(plan) # update pg activity in `balancer status detail`
761759
self.optimizing = False
762760
self.log.debug('Sleeping for %d', sleep_interval)
763761
self.event.wait(sleep_interval)
@@ -1582,22 +1580,16 @@ def gather_telemetry(self) -> Dict[str, Any]:
15821580
'mode': self.mode,
15831581
}
15841582

1585-
def update_pg_upmap_activity(self) -> None:
1586-
osdmap = self.get_osdmap()
1587-
if not self.pg_upmap_activity_initalized:
1588-
self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '')
1589-
self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '')
1590-
self.pg_upmap_activity_initalized = True
1583+
def update_pg_upmap_activity(self, plan: Plan) -> None:
1584+
incdump = plan.inc.dump()
15911585

15921586
# update pg_upmap_items
1593-
self.pg_upmap_items_added = [pg for pg in osdmap.dump().get('pg_upmap_items', '') if pg not in self.last_pg_upmap]
1594-
self.pg_upmap_items_removed = [pg for pg in self.last_pg_upmap if pg not in osdmap.dump().get('pg_upmap_items', '')]
1595-
self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '')
1587+
self.pg_upmap_items_added = incdump.get('new_pg_upmap_items', [])
1588+
self.pg_upmap_items_removed = incdump.get('old_pg_upmap_items', [])
15961589

15971590
# update pg_upmap_primaries
1598-
self.pg_upmap_primaries_added = [pg for pg in osdmap.dump().get('pg_upmap_primaries', '') if pg not in self.last_pg_upmap_primaries]
1599-
self.pg_upmap_primaries_removed = [pg for pg in self.last_pg_upmap_primaries if pg not in osdmap.dump().get('pg_upmap_primaries', '')]
1600-
self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '')
1591+
self.pg_upmap_primaries_added = incdump.get('new_pg_upmap_primaries', [])
1592+
self.pg_upmap_primaries_removed = incdump.get('old_pg_upmap_primaries', [])
16011593

16021594
def self_test(self) -> None:
16031595
# turn balancer on

0 commit comments

Comments
 (0)