Mercurial > hg > orthanc
changeset 5662:d77292629430
merge
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Wed, 03 Jul 2024 17:50:59 +0200 |
parents | 71c7d260510d (diff) e4d9a872998f (current diff) |
children | 3765085693e5 301212a3fa08 f690568f0325 |
files | |
diffstat | 3 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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();
--- 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<std::pair<ResourceType, int64_t>, 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);