# HG changeset patch # User Alain Mazy # Date 1720021859 -7200 # Node ID d77292629430ef79d7c44108d2d7e0ec161d42f8 # Parent 71c7d260510de724edf5825e03407d5ed4449f3d# Parent e4d9a872998f3ec93005e6a290baa53a4759b9d7 merge diff -r e4d9a872998f -r d77292629430 NEWS --- a/NEWS Sun Jun 23 10:24:31 2024 +0200 +++ b/NEWS Wed Jul 03 17:50:59 2024 +0200 @@ -13,6 +13,10 @@ * DICOM TLS: "DicomTlsTrustedCertificates" is not required anymore when issuing an outgoing SCU connexion when "DicomTlsRemoteCertificateRequired" is set to false. +* Introduced a new thread to update the statistics at regular interval for the + DB plugins that are implementing the UpdateAndGetStatistics function (currently only + PostgreSQL). This avoids very long update times in case you don't call /statistics + for a long period. Version 1.12.4 (2024-06-05) diff -r e4d9a872998f -r d77292629430 OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Sun Jun 23 10:24:31 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.cpp Wed Jul 03 17:50:59 2024 +0200 @@ -266,6 +266,39 @@ } }; + void ServerIndex::UpdateStatisticsThread(ServerIndex* that, + unsigned int threadSleepGranularityMilliseconds) + { + Logging::SetCurrentThreadName("DB-STATS"); + + static const unsigned int SLEEP_SECONDS = 60; + + if (threadSleepGranularityMilliseconds > 1000) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + LOG(INFO) << "Starting the update statistics thread (sleep = " << SLEEP_SECONDS << " seconds)"; + + unsigned int count = 0; + unsigned int countThreshold = (1000 * SLEEP_SECONDS) / threadSleepGranularityMilliseconds; + + while (!that->done_) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); + count++; + + if (count >= countThreshold) + { + uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances; + that->GetGlobalStatistics(diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances); + + count = 0; + } + } + + LOG(INFO) << "Stopping the update statistics thread"; + } void ServerIndex::FlushThread(ServerIndex* that, unsigned int threadSleepGranularityMilliseconds) @@ -326,11 +359,20 @@ // execution of Orthanc StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); + // For some DB engines (like SQLite), make sure we flush the DB to disk at regular interval if (GetDatabaseCapabilities().HasFlushToDisk()) { flushThread_ = boost::thread(FlushThread, this, threadSleepGranularityMilliseconds); } + // For some DB plugins that implements the UpdateAndGetStatistics function, updating + // the statistics can take quite some time if you have not done it for a long time + // -> make sure they are updated at regular interval + if (GetDatabaseCapabilities().HasUpdateAndGetStatistics()) + { + updateStatisticsThread_ = boost::thread(UpdateStatisticsThread, this, threadSleepGranularityMilliseconds); + } + unstableResourcesMonitorThread_ = boost::thread (UnstableResourcesMonitorThread, this, threadSleepGranularityMilliseconds); } @@ -357,6 +399,11 @@ flushThread_.join(); } + if (updateStatisticsThread_.joinable()) + { + updateStatisticsThread_.join(); + } + if (unstableResourcesMonitorThread_.joinable()) { unstableResourcesMonitorThread_.join(); diff -r e4d9a872998f -r d77292629430 OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Sun Jun 23 10:24:31 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.h Wed Jul 03 17:50:59 2024 +0200 @@ -42,6 +42,7 @@ bool done_; boost::mutex monitoringMutex_; boost::thread flushThread_; + boost::thread updateStatisticsThread_; boost::thread unstableResourcesMonitorThread_; LeastRecentlyUsedIndex, UnstableResourcePayload> unstableResources_; @@ -53,6 +54,9 @@ static void FlushThread(ServerIndex* that, unsigned int threadSleep); + static void UpdateStatisticsThread(ServerIndex* that, + unsigned int threadSleep); + static void UnstableResourcesMonitorThread(ServerIndex* that, unsigned int threadSleep);