Repository: mesos Updated Branches: refs/heads/master 3633142e4 -> 6fdd2d40e
Avoid docker inspect on each usage call Review: https://reviews.apache.org/r/26436 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6fdd2d40 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6fdd2d40 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6fdd2d40 Branch: refs/heads/master Commit: 6fdd2d40e588a0d45c388a29bdf8a1d976b3af7c Parents: 3633142 Author: Timothy Chen <[email protected]> Authored: Fri Oct 17 16:05:12 2014 -0700 Committer: Timothy Chen <[email protected]> Committed: Fri Oct 31 17:07:20 2014 -0700 ---------------------------------------------------------------------- src/slave/containerizer/docker.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/6fdd2d40/src/slave/containerizer/docker.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp index 33ec6de..a668920 100644 --- a/src/slave/containerizer/docker.cpp +++ b/src/slave/containerizer/docker.cpp @@ -199,8 +199,12 @@ private: pid_t pid); Future<ResourceStatistics> _usage( - const ContainerID& containerId, - const Docker::Container& container); + const ContainerID& containerId, + const Docker::Container& container); + + Future<ResourceStatistics> __usage( + const ContainerID& containerId, + pid_t pid); // Call back for when the executor exits. This will trigger // container destroy. @@ -1380,6 +1384,11 @@ Future<ResourceStatistics> DockerContainerizerProcess::usage( return Failure("Container is being removed: " + stringify(containerId)); } + // Skip inspecting the docker container if we already have the pid. + if (container->pid.isSome()) { + return __usage(containerId, container->pid.get()); + } + return docker->inspect(container->name()) .then(defer(self(), &Self::_usage, containerId, lambda::_1)); #endif // __linux__ @@ -1405,11 +1414,22 @@ Future<ResourceStatistics> DockerContainerizerProcess::_usage( return Failure("Container is not running"); } + container->pid = pid; + + return __usage(containerId, pid.get()); +} + + +Future<ResourceStatistics> DockerContainerizerProcess::__usage( + const ContainerID& containerId, + pid_t pid) +{ + Container* container = containers_[containerId]; + // Note that here getting the root pid is enough because // the root process acts as an 'init' process in the docker // container, so no other child processes will escape it. - Try<ResourceStatistics> statistics = - mesos::internal::usage(pid.get(), true, true); + Try<ResourceStatistics> statistics = mesos::internal::usage(pid, true, true); if (statistics.isError()) { return Failure(statistics.error()); }
