]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/balancer: optimize 'balancer status detail'
authorLaura Flores <lflores@ibm.com>
Mon, 28 Oct 2024 22:40:13 +0000 (22:40 +0000)
committerLaura Flores <lflores@ibm.com>
Tue, 12 Nov 2024 20:56:39 +0000 (20:56 +0000)
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 <lflores@ibm.com>
(cherry picked from commit 31c498da96fa1acc1700515edcd544dead86dab9)

src/pybind/mgr/balancer/module.py

index c98ce9aec41c23ef8607dd88838f458e21f7e790..cb5a75f68d29bb9fdca84d68fd9dd583aa5a99d8 100644 (file)
@@ -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