Repository: mesos Updated Branches: refs/heads/master a5a28336b -> 5028490f9
Used move assignment in the master's state.json endpoint. This is a simple attempt at improvement for MESOS-2353 in the interim of writing a more comprehensive JSON benchmark. Per the discussion on r/31700, moves here avoid the very expensive copies of the large JSON objects so long as variant has move assignment defined (or generated) and our objects have move generated. It appears that variant has move assignment and our json classes can have move assignment generated, so this should help. Review: https://reviews.apache.org/r/32419 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5028490f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5028490f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5028490f Branch: refs/heads/master Commit: 5028490f99d175927a742c14ede5da07bc40c668 Parents: 99cd79c Author: Benjamin Mahler <[email protected]> Authored: Thu Apr 9 12:13:58 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Thu Apr 9 12:26:36 2015 -0700 ---------------------------------------------------------------------- src/common/http.cpp | 9 ++++--- src/master/http.cpp | 70 ++++++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5028490f/src/common/http.cpp ---------------------------------------------------------------------- diff --git a/src/common/http.cpp b/src/common/http.cpp index d3b7ca3..2ac7fba 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#include <utility> #include <vector> #include <mesos/resources.hpp> @@ -130,7 +131,7 @@ JSON::Object model(const Task& task) foreach (const TaskStatus& status, task.statuses()) { array.values.push_back(model(status)); } - object.values["statuses"] = array; + object.values["statuses"] = std::move(array); } { @@ -142,7 +143,7 @@ JSON::Object model(const Task& task) array.values.push_back(JSON::Protobuf(label)); } } - object.values["labels"] = array; + object.values["labels"] = std::move(array); } if (task.has_discovery()) { @@ -182,7 +183,7 @@ JSON::Object model( foreach (const TaskStatus& status, statuses) { array.values.push_back(model(status)); } - object.values["statuses"] = array; + object.values["statuses"] = std::move(array); } { @@ -194,7 +195,7 @@ JSON::Object model( array.values.push_back(JSON::Protobuf(label)); } } - object.values["labels"] = array; + object.values["labels"] = std::move(array); } if (task.has_discovery()) { http://git-wip-us.apache.org/repos/asf/mesos/blob/5028490f/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index e1a87d6..240687f 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -20,6 +20,7 @@ #include <map> #include <sstream> #include <string> +#include <utility> #include <vector> #include <boost/array.hpp> @@ -150,7 +151,7 @@ JSON::Object model(const Framework& framework) array.values.push_back(model(*task)); } - object.values["tasks"] = array; + object.values["tasks"] = std::move(array); } // Model all of the completed tasks of a framework. @@ -162,7 +163,7 @@ JSON::Object model(const Framework& framework) array.values.push_back(model(*task)); } - object.values["completed_tasks"] = array; + object.values["completed_tasks"] = std::move(array); } // Model all of the offers associated with a framework. @@ -174,7 +175,7 @@ JSON::Object model(const Framework& framework) array.values.push_back(model(*offer)); } - object.values["offers"] = array; + object.values["offers"] = std::move(array); } return object; @@ -216,7 +217,7 @@ JSON::Object model(const Role& role) array.values.push_back(frameworkId.value()); } - object.values["frameworks"] = array; + object.values["frameworks"] = std::move(array); } return object; @@ -390,13 +391,19 @@ const string Master::Http::SLAVES_HELP = HELP( Future<Response> Master::Http::slaves(const Request& request) { LOG(INFO) << "HTTP request for '" << request.path << "'"; - JSON::Array array; - foreachvalue (const Slave* slave, master->slaves.registered) { - array.values.push_back(model(*slave)); + JSON::Object object; + + { + JSON::Array array; + array.values.reserve(master->slaves.registered.size()); // MESOS-2353. + + foreachvalue (const Slave* slave, master->slaves.registered) { + array.values.push_back(model(*slave)); + } + + object.values["slaves"] = std::move(array); } - JSON::Object object; - object.values["slaves"] = array; return OK(object, request.query.get("jsonp")); } @@ -452,14 +459,16 @@ Future<Response> Master::Http::state(const Request& request) object.values["external_log_file"] = master->flags.external_log_file.get(); } - JSON::Object flags; - foreachpair (const string& name, const flags::Flag& flag, master->flags) { - Option<string> value = flag.stringify(master->flags); - if (value.isSome()) { - flags.values[name] = value.get(); + { + JSON::Object flags; + foreachpair (const string& name, const flags::Flag& flag, master->flags) { + Option<string> value = flag.stringify(master->flags); + if (value.isSome()) { + flags.values[name] = value.get(); + } } + object.values["flags"] = std::move(flags); } - object.values["flags"] = flags; // Model all of the slaves. { @@ -470,7 +479,7 @@ Future<Response> Master::Http::state(const Request& request) array.values.push_back(model(*slave)); } - object.values["slaves"] = array; + object.values["slaves"] = std::move(array); } // Model all of the frameworks. @@ -482,7 +491,7 @@ Future<Response> Master::Http::state(const Request& request) array.values.push_back(model(*framework)); } - object.values["frameworks"] = array; + object.values["frameworks"] = std::move(array); } // Model all of the completed frameworks. @@ -495,7 +504,7 @@ Future<Response> Master::Http::state(const Request& request) array.values.push_back(model(*framework)); } - object.values["completed_frameworks"] = array; + object.values["completed_frameworks"] = std::move(array); } // Model all of the orphan tasks. @@ -515,7 +524,7 @@ Future<Response> Master::Http::state(const Request& request) } } - object.values["orphan_tasks"] = array; + object.values["orphan_tasks"] = std::move(array); } // Model all currently unregistered frameworks. @@ -533,7 +542,7 @@ Future<Response> Master::Http::state(const Request& request) } } - object.values["unregistered_frameworks"] = array; + object.values["unregistered_frameworks"] = std::move(array); } return OK(object, request.query.get("jsonp")); @@ -553,7 +562,7 @@ Future<Response> Master::Http::roles(const Request& request) array.values.push_back(model(*role)); } - object.values["roles"] = array; + object.values["roles"] = std::move(array); } return OK(object, request.query.get("jsonp")); @@ -763,15 +772,18 @@ Future<Response> Master::Http::tasks(const Request& request) sort(tasks.begin(), tasks.end(), TaskComparator::descending); } - JSON::Array array; - size_t end = std::min(offset + limit, tasks.size()); - for (size_t i = offset; i < end; i++) { - const Task* task = tasks[i]; - array.values.push_back(model(*task)); - } - JSON::Object object; - object.values["tasks"] = array; + + { + JSON::Array array; + size_t end = std::min(offset + limit, tasks.size()); + for (size_t i = offset; i < end; i++) { + const Task* task = tasks[i]; + array.values.push_back(model(*task)); + } + + object.values["tasks"] = std::move(array); + } return OK(object, request.query.get("jsonp")); }
