# HG changeset patch # User Alain Mazy # Date 1675273119 -3600 # Node ID c81f363d3aa35395d4d9cfeecdbfcb7b548ebedc # Parent 05112ff6ba22956b4d9cadf749a08d2def36406e housekeeper thread to call malloc_trim and give back memory to the system diff -r 05112ff6ba22 -r c81f363d3aa3 NEWS --- a/NEWS Fri Jan 27 16:46:46 2023 +0100 +++ b/NEWS Wed Feb 01 18:38:39 2023 +0100 @@ -12,6 +12,10 @@ * New configuration "KeepAliveTimeout" with a default value of 1 second. * ResourceModification jobs (/modify + /anonymize) can now use multiple threads to speed up processing - New configuration "JobsEngineThreadsCount.ResourceModification" to configure the number of threads. +* Introduced a new Housekeeper thread in Orthanc (different from the Housekeeper sample plugin). This thread + regularly try to give back memory that Orthanc no longer uses to the system. This reduces the overall memory + consumption however, only the memory at the end of a memory arena is given back to the system. Fragmented memory + is not given back and therefore, the memory consumption may still stay high. REST API -------- diff -r 05112ff6ba22 -r c81f363d3aa3 OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Fri Jan 27 16:46:46 2023 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Wed Feb 01 18:38:39 2023 +0100 @@ -104,6 +104,19 @@ { } + void ServerContext::HousekeeperThread(ServerContext* that, + unsigned int sleepDelay) + { + while (!that->done_) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); + + // If possible, gives memory back to the system + // (see OrthancServer/Resources/ImplementationNotes/memory_consumption.txt) + + malloc_trim(256*1024); + } + } void ServerContext::ChangeThread(ServerContext* that, unsigned int sleepDelay) @@ -143,8 +156,6 @@ } } } - - malloc_trim(0); } } @@ -419,7 +430,8 @@ listeners_.push_back(ServerListener(luaListener_, "Lua")); changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); - + housekeeperThread_ = boost::thread(HousekeeperThread, this, 100); + dynamic_cast(*dcmtkTranscoder_).SetLossyQuality(lossyQuality); } catch (OrthancException&) diff -r 05112ff6ba22 -r c81f363d3aa3 OrthancServer/Sources/ServerContext.h --- a/OrthancServer/Sources/ServerContext.h Fri Jan 27 16:46:46 2023 +0100 +++ b/OrthancServer/Sources/ServerContext.h Wed Feb 01 18:38:39 2023 +0100 @@ -187,6 +187,9 @@ static void SaveJobsThread(ServerContext* that, unsigned int sleepDelay); + static void HousekeeperThread(ServerContext* that, + unsigned int sleepDelay); + void SaveJobsEngine(); virtual void SignalJobSubmitted(const std::string& jobId) ORTHANC_OVERRIDE; @@ -230,6 +233,7 @@ SharedMessageQueue pendingChanges_; boost::thread changeThread_; boost::thread saveJobsThread_; + boost::thread housekeeperThread_; std::unique_ptr queryRetrieveArchive_; std::string defaultLocalAet_;