]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/BaseMgrModule: Optimize CPython Call in Finish Function 55110/head
authorNitzanMordhai <nmordech@redhat.com>
Thu, 23 Nov 2023 12:01:03 +0000 (12:01 +0000)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Tue, 9 Jan 2024 16:29:13 +0000 (23:29 +0700)
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 <nmordech@redhat.com>
(cherry picked from commit 247ace17086ddddd6b7bda44a067d4b1eaa238fd)

src/mgr/BaseMgrModule.cc

index ab64ac39fbedb1c1f0cbd379c91fd68b015a784b..6cb3a6bce2458d2cb00a6a487545f8163971ee78 100644 (file)
@@ -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;
     }