Repository navigation
mgr: read cached maps in prometheus, pg_autoscaler and balancer - #72754
NitzanMordhai wants to merge 3 commits into
Conversation
1204717 to
82785bb
Compare
|
@ljflores when you have a moment, could you review this? It has been waiting since 10-15. |
| return self.get('osd_map') | ||
|
|
||
| def get_osdmap_flags(self) -> str: | ||
| return self.get_osdmap_dump().get('flags', '') |
There was a problem hiding this comment.
Just curious, why is "the cache may already hold a newer osdmap" logic applied only for pools (in get_osdmap_pools_by_name()) but not for flags or require_osd_release fields? Is it not a concern that e.g. noautoscale flag may be set in OSDMap object that _maybe_adjust() is called on but unset in the cache that has_noautoscale_flag() would go by when _maybe_adjust() calls it?
There was a problem hiding this comment.
Good question. The flags were never read from the OSDMap object passed to _maybe_adjust().
Before this change, has_noautoscale_flag() and has_norecover_flag() called self.get_osdmap().dump(), which fetches a fresh map on every call, so they could already disagree with the osdmap argument. serve() also checks them before it calls get_osdmap().
I kept that behavior and just read the same latest map from the cache without the dump. For a gate like noautoscale, the newest value is the one we want anyway: if the flag was set an epoch later, we should honor it.
Pools are different because the code uses them together with the OSDMap object (CRUSH rule lookups, pool ids, pg_num in _get_pool_status()).
If the two came from different epochs, a pool created or deleted in between would exist in one and not the other, and that can break the calculation. That's why only the pools get the epoch check.
require_osd_release only ever moves forward, and the check is < 'nautilus', so being an epoch apart can't change the result. I moved it to the cache because OSDMap.get_require_osd_release() does a full _dump() internally. If you'd prefer it to come from the same epoch for consistency, I can add the epoch check there too.
There was a problem hiding this comment.
Before this change, has_noautoscale_flag() and has_norecover_flag() called self.get_osdmap().dump(), which fetches a fresh map on every call, so they could already disagree with the osdmap argument.
Ah, I didn't realize that. This means that they could disagree not only with osdmap which is passed in but also with each other (has_noautoscale_flag() using epoch N and has_norecover_flag() using epoch N + 1). This PR doesn't make it worse in any way.
If you'd prefer it to come from the same epoch for consistency, I can add the epoch check there too.
Given the above, I don't think it's necessary. Plus this check against nautilus OSDs is more or less dead anyway.
| def get_osdmap_pools_by_name(self, osdmap: OSDMap) -> Dict[str, Dict[str, Any]]: | ||
| # the cache may already hold a newer osdmap | ||
| dump = self.get_osdmap_dump() | ||
| if dump.get('epoch') != osdmap.get_epoch(): | ||
| dump = osdmap.dump() | ||
| return {p['pool_name']: p for p in dump.get('pools', [])} | ||
|
|
||
| def get_osdmap_require_osd_release(self) -> str: | ||
| return self.get_osdmap_dump().get('require_osd_release', '') |
kamoltat
left a comment
There was a problem hiding this comment.
autoscaler change LGTM, maybe add a stale cache test case?
There was a problem hiding this comment.
Should we include a stale cached scenario as well? Where OSDMAP is 11 and cache is 10?
There was a problem hiding this comment.
the mgr cache is invalidating old maps as soon as new maps arrived, we have set of checks inside the mgr cache
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
|
||
| class Plan(object): | ||
| def __init__(self, name, mode, osdmap, pools): | ||
| def __init__(self, name, mode, osdmap, pools, osdmap_dump=None): |
There was a problem hiding this comment.
I'm fine with the overall idea, but passing in a "None" object to get the osd dump to update to the latest dump isn't totally intuitive, IMO.
Maybe passing in an optional boolean would be a bit better, like:
def __init__(self, name, mode, osdmap, pools, refresh_osdmap=False):
self.osdmap_dump = osdmap.dump() if refresh_osdmap else osdmap_dump
# the cache may already hold a newer osdmap
refresh_osdmap = False
dump = self.get('osd_map')
if dump.get('epoch') != osdmap.get_epoch():
refresh_osdmap = True
plan = Plan(name, mode, osdmap, pools, refresh_osdmap)
There was a problem hiding this comment.
Otherwise, LGTM! I'll approve for the balancer after this is addressed. Again, it's not a problem with the concept but just to make the code more intuitive.
There was a problem hiding this comment.
@ljflores thanks! i used your idea a bit differently - so i think its more readable now - use_cached_dump
get_pool_repaired_objects() only uses the pool_stats array, but fetched
the whole pg_dump, which builds a Python object for every PG and OSD
while holding the GIL. get('pool_stats') returns the same array, as
both come from PGMap::dump_pool_stats(), so the metric is unchanged.
With 50 OSDs and 16k PGs, get('pg_dump') took 144ms and
get('pool_stats') 0.04ms.
Also add @profile_method() to get_pool_repaired_objects(),
get_all_daemon_health_metrics() and get_perf_counters(), the only
collect() steps missing from prometheus_collect_duration_seconds.
https://tracker.ceph.com/issues/81902
Signed-off-by: Nitzan Mordechai <[email protected]>
Assisted-by: Claude
has_noautoscale_flag(), has_norecover_flag(), get_pools_by_name() and
get_require_osd_release() each built a Python object for the whole
OSDMap just to read a few fields, several times per serve() loop and
while holding the GIL.
Read those fields from self.get('osd_map') instead: the same
OSDMap::dump() output, served from the api cache and dropped on every
new osdmap. The OSDMap object is still used for pool_raw_used_rate()
and get_crush(), so the pool list is taken from the cache only when its
epoch matches that object; otherwise a pool created after get_osdmap()
would make pool_raw_used_rate() fail and stop serve().
With 24 OSDs and 8192 PGs, py-spy --gil put get_pools_by_name() and
get_require_osd_release() at about 40% of all mgr module GIL time.
https://tracker.ceph.com/issues/81902
Signed-off-by: Nitzan Mordechai <[email protected]>
Assisted-by: Claude
Plan.__init__() calls osdmap.dump(), which builds a Python object for
the whole OSDMap on every balancer run. With 24 OSDs and 8192 PGs,
py-spy --gil put it at about 22% of all mgr module GIL time.
plan_create() now passes self.get('osd_map'), the same OSDMap::dump()
output served from the api cache, when its epoch matches the map
being passed. A new osdmap can land after get_osdmap(), and a pool
missing from that map would make balance_primaries() fail, so on a
mismatch Plan dumps the map as before.
The parameter is optional: MsPlan and show() work from a modified or
stored map and still dump that map.
Fixes: https://tracker.ceph.com/issues/81902
Signed-off-by: Nitzan Mordechai <[email protected]>
Assisted-by: Claude
82785bb to
ffa53d3
Compare
|
This PR has been added to wip-bharath3-testing-20261127.055027-main. |
Three mgr modules rebuilt large Python objects (the full pg_dump or a full
OSDMap dump) on every loop, while holding the GIL, just to read a few fields.
The same data is already available, either from a smaller key or from the
mgr's api cache.
get_pool_repaired_objects()readspool_statsinstead ofthe whole
pg_dump(samePGMap::dump_pool_stats()output). Also adds@profile_method()to the threecollect()steps that were missing fromprometheus_collect_duration_seconds.require_osd_releasecome from thecached
osd_mapinstead ofOSDMap.dump(). The pool list is used with theOSDMapobject, so it is taken from the cache only when the epochs match.Planuses the cachedosd_mapinstead ofosdmap.dump(),with the same epoch check.
Testing
test covers a cached dump that is newer than the
OSDMap.mgr_stats_period=5, autotune off, 600s sampling):Fixes: https://tracker.ceph.com/issues/81902
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.