Mercurial > hg > orthanc
changeset 2620:1232922c8793 jobs
speeding up shutdown if Lua script is in trailing phase
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 May 2018 14:08:57 +0200 |
parents | 4ecb79c6e81c |
children | 83ac5a05ce84 |
files | Core/JobsEngine/JobsRegistry.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.h OrthancServer/LuaScripting.cpp OrthancServer/ServerJobs/LuaJobManager.cpp OrthancServer/ServerJobs/LuaJobManager.h OrthancServer/main.cpp Resources/Configuration.json |
diffstat | 8 files changed, 50 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp Tue May 22 13:11:47 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Tue May 22 14:08:57 2018 +0200 @@ -446,12 +446,14 @@ } - void JobsRegistry::SetMaxCompletedJobs(size_t i) + void JobsRegistry::SetMaxCompletedJobs(size_t n) { boost::mutex::scoped_lock lock(mutex_); CheckInvariants(); - maxCompletedJobs_ = i; + LOG(INFO) << "The size of the history of the jobs engine is set to: " << n << " job(s)"; + + maxCompletedJobs_ = n; ForgetOldCompletedJobs(); CheckInvariants();
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Tue May 22 13:11:47 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Tue May 22 14:08:57 2018 +0200 @@ -207,7 +207,7 @@ } - void SequenceOfOperationsJob::Lock::SetDicomConnectionTimeout(unsigned int timeout) + void SequenceOfOperationsJob::Lock::SetDicomAssociationTimeout(unsigned int timeout) { that_.connectionManager_.SetTimeout(timeout); }
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Tue May 22 13:11:47 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Tue May 22 14:08:57 2018 +0200 @@ -103,7 +103,7 @@ void SetTrailingOperationTimeout(unsigned int timeout); - void SetDicomConnectionTimeout(unsigned int timeout); + void SetDicomAssociationTimeout(unsigned int timeout); size_t AddOperation(IJobOperation* operation); @@ -139,5 +139,10 @@ virtual void GetPublicContent(Json::Value& value); virtual void GetInternalContent(Json::Value& value); + + void AwakeTrailingSleep() + { + operationAdded_.notify_one(); + } }; }
--- a/OrthancServer/LuaScripting.cpp Tue May 22 13:11:47 2018 +0200 +++ b/OrthancServer/LuaScripting.cpp Tue May 22 14:08:57 2018 +0200 @@ -588,6 +588,8 @@ continue_ = false; } + jobManager_.AwakeTrailingSleep(); + if (eventThread_.joinable()) { LOG(INFO) << "Stopping the Lua engine";
--- a/OrthancServer/ServerJobs/LuaJobManager.cpp Tue May 22 13:11:47 2018 +0200 +++ b/OrthancServer/ServerJobs/LuaJobManager.cpp Tue May 22 14:08:57 2018 +0200 @@ -34,6 +34,9 @@ #include "../PrecompiledHeadersServer.h" #include "LuaJobManager.h" +#include "../OrthancInitialization.h" +#include "../../Core/Logging.h" + #include "../../Core/JobsEngine/Operations/LogJobOperation.h" #include "DeleteResourceOperation.h" #include "ModifyInstanceOperation.h" @@ -65,6 +68,9 @@ priority_(0), trailingTimeout_(5000) { + dicomTimeout_ = Configuration::GetGlobalUnsignedIntegerParameter("DicomAssociationCloseDelay", 5); + LOG(INFO) << "Lua: DICOM associations will be closed after " + << dicomTimeout_ << " seconds of inactivity"; } @@ -89,6 +95,19 @@ } + void LuaJobManager::AwakeTrailingSleep() + { + boost::mutex::scoped_lock lock(mutex_); + + LOG(INFO) << "Awaking trailing sleep"; + + if (currentJob_ != NULL) + { + currentJob_->AwakeTrailingSleep(); + } + } + + LuaJobManager::Lock::Lock(LuaJobManager& that, JobsEngine& engine) : that_(that), @@ -125,6 +144,7 @@ { jobLock_.reset(new SequenceOfOperationsJob::Lock(*that_.currentJob_)); jobLock_->SetTrailingOperationTimeout(that_.trailingTimeout_); + jobLock_->SetDicomAssociationTimeout(that_.dicomTimeout_ * 1000); // Milliseconds expected } }
--- a/OrthancServer/ServerJobs/LuaJobManager.h Tue May 22 13:11:47 2018 +0200 +++ b/OrthancServer/ServerJobs/LuaJobManager.h Tue May 22 14:08:57 2018 +0200 @@ -33,7 +33,6 @@ #pragma once -#include "../../Core/DicomNetworking/TimeoutDicomConnectionManager.h" #include "../../Core/DicomParsing/DicomModification.h" #include "../../Core/JobsEngine/JobsEngine.h" #include "../../Core/JobsEngine/Operations/SequenceOfOperationsJob.h" @@ -52,6 +51,7 @@ size_t maxOperations_; int priority_; unsigned int trailingTimeout_; + unsigned int dicomTimeout_; virtual void SignalDone(const SequenceOfOperationsJob& job); @@ -64,6 +64,8 @@ void SetTrailingOperationTimeout(unsigned int timeout); + void AwakeTrailingSleep(); + class Lock : public boost::noncopyable { private:
--- a/OrthancServer/main.cpp Tue May 22 13:11:47 2018 +0200 +++ b/OrthancServer/main.cpp Tue May 22 14:08:57 2018 +0200 @@ -997,6 +997,9 @@ LOG(INFO) << "Initializing Lua for the event handler"; context.GetLuaScripting().LoadGlobalConfiguration(); + context.GetJobsEngine().GetRegistry().SetMaxCompletedJobs + (Configuration::GetGlobalUnsignedIntegerParameter("JobsHistorySize", 10)); + #if ORTHANC_ENABLE_PLUGINS == 1 if (plugins) {
--- a/Resources/Configuration.json Tue May 22 13:11:47 2018 +0200 +++ b/Resources/Configuration.json Tue May 22 14:08:57 2018 +0200 @@ -315,10 +315,11 @@ // this option might prevent the upgrade to newer versions of Orthanc. "StoreDicom" : true, - // DICOM associations are kept open as long as new DICOM commands - // are issued. This option sets the number of seconds of inactivity - // to wait before automatically closing a DICOM association. If set - // to 0, the connection is closed immediately. + // DICOM associations initiated by Lua scripts are kept open as long + // as new DICOM commands are issued. This option sets the number of + // seconds of inactivity to wait before automatically closing a + // DICOM association used by Lua. If set to 0, the connection is + // closed immediately. "DicomAssociationCloseDelay" : 5, // Maximum number of query/retrieve DICOM requests that are @@ -376,5 +377,10 @@ // "00e1,10c2" : [ "UI", "PET-CT Multi Modality Name", 1, 1, "ELSCINT1" ] // "7053,1003" : [ "ST", "Original Image Filename", 1, 1, "Philips PET Private Group" ] // "2001,5f" : [ "SQ", "StackSequence", 1, 1, "Philips Imaging DD 001" ] - } + }, + + // Maximum number of completed jobs that are kept in memory. A + // processing job is considered as complete once it is tagged as + // "Success" or "Failure". + "JobsHistorySize" : 10 }