You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/05/31 17:17:20 UTC

[1/2] mesos git commit: Added move semantics to `process::http::Pipe::write()`.

Repository: mesos
Updated Branches:
  refs/heads/master 5169f3f7b -> 45ae9fbd9


Added move semantics to `process::http::Pipe::write()`.

Instead of having separate rvalue overload for `write`,
this change takes the sink argument by value and then
does a move. This has the additional small overhead of
performing an extra move.

Review: https://reviews.apache.org/r/47990/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/624f7aa0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/624f7aa0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/624f7aa0

Branch: refs/heads/master
Commit: 624f7aa029e0176919a99462536f8c848ef5e973
Parents: 5169f3f
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Tue May 31 10:03:35 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue May 31 10:13:47 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/http.hpp | 2 +-
 3rdparty/libprocess/src/http.cpp             | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/624f7aa0/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index c180e6e..c17c047 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -370,7 +370,7 @@ public:
     // Returns false if the data could not be written because
     // either end of the pipe was already closed. Note that an
     // empty write has no effect.
-    bool write(const std::string& s);
+    bool write(std::string s);
 
     // Closing the write-end of the pipe will send end-of-file
     // to the reader. Returns false if the write-end of the pipe

http://git-wip-us.apache.org/repos/asf/mesos/blob/624f7aa0/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index b7839b1..8b5c0f4 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -453,7 +453,7 @@ bool Pipe::Reader::close()
 }
 
 
-bool Pipe::Writer::write(const string& s)
+bool Pipe::Writer::write(string s)
 {
   bool written = false;
   Owned<Promise<string>> read;
@@ -464,7 +464,7 @@ bool Pipe::Writer::write(const string& s)
       // Don't bother surfacing empty writes to the readers.
       if (!s.empty()) {
         if (data->reads.empty()) {
-          data->writes.push(s);
+          data->writes.push(std::move(s));
         } else {
           read = data->reads.front();
           data->reads.pop();
@@ -477,7 +477,7 @@ bool Pipe::Writer::write(const string& s)
   // NOTE: We set the promise outside the critical section to avoid
   // triggering callbacks that try to reacquire the lock.
   if (read.get() != NULL) {
-    read->set(s);
+    read->set(std::move(s));
   }
 
   return written;


[2/2] mesos git commit: Avoid copying the Request for each streaming chunk in libprocess.

Posted by bm...@apache.org.
Avoid copying the Request for each streaming chunk in libprocess.

This change passes the `Request` object by wrapping it in
`Owned` instead of copying it on each streaming read from the
`Pipe`. Ideally, we can make the `Request` an `Owned` or `Shared`
object from the point where it is decoded to avoid copying it
around in libprocess.

Review: https://reviews.apache.org/r/47991/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/45ae9fbd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/45ae9fbd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/45ae9fbd

Branch: refs/heads/master
Commit: 45ae9fbd9a34a916a06a91c3f8322314c481522d
Parents: 624f7aa
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Tue May 31 10:03:37 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue May 31 10:14:37 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/45ae9fbd/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 988fb3b..be120fb 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -215,7 +215,7 @@ private:
   bool process(const Future<Response>& future, const Request& request);
 
   // Handles stream based responses.
-  void stream(const Request& request, const Future<string>& chunk);
+  void stream(const Owned<Request>& request, const Future<string>& chunk);
 
   Socket socket; // Wrap the socket to keep it from getting closed.
 
@@ -1282,8 +1282,14 @@ bool HttpProxy::process(const Future<Response>& future, const Request& request)
 
     pipe = reader;
 
+    // Avoid copying the request for each chunk read on the pipe.
+    //
+    // TODO(bmahler): Make request a process::Owned or
+    // process::Shared from the point where it is decoded.
+    Owned<Request> request_(new Request(request));
+
     reader.read()
-      .onAny(defer(self(), &Self::stream, request, lambda::_1));
+      .onAny(defer(self(), &Self::stream, request_, lambda::_1));
 
     return false; // Streaming, don't process next response (yet)!
   } else {
@@ -1295,10 +1301,11 @@ bool HttpProxy::process(const Future<Response>& future, const Request& request)
 
 
 void HttpProxy::stream(
-    const Request& request,
+    const Owned<Request>& request,
     const Future<string>& chunk)
 {
   CHECK_SOME(pipe);
+  CHECK_NOTNULL(request.get());
 
   http::Pipe::Reader reader = pipe.get();
 
@@ -1324,16 +1331,16 @@ void HttpProxy::stream(
     // Always persist the connection when streaming is not finished.
     socket_manager->send(
         new DataEncoder(socket, out.str()),
-        finished ? request.keepAlive : true);
+        finished ? request->keepAlive : true);
   } else if (chunk.isFailed()) {
     VLOG(1) << "Failed to read from stream: " << chunk.failure();
     // TODO(bmahler): Have to close connection if headers were sent!
-    socket_manager->send(InternalServerError(), request, socket);
+    socket_manager->send(InternalServerError(), *request, socket);
     finished = true;
   } else {
     VLOG(1) << "Failed to read from stream: discarded";
     // TODO(bmahler): Have to close connection if headers were sent!
-    socket_manager->send(InternalServerError(), request, socket);
+    socket_manager->send(InternalServerError(), *request, socket);
     finished = true;
   }