comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 3926:2910b0d30fe0 transcoding

Allow concurrent calls to the custom image decoders provided by the plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 May 2020 07:37:44 +0200
parents 09f091b6b569
children 4cdc875510d1
comparison
equal deleted inserted replaced
3925:dd112d2b83f0 3926:2910b0d30fe0
41 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h" 41 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h"
42 #include "../../Core/HttpServer/HttpContentNegociation.h" 42 #include "../../Core/HttpServer/HttpContentNegociation.h"
43 #include "../../Core/Images/Image.h" 43 #include "../../Core/Images/Image.h"
44 #include "../../Core/Images/ImageProcessing.h" 44 #include "../../Core/Images/ImageProcessing.h"
45 #include "../../Core/Logging.h" 45 #include "../../Core/Logging.h"
46 #include "../../Core/MultiThreading/Semaphore.h"
46 #include "../DefaultDicomImageDecoder.h" 47 #include "../DefaultDicomImageDecoder.h"
47 #include "../OrthancConfiguration.h" 48 #include "../OrthancConfiguration.h"
48 #include "../Search/DatabaseLookup.h" 49 #include "../Search/DatabaseLookup.h"
49 #include "../ServerContext.h" 50 #include "../ServerContext.h"
50 #include "../ServerToolbox.h" 51 #include "../ServerToolbox.h"
52 53
53 #include "../../Plugins/Engine/OrthancPlugins.h" 54 #include "../../Plugins/Engine/OrthancPlugins.h"
54 55
55 // This "include" is mandatory for Release builds using Linux Standard Base 56 // This "include" is mandatory for Release builds using Linux Standard Base
56 #include <boost/math/special_functions/round.hpp> 57 #include <boost/math/special_functions/round.hpp>
58
59
60 /**
61 * This semaphore is used to limit the number of concurrent HTTP
62 * requests on CPU-intensive routes of the REST API, in order to
63 * prevent exhaustion of resources (new in Orthanc 1.7.0).
64 **/
65 static Orthanc::Semaphore throttlingSemaphore_(4); // TODO => PARAMETER?
57 66
58 67
59 namespace Orthanc 68 namespace Orthanc
60 { 69 {
61 static void AnswerDicomAsJson(RestApiCall& call, 70 static void AnswerDicomAsJson(RestApiCall& call,
936 945
937 946
938 template <enum ImageExtractionMode mode> 947 template <enum ImageExtractionMode mode>
939 static void GetImage(RestApiGetCall& call) 948 static void GetImage(RestApiGetCall& call)
940 { 949 {
950 Semaphore::Locker locker(throttlingSemaphore_);
951
941 GetImageHandler handler(mode); 952 GetImageHandler handler(mode);
942 IDecodedFrameHandler::Apply(call, handler); 953 IDecodedFrameHandler::Apply(call, handler);
943 } 954 }
944 955
945 956
946 static void GetRenderedFrame(RestApiGetCall& call) 957 static void GetRenderedFrame(RestApiGetCall& call)
947 { 958 {
959 Semaphore::Locker locker(throttlingSemaphore_);
960
948 RenderedFrameHandler handler; 961 RenderedFrameHandler handler;
949 IDecodedFrameHandler::Apply(call, handler); 962 IDecodedFrameHandler::Apply(call, handler);
950 } 963 }
951 964
952 965
953 static void GetMatlabImage(RestApiGetCall& call) 966 static void GetMatlabImage(RestApiGetCall& call)
954 { 967 {
968 Semaphore::Locker locker(throttlingSemaphore_);
969
955 ServerContext& context = OrthancRestApi::GetContext(call); 970 ServerContext& context = OrthancRestApi::GetContext(call);
956 971
957 std::string frameId = call.GetUriComponent("frame", "0"); 972 std::string frameId = call.GetUriComponent("frame", "0");
958 973
959 unsigned int frame; 974 unsigned int frame;