Repository: mesos Updated Branches: refs/heads/master acaee563a -> 0c7104d4d
Reserved memory for JSON arrays in the master's http endpoints. Review: https://reviews.apache.org/r/31700 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0c7104d4 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0c7104d4 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0c7104d4 Branch: refs/heads/master Commit: 0c7104d4d83d28371db7d19dcbb1bf077eeede05 Parents: acaee56 Author: Alexander Rukletsov <[email protected]> Authored: Thu Mar 12 12:22:36 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Thu Mar 12 12:25:36 2015 -0700 ---------------------------------------------------------------------- src/common/http.cpp | 52 +++++++++++++++++++++++++++++++----------------- src/master/http.cpp | 14 +++++++++++-- 2 files changed, 46 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0c7104d4/src/common/http.cpp ---------------------------------------------------------------------- diff --git a/src/common/http.cpp b/src/common/http.cpp index 0b57fb0..d3b7ca3 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -123,19 +123,27 @@ JSON::Object model(const Task& task) object.values["state"] = TaskState_Name(task.state()); object.values["resources"] = model(task.resources()); - JSON::Array array; - foreach (const TaskStatus& status, task.statuses()) { - array.values.push_back(model(status)); + { + JSON::Array array; + array.values.reserve(task.statuses().size()); // MESOS-2353. + + foreach (const TaskStatus& status, task.statuses()) { + array.values.push_back(model(status)); + } + object.values["statuses"] = array; } - object.values["statuses"] = array; - JSON::Array labels; - if (task.has_labels()) { - foreach (const Label& label, task.labels().labels()) { - labels.values.push_back(JSON::Protobuf(label)); + { + JSON::Array array; + if (task.has_labels()) { + array.values.reserve(task.labels().labels().size()); // MESOS-2353. + + foreach (const Label& label, task.labels().labels()) { + array.values.push_back(JSON::Protobuf(label)); + } } + object.values["labels"] = array; } - object.values["labels"] = labels; if (task.has_discovery()) { object.values["discovery"] = JSON::Protobuf(task.discovery()); @@ -167,19 +175,27 @@ JSON::Object model( object.values["state"] = TaskState_Name(state); object.values["resources"] = model(task.resources()); - JSON::Array array; - foreach (const TaskStatus& status, statuses) { - array.values.push_back(model(status)); + { + JSON::Array array; + array.values.reserve(statuses.size()); // MESOS-2353. + + foreach (const TaskStatus& status, statuses) { + array.values.push_back(model(status)); + } + object.values["statuses"] = array; } - object.values["statuses"] = array; - JSON::Array labels; - if (task.has_labels()) { - foreach (const Label& label, task.labels().labels()) { - labels.values.push_back(JSON::Protobuf(label)); + { + JSON::Array array; + if (task.has_labels()) { + array.values.reserve(task.labels().labels().size()); // MESOS-2353. + + foreach (const Label& label, task.labels().labels()) { + array.values.push_back(JSON::Protobuf(label)); + } } + object.values["labels"] = array; } - object.values["labels"] = labels; if (task.has_discovery()) { object.values["discovery"] = JSON::Protobuf(task.discovery()); http://git-wip-us.apache.org/repos/asf/mesos/blob/0c7104d4/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 0b56cb4..e1a87d6 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -138,6 +138,8 @@ JSON::Object model(const Framework& framework) // Model all of the tasks associated with a framework. { JSON::Array array; + array.values.reserve( + framework.pendingTasks.size() + framework.tasks.size()); // MESOS-2353. foreachvalue (const TaskInfo& task, framework.pendingTasks) { vector<TaskStatus> statuses; @@ -154,6 +156,8 @@ JSON::Object model(const Framework& framework) // Model all of the completed tasks of a framework. { JSON::Array array; + array.values.reserve(framework.completedTasks.size()); // MESOS-2353. + foreach (const memory::shared_ptr<Task>& task, framework.completedTasks) { array.values.push_back(model(*task)); } @@ -164,6 +168,8 @@ JSON::Object model(const Framework& framework) // Model all of the offers associated with a framework. { JSON::Array array; + array.values.reserve(framework.offers.size()); // MESOS-2353. + foreach (Offer* offer, framework.offers) { array.values.push_back(model(*offer)); } @@ -386,8 +392,7 @@ Future<Response> Master::Http::slaves(const Request& request) { JSON::Array array; foreachvalue (const Slave* slave, master->slaves.registered) { - JSON::Object object = model(*slave); - array.values.push_back(object); + array.values.push_back(model(*slave)); } JSON::Object object; @@ -459,6 +464,8 @@ Future<Response> Master::Http::state(const Request& request) // Model all of the slaves. { JSON::Array array; + array.values.reserve(master->slaves.registered.size()); // MESOS-2353. + foreachvalue (Slave* slave, master->slaves.registered) { array.values.push_back(model(*slave)); } @@ -469,6 +476,8 @@ Future<Response> Master::Http::state(const Request& request) // Model all of the frameworks. { JSON::Array array; + array.values.reserve(master->frameworks.registered.size()); // MESOS-2353. + foreachvalue (Framework* framework, master->frameworks.registered) { array.values.push_back(model(*framework)); } @@ -479,6 +488,7 @@ Future<Response> Master::Http::state(const Request& request) // Model all of the completed frameworks. { JSON::Array array; + array.values.reserve(master->frameworks.completed.size()); // MESOS-2353. foreach (const memory::shared_ptr<Framework>& framework, master->frameworks.completed) {
