Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 5152:c81f363d3aa3 malloc-trim
housekeeper thread to call malloc_trim and give back memory to the system
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 01 Feb 2023 18:38:39 +0100 |
parents | 05112ff6ba22 |
children | f5907aecbaed |
comparison
equal
deleted
inserted
replaced
5149:05112ff6ba22 | 5152:c81f363d3aa3 |
---|---|
102 status_(StoreStatus_Failure), | 102 status_(StoreStatus_Failure), |
103 cstoreStatusCode_(0) | 103 cstoreStatusCode_(0) |
104 { | 104 { |
105 } | 105 } |
106 | 106 |
107 void ServerContext::HousekeeperThread(ServerContext* that, | |
108 unsigned int sleepDelay) | |
109 { | |
110 while (!that->done_) | |
111 { | |
112 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); | |
113 | |
114 // If possible, gives memory back to the system | |
115 // (see OrthancServer/Resources/ImplementationNotes/memory_consumption.txt) | |
116 | |
117 malloc_trim(256*1024); | |
118 } | |
119 } | |
107 | 120 |
108 void ServerContext::ChangeThread(ServerContext* that, | 121 void ServerContext::ChangeThread(ServerContext* that, |
109 unsigned int sleepDelay) | 122 unsigned int sleepDelay) |
110 { | 123 { |
111 while (!that->done_) | 124 while (!that->done_) |
141 << " callback while signaling a change: " << e.What() | 154 << " callback while signaling a change: " << e.What() |
142 << " (code " << e.GetErrorCode() << ")"; | 155 << " (code " << e.GetErrorCode() << ")"; |
143 } | 156 } |
144 } | 157 } |
145 } | 158 } |
146 | |
147 malloc_trim(0); | |
148 } | 159 } |
149 } | 160 } |
150 | 161 |
151 | 162 |
152 void ServerContext::SaveJobsThread(ServerContext* that, | 163 void ServerContext::SaveJobsThread(ServerContext* that, |
417 | 428 |
418 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | 429 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); |
419 | 430 |
420 listeners_.push_back(ServerListener(luaListener_, "Lua")); | 431 listeners_.push_back(ServerListener(luaListener_, "Lua")); |
421 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); | 432 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); |
422 | 433 housekeeperThread_ = boost::thread(HousekeeperThread, this, 100); |
434 | |
423 dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetLossyQuality(lossyQuality); | 435 dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetLossyQuality(lossyQuality); |
424 } | 436 } |
425 catch (OrthancException&) | 437 catch (OrthancException&) |
426 { | 438 { |
427 Stop(); | 439 Stop(); |