changeset 2903:1153b1a128fe

MongooseServer::SetThreadsCount()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 23 Oct 2018 17:32:56 +0200
parents e80b38fb22c6
children 0dd54ee073db
files Core/HttpServer/MongooseServer.cpp Core/HttpServer/MongooseServer.h OrthancServer/main.cpp
diffstat 3 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp	Tue Oct 23 12:05:19 2018 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Tue Oct 23 17:32:56 2018 +0200
@@ -919,6 +919,7 @@
     httpCompression_ = true;
     exceptionFormatter_ = NULL;
     realm_ = ORTHANC_REALM;
+    threadsCount_ = 50;  // Default value in mongoose
 
 #if ORTHANC_ENABLE_SSL == 1
     // Check for the Heartbleed exploit
@@ -957,6 +958,7 @@
     if (!IsRunning())
     {
       std::string port = boost::lexical_cast<std::string>(port_);
+      std::string numThreads = boost::lexical_cast<std::string>(threadsCount_);
 
       if (ssl_)
       {
@@ -975,6 +977,9 @@
         // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no
         "keep_alive_timeout_ms", (keepAlive_ ? "500" : "0"),
 #endif
+
+        // Set the number of threads
+        "num_threads", numThreads.c_str(),
         
         // Set the SSL certificate, if any. This must be the last option.
         ssl_ ? "ssl_certificate" : NULL,
@@ -1125,4 +1130,16 @@
 
     return *handler_;
   }
+
+
+  void MongooseServer::SetThreadsCount(unsigned int threads)
+  {
+    if (threads <= 0)
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    
+    Stop();
+    threadsCount_ = threads;
+  }
 }
--- a/Core/HttpServer/MongooseServer.h	Tue Oct 23 12:05:19 2018 +0200
+++ b/Core/HttpServer/MongooseServer.h	Tue Oct 23 17:32:56 2018 +0200
@@ -96,6 +96,7 @@
     bool httpCompression_;
     IHttpExceptionFormatter* exceptionFormatter_;
     std::string realm_;
+    unsigned int threadsCount_;
   
     bool IsRunning() const;
 
@@ -198,5 +199,12 @@
     {
       realm_ = realm;
     }
+
+    void SetThreadsCount(unsigned int threads);
+
+    unsigned int GetThreadsCount() const
+    {
+      return threadsCount_;
+    }
   };
 }
--- a/OrthancServer/main.cpp	Tue Oct 23 12:05:19 2018 +0200
+++ b/OrthancServer/main.cpp	Tue Oct 23 17:32:56 2018 +0200
@@ -752,6 +752,7 @@
   // HTTP server
   MyIncomingHttpRequestFilter httpFilter(context, plugins);
   MongooseServer httpServer;
+  //httpServer.SetThreadsCount(50);
   httpServer.SetPortNumber(Configuration::GetGlobalUnsignedIntegerParameter("HttpPort", 8042));
   httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false));
   httpServer.SetKeepAliveEnabled(Configuration::GetGlobalBoolParameter("KeepAlive", false));