changeset 7001:e9cebd8402c5 streaming

merge
author Alain Mazy <am@orthanc.team>
date Mon, 06 Jul 2026 15:07:11 +0200
parents 053ce2231c18 (diff) 8c303fedfe87 (current diff)
children a998c3b34bf4
files OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/main.cpp
diffstat 9 files changed, 57 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -361,10 +361,8 @@
                                        uint64_t& tasksCurrentMemory,
                                        unsigned int& tasksReservations) const
   {
-    { // TODO-Streaming - Question AM: why this copy ?
-      boost::shared_ptr<Internals::DataSourceMemoryBudget> budgetCopy(budget_);
-      budgetCopy->GetStatistics(tasksMaximumMemory, tasksCurrentMemory, tasksReservations);
-    }
+    boost::shared_ptr<Internals::DataSourceMemoryBudget> budgetCopy(budget_);  // increment shared_ptr ref count to make sure the budget is not deleted while we use it.
+    budgetCopy->GetStatistics(tasksMaximumMemory, tasksCurrentMemory, tasksReservations);
   }
 
 
--- a/OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -317,7 +317,7 @@
                                                                                             bool hasLossyQuality,
                                                                                             unsigned int lossyQuality) const
   {
-    // TODO-Streaming : No optimization seems possible, we need to go through the transcoder anyway
+    // No optimization seems possible, we need to go through the transcoder anyway
     return CreateForTranscodedParsedDicomFile(targetSyntax, mode, hasLossyQuality, lossyQuality);
   }
 
--- a/OrthancFramework/Sources/Logging.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancFramework/Sources/Logging.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -46,6 +46,8 @@
 {
   namespace Logging
   {
+    static bool logCallerThreadNameInContext = false; // add a "from THREADNAME" in the context everytime the context is copied from a thread to the other to help track the runnable/callable journey
+
     static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff;
     
     static uint32_t infoCategoriesMask_ = 0;
@@ -1114,18 +1116,17 @@
     struct ThreadContextMemento::PImpl : public boost::noncopyable
     {
       std::list<std::string>  context_;
+      std::string             threadName_;
     };
 
 
     ThreadContextMemento::ScopedSetter::ScopedSetter(const ThreadContextMemento& memento) :
       count_(memento.pimpl_->context_.size())
     {
-      if (false) // additional debug information: add the caller thread name
+      if (logCallerThreadNameInContext && enableThreadNames_ && !memento.pimpl_->threadName_.empty())
       {
-        if (enableThreadNames_)
-        {
-          PushCurrentThreadContext("from " + GetCurrentThreadName());
-        }
+        count_++;
+        PushCurrentThreadContext("from " + memento.pimpl_->threadName_);
       }
 
       for (std::list<std::string>::const_iterator it = memento.pimpl_->context_.begin(); it != memento.pimpl_->context_.end(); ++it)
@@ -1149,6 +1150,10 @@
     {
       ThreadsInformations::CurrentThreadReader reader(threadsInformations_);
       reader.CopyContext(pimpl_->context_);
+      if (reader.HasThreadName())
+      {
+        pimpl_->threadName_ = reader.GetThreadName();
+      }
     }
 
 
--- a/OrthancServer/Resources/Configuration.json	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Resources/Configuration.json	Mon Jul 06 15:07:11 2026 +0200
@@ -1157,6 +1157,11 @@
 
 
 
+  // -> TODO-Streaming: move this into AdvancedConfiguration.json
+
+  // add a page in the book: performance: fine tuning: limiting memory + increasing the number of threads blah blah blah
+
+
   // Number of threads that are used to parse DICOM files (when you need
   // to access the value of DICOM tags that are not store in DB).
   // (new in Orthanc 1.12.11+)
@@ -1201,26 +1206,33 @@
   "TranscoderCacheSize" : 128,
 
   // Number of threads that are used to provide DICOM files sequentially
-  // (currently used in Archive jobs, C-Store and C-Get).  This limits
-  // the number of concurrent such jobs.
-  // TODO-Streaming: clarify the meaning with Seb.  If the above definition
-  // is correct; shouldn't we simply set it to the same value as "ConcurrentJobs" if not defined ?
-  // (new in Orthanc 1.12.11+)
+  // (currently used in Archive jobs, C-Store and C-Get).
+  // Each time such a job needs to get a DICOM file content, it requests it from
+  // a sequential DICOM reader that will itself use a s torage loader thread.
+  // Therefore, by default, the value of this configuration is identical to
+  // "StorageLoaderThreads".
+  // (new in Orthanc 1.13.0)
   // You should monitor the "orthanc_seq_reader_available_threads" 
   // metrics to determine the optimal value for your setup and usage.
-  "SequentialDicomReaderThreads": 2,
+  // "SequentialDicomReaderThreads": 4,
 
-  // TODO-Streaming: clarify the meaning with Seb.
   // Number of files each sequential DICOM reader is allowed to buffer
   // in advance before it is consumed by the related job.
+  // This is kind of equivalent to the older "LoaderThreads" configuration
+  // but, furthermore, you must make sure that there are enough "StorageLoaderThreads"
+  // and "SequentialDicomReaderThreads" for each job -> 
+  // "StorageLoaderThreads" should be larger than "ConcurrentJobs" * "SequentialDicomReaderWindowCapacity"
+  // Together with "SequentialDicomReaderWindowCapacity", this also defines the amount of memory that is
+  // used by each job that required a SequentialDicomReader.
   "SequentialDicomReaderWindowSize": 4,
   
-  // TODO-Streaming: clarify the meaning with Seb.
   // Amount of RAM (in MB) that are allocated to each sequential DICOM
-  // Reader.
+  // Reader.  The sequential DICOM reader stops pauses buffering as soon
+  // as one of the "SequentialDicomReaderWindowSize" or 
+  // "SequentialDicomReaderWindowCapacity" limit is reached.
   // Note that this limit can be overpassed when a single file 
   // exceeds this size.
-  // (new in Orthanc 1.12.11+).
+  // (new in Orthanc 1.13.0).
   "SequentialDicomReaderWindowCapacity": 64
 
 }
--- a/OrthancServer/Sources/OrthancConfiguration.h	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.h	Mon Jul 06 15:07:11 2026 +0200
@@ -57,10 +57,9 @@
 #define ORTHANC_CONFIG_HTTP_THREADS_COUNT "HttpThreadsCount"
 #define ORTHANC_CONFIG_DICOM_THREADS_COUNT "DicomThreadsCount"
 
-// TODO-Streaming: finalize the names with Seb
 #define ORTHANC_CONFIG_STORAGE_LOADER_THREADS "StorageLoaderThreads"
 #define ORTHANC_CONFIG_STORAGE_MEMORY_CAPACITY "StorageMemoryCapacity"
-#define ORTHANC_CONFIG_MAXIMUM_STORAGE_CACHE_SIZE "MaximumStorageCacheSize"  // TODO-Streaming: we keep the old naming for historical reasons ?
+#define ORTHANC_CONFIG_MAXIMUM_STORAGE_CACHE_SIZE "MaximumStorageCacheSize"
 #define ORTHANC_CONFIG_DICOM_PARSER_SOURCE_THREADS "DicomParserThreads"
 #define ORTHANC_CONFIG_DICOM_PARSER_MEMORY_CAPACITY "DicomParserMemoryCapacity"
 #define ORTHANC_CONFIG_DICOM_PARSER_CACHE_SIZE "DicomParserCacheSize"
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -354,7 +354,7 @@
       source.AcquireParsed(dicom);  // This invalidates the "dicom" object, cf. (*)
 
       /**
-       * TODO-Streaming : It doesn't seem possible to uniformly trancode upfront
+       * It doesn't seem possible to uniformly trancode upfront
        * using "DicomSequentialReader::CreateForTranscoded()", as the
        * selected transfer syntax is not constant, but varies upon
        * each individual instance given the presentation context.
--- a/OrthancServer/Sources/ServerContext.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -554,8 +554,6 @@
   {
     try
     {
-      bool checkMD5 = true;
-
       {
         OrthancConfiguration::ReaderLock lock;
 
@@ -681,8 +679,6 @@
         SetAcceptedSopClasses(acceptedSopClasses, rejectedSopClasses);
 
         defaultDicomRetrieveMethod_ = StringToRetrieveMethod(lock.GetConfiguration().GetDicomDefaultRetrieveMethod());
-
-        checkMD5 = lock.GetConfiguration().GetBooleanParameter("CheckMD5", true);  // TODO-Streaming - Parameter
       }
 
       jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
@@ -735,8 +731,15 @@
         dicomParserThreads = lock.GetConfiguration().GetUnsignedIntegerParameter(ORTHANC_CONFIG_DICOM_PARSER_SOURCE_THREADS, 2);
         LOG(WARNING) << "'" << ORTHANC_CONFIG_DICOM_PARSER_SOURCE_THREADS << "' is set to " << dicomParserThreads;
 
-        sequentialReaderThreads = lock.GetConfiguration().GetUnsignedIntegerParameter(ORTHANC_CONFIG_SEQUENTIAL_DICOM_READER_THREADS, 2);
-        LOG(WARNING) << "'" << ORTHANC_CONFIG_SEQUENTIAL_DICOM_READER_THREADS << "' is set to " << sequentialReaderThreads;
+        if (!lock.GetConfiguration().LookupUnsignedIntegerParameter(sequentialReaderThreads, ORTHANC_CONFIG_SEQUENTIAL_DICOM_READER_THREADS))
+        {
+          LOG(WARNING) << "'" << ORTHANC_CONFIG_SEQUENTIAL_DICOM_READER_THREADS << "' is not defined in your configuration, setting it to the same value as '" << ORTHANC_CONFIG_STORAGE_LOADER_THREADS << "': " << storageLoaderThreads;
+          sequentialReaderThreads = storageLoaderThreads;
+        }
+        else
+        {
+          LOG(WARNING) << "'" << ORTHANC_CONFIG_SEQUENTIAL_DICOM_READER_THREADS << "' is set to " << sequentialReaderThreads;
+        }
 
         // ----> IF you update values here, you must also update them in Configuration.json <-----
         GetMemoryConfiguration(storageMemoryCapacityMb, lock, ORTHANC_CONFIG_STORAGE_MEMORY_CAPACITY, 512);
@@ -759,7 +762,7 @@
         pool->SetMetricsConfiguration(*metricsRegistry_, METRICS_STORAGE_THREAD_POOL_AVAILABLE_THREADS);
         pool->Start();
 
-        std::unique_ptr<StorageAreaDataSource> source(new StorageAreaDataSource(area_, checkMD5));
+        std::unique_ptr<StorageAreaDataSource> source(new StorageAreaDataSource(area_, IsStoreMD5ForAttachments()));
         source->SetMetricsRegistry(metricsRegistry_,
                                    METRICS_STORAGE_AREA_READ_BYTES, METRICS_STORAGE_AREA_READ_DURATION);
 
@@ -777,6 +780,15 @@
 
         storageAreaReader_->SetCapacity(storageMemoryCapacityMb * MEGABYTE);
         storageAreaReader_->CreateCache(storageCacheSizeMb * MEGABYTE);
+        
+        if (storageCacheSizeMb == 0)
+        {
+          LOG(WARNING) << "Storage cache is disabled";
+        }
+        else
+        {
+          LOG(WARNING) << "Storage cache size is " << storageCacheSizeMb << " MB";
+        }
       }
 
       {
--- a/OrthancServer/Sources/ServerContext.h	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Mon Jul 06 15:07:11 2026 +0200
@@ -322,11 +322,6 @@
       return index_;
     }
 
-    void SetMaximumStorageCacheSize(size_t size)
-    {
-      // TODO-Streaming
-    }
-
     void SetPatientLevelEnabled(bool enabled);
 
     bool IsPatientLevelEnabled() const
@@ -369,7 +364,7 @@
 
     StoreResult TranscodeAndStore(std::string& resultPublicId,
                                   DicomInstanceToStore* dicom,
-                                  bool isReconstruct = false);  // TODO-Streaming: To check
+                                  bool isReconstruct = false);
 
     void AnswerAttachment(RestApiOutput& output,
                           const FileInfo& fileInfo,
--- a/OrthancServer/Sources/main.cpp	Sat Jul 04 11:00:16 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Mon Jul 06 15:07:11 2026 +0200
@@ -1789,26 +1789,6 @@
         context.GetIndex().SetMaximumStorageMode(MaxStorageMode_Recycle);
       }
     }
-
-    // note: this config is valid in ReadOnlyMode
-    try
-    {
-      uint64_t size = lock.GetConfiguration().GetMaximumStorageCacheSize();
-      if (size == 0)
-      {
-        LOG(WARNING) << "Storage cache is disabled";
-      }
-      else
-      {
-        LOG(WARNING) << "Storage cache size is " << size << " MB";
-      }
-      
-      context.SetMaximumStorageCacheSize(size * 1024 * 1024);
-    }
-    catch (...)
-    {
-      context.SetMaximumStorageCacheSize(128);
-    }
   }
 
   {