From f7e13bd9eb4031c492e1904bf04128686cf9526d Mon Sep 17 00:00:00 2001 From: Laura Flores Date: Mon, 28 Oct 2024 22:40:13 +0000 Subject: [PATCH] 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 (cherry picked from commit 31c498da96fa1acc1700515edcd544dead86dab9) --- src/pybind/mgr/balancer/module.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index c98ce9aec41..cb5a75f68d2 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -339,12 +339,10 @@ class Module(MgrModule): no_optimization_needed = False success_string = 'Optimization plan created successfully' in_progress_string = 'in progress' - last_pg_upmap: List[Dict[str, Any]] = [] pg_upmap_items_added: List[Dict[str, Any]] = [] pg_upmap_items_removed: List[Dict[str, Any]] = [] - last_pg_upmap_primaries: List[Dict[str, Any]] = [] pg_upmap_primaries_added: List[Dict[str, Any]] = [] - pg_upmap_activity_initalized = False + pg_upmap_primaries_removed: List[Dict[str, Any]] = [] def __init__(self, *args: Any, **kwargs: Any) -> None: super(Module, self).__init__(*args, **kwargs) @@ -665,7 +663,7 @@ class Module(MgrModule): if not plan_: return (-errno.ENOENT, '', f'plan {plan} not found') r, detail = self.execute(plan_) - self.update_pg_upmap_activity() # update pg activity in `balancer status detail` + self.update_pg_upmap_activity(plan_) # update pg activity in `balancer status detail` self.plan_rm(plan) return (r, '', detail) @@ -757,7 +755,7 @@ class Module(MgrModule): self.execute(plan) else: self.optimize_result = detail - self.update_pg_upmap_activity() # update pg activity in `balancer status detail` + self.update_pg_upmap_activity(plan) # update pg activity in `balancer status detail` self.optimizing = False self.log.debug('Sleeping for %d', sleep_interval) self.event.wait(sleep_interval) @@ -1582,22 +1580,16 @@ class Module(MgrModule): 'mode': self.mode, } - def update_pg_upmap_activity(self) -> None: - osdmap = self.get_osdmap() - if not self.pg_upmap_activity_initalized: - self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '') - self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '') - self.pg_upmap_activity_initalized = True + def update_pg_upmap_activity(self, plan: Plan) -> None: + incdump = plan.inc.dump() # update pg_upmap_items - self.pg_upmap_items_added = [pg for pg in osdmap.dump().get('pg_upmap_items', '') if pg not in self.last_pg_upmap] - self.pg_upmap_items_removed = [pg for pg in self.last_pg_upmap if pg not in osdmap.dump().get('pg_upmap_items', '')] - self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '') + self.pg_upmap_items_added = incdump.get('new_pg_upmap_items', []) + self.pg_upmap_items_removed = incdump.get('old_pg_upmap_items', []) # update pg_upmap_primaries - self.pg_upmap_primaries_added = [pg for pg in osdmap.dump().get('pg_upmap_primaries', '') if pg not in self.last_pg_upmap_primaries] - self.pg_upmap_primaries_removed = [pg for pg in self.last_pg_upmap_primaries if pg not in osdmap.dump().get('pg_upmap_primaries', '')] - self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '') + self.pg_upmap_primaries_added = incdump.get('new_pg_upmap_primaries', []) + self.pg_upmap_primaries_removed = incdump.get('old_pg_upmap_primaries', []) def self_test(self) -> None: # turn balancer on -- 2.39.5