From 5ed75f7b7b63b3743830a6bdb2e7280106e14d43 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 8 Apr 2020 07:22:27 +0200 Subject: [PATCH] No more copy, between PyBytes and CORBA sequence. Reduce Memory peak by spliting send of input pickelised object and execution and output pickelised object --- src/runtime/AutoGIL.hxx | 2 +- src/runtime/PythonNode.cxx | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/runtime/AutoGIL.hxx b/src/runtime/AutoGIL.hxx index 965743f67..d9e94b986 100644 --- a/src/runtime/AutoGIL.hxx +++ b/src/runtime/AutoGIL.hxx @@ -39,7 +39,7 @@ namespace YACS class AutoPyRef { public: - AutoPyRef(PyObject *pyobj=0):_pyobj(pyobj) { } + AutoPyRef(PyObject *pyobj=nullptr):_pyobj(pyobj) { } ~AutoPyRef() { release(); } AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); } AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; } diff --git a/src/runtime/PythonNode.cxx b/src/runtime/PythonNode.cxx index f79e1780c..d9b06c43a 100644 --- a/src/runtime/PythonNode.cxx +++ b/src/runtime/PythonNode.cxx @@ -410,6 +410,7 @@ void PythonNode::executeRemote() } // std::unique_ptr serializationInputCorba(new Engines::pickledArgs); + AutoPyRef serializationInput; { AutoGIL agil; PyObject *args(0),*ob(0); @@ -430,17 +431,15 @@ void PythonNode::executeRemote() PyObject_Print(args,stderr,Py_PRINT_RAW); std::cerr << endl; #endif - PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSer,args,NULL)); + serializationInput.set(PyObject_CallFunctionObjArgs(_pyfuncSer,args,nullptr)); Py_DECREF(args); //The pickled string may contain NULL characters so use PyString_AsStringAndSize char *serializationInputC(0); Py_ssize_t len; if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len)) throw Exception("DistributedPythonNode problem in python pickle"); - serializationInputCorba->length(len); - for(int i=0; i < len ; i++) - (*serializationInputCorba.get())[i]=serializationInputC[i]; - Py_DECREF(serializationInput); + // no copy here. The C byte array of Python is taken as this into CORBA sequence to avoid copy + serializationInputCorba.reset(new Engines::pickledArgs(len,len,reinterpret_cast(serializationInputC),0)); } //get the list of output argument names @@ -465,7 +464,10 @@ void PythonNode::executeRemote() try { //pass outargsname and dict serialized - resultCorba=_pynode->execute(myseq,*(serializationInputCorba.get())); + _pynode->executeFirst(*(serializationInputCorba.get())); + //serializationInput and serializationInputCorba are no more needed for server. Release it. + serializationInputCorba.reset(nullptr); serializationInput.set(nullptr); + resultCorba=_pynode->executeSecond(myseq); } catch( const SALOME::SALOME_Exception& ex ) { @@ -479,7 +481,6 @@ void PythonNode::executeRemote() { _pynode->UnRegister(); } - serializationInputCorba.reset(nullptr); _pynode = Engines::PyScriptNode::_nil(); // bool dummy; -- 2.39.2