[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/ClientSession.hpp loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/test loolwsd/TileCache.cpp

2016-09-19 Thread Ashod Nakashian
 loolwsd/ClientSession.cpp  |2 --
 loolwsd/ClientSession.hpp  |9 -
 loolwsd/DocumentBroker.cpp |6 --
 loolwsd/LOOLWSD.cpp|   28 ++--
 loolwsd/TileCache.cpp  |   27 ---
 loolwsd/test/Makefile.am   |1 +
 6 files changed, 31 insertions(+), 42 deletions(-)

New commits:
commit e7272019dc28da7b66a7db145bda9a9c3db1380c
Author: Ashod Nakashian 
Date:   Wed Aug 31 23:34:41 2016 -0400

loolwsd: remove tile queue and simplify tile response

Tile queue was used to process canceltiles commands.
Since those are handled by TileCache, there is no need
for queues and the threads that pump them.

But because these queues were also used to buffer between
WSD internals and clients, such that a slow client wouldn't
block WSD while sending back tiles, it is necessary
to reword that logic.
In subsequent commits that will change as well.

With this change not only do we save a thread per client,
but we also reduce latency of tile, and improve typing
responsiveness, by almost 3x or more! Latencies are
down to ~15ms from almost 50ms.

Reviewed-on: https://gerrit.libreoffice.org/28575
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 
(cherry picked from commit 59eaacd2f87f46c4c4d2963ef54f4d20d346b2d0)

Change-Id: I77813267a95a724491165792ec020ae00953c05e
Reviewed-on: https://gerrit.libreoffice.org/29066
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 533844f..b493c58 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -37,11 +37,9 @@ using Poco::StringTokenizer;
 ClientSession::ClientSession(const std::string& id,
  std::shared_ptr ws,
  std::shared_ptr docBroker,
- std::shared_ptr queue,
  bool readOnly) :
 LOOLSession(id, Kind::ToClient, ws),
 _docBroker(std::move(docBroker)),
-_queue(std::move(queue)),
 _isReadOnly(readOnly),
 _loadFailed(false),
 _loadPart(-1)
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index e6f3098..a285efe 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -23,7 +23,6 @@ public:
 ClientSession(const std::string& id,
   std::shared_ptr ws,
   std::shared_ptr docBroker,
-  std::shared_ptr queue,
   bool isReadOnly = false);
 
 virtual ~ClientSession();
@@ -58,11 +57,6 @@ public:
 _loadFailed = true;
 }
 
-void sendToInputQueue(const std::string& message)
-{
-_queue->put(message);
-}
-
 std::shared_ptr getDocumentBroker() const { return 
_docBroker; }
 
 private:
@@ -83,9 +77,6 @@ private:
 
 std::shared_ptr _docBroker;
 
-/// The incoming message queue.
-std::shared_ptr _queue;
-
 // Whether the session is opened as readonly
 bool _isReadOnly;
 
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 1e58e76..78cc9e7 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -364,8 +364,10 @@ bool DocumentBroker::sendUnoSave(const bool 
dontSaveIfUnmodified)
 // arguments end
 oss << "}";
 
-Log::debug(".uno:Save arguments: " + oss.str());
-sessionIt.second->sendToInputQueue("uno .uno:Save " + oss.str());
+const auto saveArgs = oss.str();
+Log::trace(".uno:Save arguments: " + saveArgs);
+const auto command = "uno .uno:Save " + saveArgs;
+sessionIt.second->handleInput(command.data(), command.size());
 return true;
 }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9f1d6d7..266ac7c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -399,7 +399,7 @@ private:
 
 // Load the document.
 std::shared_ptr ws;
-auto session = std::make_shared(id, ws, 
docBroker, nullptr);
+auto session = std::make_shared(id, ws, 
docBroker);
 
 // Request the child to connect to us and add this session.
 auto sessionsCount = docBroker->addSession(session);
@@ -686,10 +686,7 @@ private:
 std::shared_ptr session;
 try
 {
-// For ToClient sessions, we store incoming messages in a queue 
and have a separate
-// thread to pump them. This is to empty the queue when we get a 
"canceltiles" message.
-auto queue = std::make_shared();
-session = std::make_shared(id, ws, docBroker, 
queue, isReadOnly);
+session = std::make_shared(id, ws, docBroker, 
isReadOnly);
 if (!fileinfo._userName.empty())
 {
 Log::debug(uriPublic.toString() + " requested with username [" 
+ file

[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/ClientSession.hpp loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/test loolwsd/TileCache.cpp

2016-08-31 Thread Ashod Nakashian
 loolwsd/ClientSession.cpp  |2 --
 loolwsd/ClientSession.hpp  |9 -
 loolwsd/DocumentBroker.cpp |7 ---
 loolwsd/LOOLWSD.cpp|   28 ++--
 loolwsd/TileCache.cpp  |   27 ---
 loolwsd/test/Makefile.am   |1 +
 6 files changed, 31 insertions(+), 43 deletions(-)

New commits:
commit 59eaacd2f87f46c4c4d2963ef54f4d20d346b2d0
Author: Ashod Nakashian 
Date:   Wed Aug 31 23:34:41 2016 -0400

loolwsd: remove tile queue and simplify tile response

Tile queue was used to process canceltiles commands.
Since those are handled by TileCache, there is no need
for queues and the threads that pump them.

But because these queues were also used to buffer between
WSD internals and clients, such that a slow client wouldn't
block WSD while sending back tiles, it is necessary
to reword that logic.
In subsequent commits that will change as well.

With this change not only do we save a thread per client,
but we also reduce latency of tile, and improve typing
responsiveness, by almost 3x or more! Latencies are
down to ~15ms from almost 50ms.

Change-Id: I9bb5856efed28caea9d4e6f94f77b093779e5241
Reviewed-on: https://gerrit.libreoffice.org/28575
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 40d..c61c574 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -37,11 +37,9 @@ using Poco::StringTokenizer;
 ClientSession::ClientSession(const std::string& id,
  std::shared_ptr ws,
  std::shared_ptr docBroker,
- std::shared_ptr queue,
  bool readOnly) :
 LOOLSession(id, Kind::ToClient, ws),
 _docBroker(std::move(docBroker)),
-_queue(std::move(queue)),
 _haveEditLock(std::getenv("LOK_VIEW_CALLBACK")),
 _isReadOnly(readOnly),
 _loadFailed(false),
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index dc531c8..3a9b1a1 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -23,7 +23,6 @@ public:
 ClientSession(const std::string& id,
   std::shared_ptr ws,
   std::shared_ptr docBroker,
-  std::shared_ptr queue,
   bool isReadOnly = false);
 
 virtual ~ClientSession();
@@ -60,11 +59,6 @@ public:
 _loadFailed = true;
 }
 
-void sendToInputQueue(const std::string& message)
-{
-_queue->put(message);
-}
-
 std::shared_ptr getDocumentBroker() const { return 
_docBroker; }
 
 private:
@@ -85,9 +79,6 @@ private:
 
 std::shared_ptr _docBroker;
 
-/// The incoming message queue.
-std::shared_ptr _queue;
-
 // If this document holds the edit lock.
 // An edit lock will only allow the current session to make edits,
 // while other session opening the same document can only see
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 1e82696..afa8460 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -317,7 +317,6 @@ bool DocumentBroker::sendUnoSave(const bool 
dontSaveIfUnmodified)
 _lastFileModifiedTime.fromEpochTime(0);
 
 // We do not want save to terminate editing mode if we are in edit 
mode now
-
 std::ostringstream oss;
 // arguments init
 oss << "{";
@@ -343,8 +342,10 @@ bool DocumentBroker::sendUnoSave(const bool 
dontSaveIfUnmodified)
 // arguments end
 oss << "}";
 
-Log::debug(".uno:Save arguments: " + oss.str());
-sessionIt.second->sendToInputQueue("uno .uno:Save " + oss.str());
+const auto saveArgs = oss.str();
+Log::trace(".uno:Save arguments: " + saveArgs);
+const auto command = "uno .uno:Save " + saveArgs;
+sessionIt.second->handleInput(command.data(), command.size());
 return true;
 }
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4d1628b..5efbd39 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -399,7 +399,7 @@ private:
 
 // Load the document.
 std::shared_ptr ws;
-auto session = std::make_shared(id, ws, 
docBroker, nullptr);
+auto session = std::make_shared(id, ws, 
docBroker);
 
 // Request the child to connect to us and add this session.
 auto sessionsCount = docBroker->addSession(session);
@@ -662,10 +662,7 @@ private:
 std::shared_ptr session;
 try
 {
-// For ToClient sessions, we store incoming messages in a queue 
and have a separate
-// thread to pump them. This is to empty the queue when we get a 
"canceltiles" message.
-auto queue = s