comparison OrthancServer/Sources/ServerContext.cpp @ 5159:f5907aecbaed

conditional usage of malloc_trim
author Alain Mazy <am@osimis.io>
date Thu, 02 Feb 2023 11:28:35 +0100
parents c81f363d3aa3
children 9f16979b6124
comparison
equal deleted inserted replaced
5158:02cfd23a556a 5159:f5907aecbaed
105 } 105 }
106 106
107 void ServerContext::HousekeeperThread(ServerContext* that, 107 void ServerContext::HousekeeperThread(ServerContext* that,
108 unsigned int sleepDelay) 108 unsigned int sleepDelay)
109 { 109 {
110 // note, right now, this thread is started only if malloc_trim is defined
110 while (!that->done_) 111 while (!that->done_)
111 { 112 {
112 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); 113 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay));
113 114
114 // If possible, gives memory back to the system 115 // If possible, gives memory back to the system
115 // (see OrthancServer/Resources/ImplementationNotes/memory_consumption.txt) 116 // (see OrthancServer/Resources/ImplementationNotes/memory_consumption.txt)
116 117 #if HAVE_MALLOC_TRIM == 1
117 malloc_trim(256*1024); 118 malloc_trim(128*1024);
119 #endif
118 } 120 }
119 } 121 }
120 122
121 void ServerContext::ChangeThread(ServerContext* that, 123 void ServerContext::ChangeThread(ServerContext* that,
122 unsigned int sleepDelay) 124 unsigned int sleepDelay)
428 430
429 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); 431 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
430 432
431 listeners_.push_back(ServerListener(luaListener_, "Lua")); 433 listeners_.push_back(ServerListener(luaListener_, "Lua"));
432 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); 434 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100));
435 #if HAVE_MALLOC_TRIM == 1
433 housekeeperThread_ = boost::thread(HousekeeperThread, this, 100); 436 housekeeperThread_ = boost::thread(HousekeeperThread, this, 100);
434 437 #else
438 LOG(INFO) << "Your platform does not support malloc_trim(), not starting the housekeeper thread";
439 #endif
435 dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetLossyQuality(lossyQuality); 440 dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetLossyQuality(lossyQuality);
436 } 441 }
437 catch (OrthancException&) 442 catch (OrthancException&)
438 { 443 {
439 Stop(); 444 Stop();