Hi,
I made some quick investigations. Here are my current notes for future follow up.
Started Orthanc with a debugger with this minimal config to reduce the number of threads at maximum:
{
"Name": "Orthanc debug",
"HttpPort": 8043,
"DicomServerEnabled" : false,
"StorageDirectory": "OrthancStorageDebugBis",
"RemoteAccessAllowed": true,
"AuthenticationEnabled": false,
"JobsEngineThreadsCount" : {
"ResourceModification": 4 // for /anonymize, /modify
},
"HttpThreadsCount": 1,
"OverwriteInstances": true
}
After a fresh Orthanc start, it is at 0.3% CPU while idle with some small peak to 5% at regular interval.
I then upload a series with 1.2k instance, restart → 0.3% CPU
Then, I anonymize the study. After it is done, the CPU is around 0.7%
I break the execution and went through all the threads before and after the anonymization. Here’s what they are doing:
HttpServer: waitForExit -> ServerBarrier sleep(100us)
DB Flusing thread -> sleep(500ms)
Unstable resource monitor thread -> sleep(500ms)
ChangeThread: waiting on pthread_cond_timedwait(100ms)
MemoryTrimmingThread: sleep(100ms)
JobsEngine::RetryHandler: sleep(200ms)
JobsEngine::Worker: waiting on pthread_cond_timedwait(200ms)
JobsEngine::Worker: waiting on pthread_cond_timedwait(200ms)
ServerContext::SaveJobsThread: sleep(100ms)
CivetWeb-worker consume_socket: waiting on mutex
CivetWeb-worker accept loop: waiting poll (200ms)
OrthancWebDav::UploadWorker waiting on pthread_cond_timedwait(100ms)
LuaScripting::EventThread waiting on pthread_cond_timedwait(100ms)
Most of these threads are doing nothing once they wake up since there’s nothing to do.
However, I tried to disable the MemoryTrimmingThread and it seems the CPU is down to 0.3% even after the anonymization.
My assumption right now is that the malloc_trim
takes more time after anonymization because the memory is ‘fragmented’ or more memory have been consumed. The next calls still takes the same time because the memory can not be trimmed…
I’ll dig into it a bit deeper. Maybe we should just execute it every 10 seconds instead of every 100ms …