[Libreoffice-commits] online.git: common/Common.hpp configure.ac wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Jan 4 04:29:37 UTC 2017


 common/Common.hpp |    3 ---
 configure.ac      |   33 +++++++++++++++++----------------
 wsd/LOOLWSD.cpp   |   22 ++++++++++++----------
 3 files changed, 29 insertions(+), 29 deletions(-)

New commits:
commit 3a79e13214dc524b0c69b7535ed4b3110239d936
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Jan 3 15:19:02 2017 -0500

    wsd: use MAX_CONNECTION from configure instead of hard-coded MAX_SESSIONS
    
    Since we always need to set the thread-pool size
    anyway, we cannot have 'unlimited' connections.
    
    Actually, we never did, so that was misleading
    in configure.ac anyway.
    
    The current defaults are 20 connections and
    10 documents, instead of the previous 1024
    connections.
    The reason for this "low" limit is to
    enable unittesting these limits automatically
    for the default configure.
    
    There is also a lower-limit (needed by unittests
    and internal technical requirements) of 3 connections
    and 2 documents.
    
    Change-Id: I6ccf3a607c50bb2a86bf1c0a16ebb6326ee34c7d
    Reviewed-on: https://gerrit.libreoffice.org/32712
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/common/Common.hpp b/common/Common.hpp
index a0a7568..5f27f84 100644
--- a/common/Common.hpp
+++ b/common/Common.hpp
@@ -11,9 +11,6 @@
 #ifndef INCLUDED_COMMON_HPP
 #define INCLUDED_COMMON_HPP
 
-// The maximum number of client connections we can accept.
-constexpr int MAX_SESSIONS = 1024;
-
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int DEFAULT_MASTER_PORT_NUMBER = 9981;
 
diff --git a/configure.ac b/configure.ac
index f803487..4b05b56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,13 +92,13 @@ AC_ARG_ENABLE([ssl],
             AS_HELP_STRING([--disable-ssl],
                            [Compile without SSL support]))
 
-AC_ARG_WITH([max-documents],
-             AS_HELP_STRING([--max-documents],
-                            [Compile with a hard-coded limit on the number of documents]))
-
 AC_ARG_WITH([max-connections],
             AS_HELP_STRING([--max-connections],
-                           [Compile with a hard-coded limit on the total number of client connections]))
+                           [Set the limit on the total number of client connections. Def: 20, Min: 3.]))
+
+AC_ARG_WITH([max-documents],
+             AS_HELP_STRING([--max-documents],
+                           [Set the limit on the total number of documents. Def: 10, Min: 2.]))
 
 AC_ARG_WITH([compiler-plugins],
             AS_HELP_STRING([--with-compiler-plugins=<path>],
@@ -137,22 +137,23 @@ if test -n "$with_logfile" ; then
 fi
 AC_SUBST(LOOLWSD_LOGFILE)
 
-MAX_DOCUMENTS=10
-AS_IF([test -n "$with_max_documents"],
-      [MAX_DOCUMENTS="$with_max_documents"])
-AC_DEFINE_UNQUOTED([MAX_DOCUMENTS],[$MAX_DOCUMENTS],[Limit the maximum number of open documents])
-AC_SUBST(MAX_DOCUMENTS)
-
 MAX_CONNECTIONS=20
-AS_IF([test -n "$with_max_connections"],
+AS_IF([test -n "$with_max_connections" -a "$with_max_connections" -gt "0"],
       [MAX_CONNECTIONS="$with_max_connections"])
+AS_IF([test "$MAX_CONNECTIONS" -lt "3"],
+      [MAX_CONNECTIONS="3"])
 AC_DEFINE_UNQUOTED([MAX_CONNECTIONS],[$MAX_CONNECTIONS],[Limit the maximum number of open connections])
 AC_SUBST(MAX_CONNECTIONS)
 
-if test $MAX_CONNECTIONS -lt $MAX_DOCUMENTS; then
-    AC_MSG_ERROR([Each document must have at least one connection, therefore, max_connections cannot be less than
-                  max_documents.])
-fi
+MAX_DOCUMENTS=10
+AS_IF([test -n "$with_max_documents" -a "$with_max_documents" -gt "0" -a "$with_max_documents" -lt "$MAX_CONNECTIONS"],
+      [MAX_DOCUMENTS="$with_max_documents"])
+AS_IF([test "$MAX_DOCUMENTS" -gt "$MAX_CONNECTIONS"],
+      [MAX_DOCUMENTS="$MAX_CONNECTIONS"])
+AS_IF([test "$MAX_DOCUMENTS" -lt "2"],
+      [MAX_DOCUMENTS="2"])
+AC_DEFINE_UNQUOTED([MAX_DOCUMENTS],[$MAX_DOCUMENTS],[Limit the maximum number of open documents])
+AC_SUBST(MAX_DOCUMENTS)
 
 # Test for build environment
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 80bcc79..141db3c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1757,13 +1757,12 @@ void LOOLWSD::initialize(Application& self)
     // Otherwise we profile the soft-device at jail creation time.
     setenv("SAL_DISABLE_OPENCL", "true", 1);
 
-    // In Trial Versions we might want to set some limits.
-    LOOLWSD::NumConnections = 0;
-    LOG_INF("Open Documents Limit: " <<
-            (MAX_DOCUMENTS != 0 ? std::to_string(MAX_DOCUMENTS) : std::string("unlimited")));
+    // Log the connection and document limits.
+    static_assert(MAX_DOCUMENTS > 0 && MAX_DOCUMENTS <= MAX_CONNECTIONS, "MAX_DOCUMENTS must be positive and no more than MAX_CONNECTIONS");
+    LOG_INF("Maximum concurrent open Documents limit: " << MAX_DOCUMENTS);
+    LOG_INF("Maximum concurrent client Connections limit: " << MAX_CONNECTIONS);
 
-    LOG_INF("Client Connections Limit: " <<
-            (MAX_CONNECTIONS != 0 ? std::to_string(MAX_CONNECTIONS) : std::string("unlimited")));
+    LOOLWSD::NumConnections = 0;
 
     // Command Tracing.
     if (getConfigValue<bool>(conf, "trace[@enable]", false))
@@ -2080,14 +2079,17 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     // Note: TCPServer internally uses a ThreadPool to
     // dispatch connections (the default if not given).
     // The capacity of the ThreadPool is increased here to
-    // match MAX_SESSIONS. The pool must have sufficient available
+    // match MAX_CONNECTIONS. The pool must have sufficient available
     // threads to dispatch new connections, otherwise will deadlock.
+    static_assert(MAX_CONNECTIONS >= 3, "MAX_CONNECTIONS must be at least 3");
+    const auto maxThreadCount = MAX_CONNECTIONS + 1; // Spare for admin.
+
     auto params1 = new HTTPServerParams();
-    params1->setMaxThreads(MAX_SESSIONS);
+    params1->setMaxThreads(maxThreadCount);
     auto params2 = new HTTPServerParams();
-    params2->setMaxThreads(MAX_SESSIONS);
+    params2->setMaxThreads(maxThreadCount);
 
-    ThreadPool threadPool(NumPreSpawnedChildren * 6, MAX_SESSIONS * 2);
+    ThreadPool threadPool(NumPreSpawnedChildren * 6, maxThreadCount * 2);
 
     // Start internal server for child processes.
     SocketAddress addr2("127.0.0.1", MasterPortNumber);


More information about the Libreoffice-commits mailing list