From: NitzanMordhai Date: Thu, 23 Nov 2023 12:01:03 +0000 (+0000) Subject: mgr/BaseMgrModule: Optimize CPython Call in Finish Function X-Git-Tag: v17.2.8~125^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46584b01a936a9434fa01fb624a6b43ed32542ba;p=ceph.git 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) --- diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index ab64ac39fbed..6cb3a6bce245 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -92,22 +92,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; }