From 910cd68b4fab51bcaf4ddecf18bc31cb4b95a357 Mon Sep 17 00:00:00 2001 From: NitzanMordhai Date: Thu, 23 Nov 2023 12:01:03 +0000 Subject: [PATCH] mgr/BaseMgrModule: Optimize CPython Call in Finish Function Remove CPython overhead packing tuple during the 'finish' function to improve memory consumption when we deal with long-string outputs. When modules like Restful return large amounts of output the use of PyObject_CallFunction without createing PyObject will reduce the time the memory held by the mgr. Fixes: https://tracker.ceph.com/issues/59580 Signed-off-by: Nitzan Mordechai (cherry picked from commit 247ace17086ddddd6b7bda44a067d4b1eaa238fd) --- src/mgr/BaseMgrModule.cc | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index b913d4c98fed..1b1f418a2b50 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -90,22 +90,13 @@ public: auto set_fn = PyObject_GetAttrString(python_completion, "complete"); ceph_assert(set_fn != nullptr); - - auto pyR = PyLong_FromLong(r); - auto pyOutBl = PyUnicode_FromString(outbl.to_str().c_str()); - auto pyOutS = PyUnicode_FromString(outs.c_str()); - auto args = PyTuple_Pack(3, pyR, pyOutBl, pyOutS); - Py_DECREF(pyR); - Py_DECREF(pyOutBl); - Py_DECREF(pyOutS); - - auto rtn = PyObject_CallObject(set_fn, args); - if (rtn != nullptr) { - Py_DECREF(rtn); + auto rtn = PyObject_CallFunction(set_fn, "(iss)", r, outbl.to_str().c_str(), outs.c_str()); + if (rtn == nullptr) { + PyErr_Print(); + } else { + Py_DECREF(rtn); } - Py_DECREF(args); Py_DECREF(set_fn); - Py_DECREF(python_completion); python_completion = nullptr; } -- 2.47.3