You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/06/05 00:01:51 UTC
[1/2] mesos git commit: Added a fixed resource estimator.
Repository: mesos
Updated Branches:
refs/heads/master 7b99908da -> 5706b76c9
Added a fixed resource estimator.
Review: https://reviews.apache.org/r/35028
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5706b76c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5706b76c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5706b76c
Branch: refs/heads/master
Commit: 5706b76c97c1f669e6675f21f947a73d35726362
Parents: 2197e03
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Jun 3 15:02:11 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 4 15:01:33 2015 -0700
----------------------------------------------------------------------
src/Makefile.am | 34 +++---
src/slave/resource_estimator.cpp | 19 +++-
src/slave/resource_estimators/fixed.cpp | 152 +++++++++++++++++++++++++++
src/tests/oversubscription_tests.cpp | 97 +++++++++++++++++
4 files changed, 287 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5706b76c/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index cc3d2e6..3cf8bd2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1387,24 +1387,32 @@ active_user_test_helper_LDADD = libmesos.la $(LDADD)
check_PROGRAMS += mesos-tests
# LDFLAGS to be used for the module libraries.
-# We need to build the module libraries for running the test suite but don't
-# need to install them. The 'noinst_' prefix ensures that these libraries will
-# not be installed. However, it also skips building the shared libraries. The
-# workaround is to use '-rpath /nowhere' to force libtool to build the shared
-# library.
-MESOS_MODULE_LDFLAGS = -release $(PACKAGE_VERSION) -shared -rpath /nowhere
+MESOS_MODULE_LDFLAGS = -release $(PACKAGE_VERSION) -shared
+
+# Library containing the fixed resource estimator.
+lib_LTLIBRARIES += libfixed_resource_estimator.la
+libfixed_resource_estimator_la_SOURCES = slave/resource_estimators/fixed.cpp
+libfixed_resource_estimator_la_CPPFLAGS = $(MESOS_CPPFLAGS)
+libfixed_resource_estimator_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+
+# We need to build the test module libraries for running the test suite but
+# don't need to install them. The 'noinst_' prefix ensures that these libraries
+# will not be installed. However, it also skips building the shared libraries.
+# The workaround is to use '-rpath /nowhere' to force libtool to build the
+# shared library.
+MESOS_TEST_MODULE_LDFLAGS = $(MESOS_MODULE_LDFLAGS) -rpath /nowhere
# Library containing an example module.
noinst_LTLIBRARIES += libexamplemodule.la
libexamplemodule_la_SOURCES = examples/example_module_impl.cpp
libexamplemodule_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libexamplemodule_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libexamplemodule_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing the test anonymous modules.
noinst_LTLIBRARIES += libtestanonymous.la
libtestanonymous_la_SOURCES = examples/test_anonymous_module.cpp
libtestanonymous_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtestanonymous_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtestanonymous_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing the test CRAM-MD5 authentication modules.
# TODO(tillt): Add cyrus-sasl2 dependency while removing it from libmesos.
@@ -1413,32 +1421,32 @@ libtestanonymous_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
noinst_LTLIBRARIES += libtestauthentication.la
libtestauthentication_la_SOURCES = examples/test_authentication_modules.cpp
libtestauthentication_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtestauthentication_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtestauthentication_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing the test DRF allocator module.
noinst_LTLIBRARIES += libtestallocator.la
libtestallocator_la_SOURCES = examples/test_allocator_module.cpp
libtestallocator_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtestallocator_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtestallocator_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing test Hook module.
noinst_LTLIBRARIES += libtesthook.la
libtesthook_la_SOURCES = examples/test_hook_module.cpp
libtesthook_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtesthook_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtesthook_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing test CPU and memory isolator modules.
noinst_LTLIBRARIES += libtestisolator.la
libtestisolator_la_SOURCES = examples/test_isolator_module.cpp
libtestisolator_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtestisolator_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtestisolator_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
# Library containing example test noop resource estimator module.
noinst_LTLIBRARIES += libtestresource_estimator.la
libtestresource_estimator_la_SOURCES = \
examples/test_resource_estimator_module.cpp
libtestresource_estimator_la_CPPFLAGS = $(MESOS_CPPFLAGS)
-libtestresource_estimator_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+libtestresource_estimator_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS)
mesos_tests_SOURCES = \
tests/anonymous_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/5706b76c/src/slave/resource_estimator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/resource_estimator.cpp b/src/slave/resource_estimator.cpp
index 5aaf305..4a677a6 100644
--- a/src/slave/resource_estimator.cpp
+++ b/src/slave/resource_estimator.cpp
@@ -18,6 +18,12 @@
#include <stout/error.hpp>
+#include <mesos/module/resource_estimator.hpp>
+
+#include <mesos/slave/resource_estimator.hpp>
+
+#include "module/manager.hpp"
+
#include "slave/resource_estimators/noop.hpp"
using std::string;
@@ -27,12 +33,21 @@ namespace slave {
Try<ResourceEstimator*> ResourceEstimator::create(const Option<string>& type)
{
- // TODO(jieyu): Support loading resource estimator from module.
if (type.isNone()) {
return new internal::slave::NoopResourceEstimator();
}
- return Error("Unsupported resource estimator '" + type.get() + "'");
+ // Try to load resource estimator from module.
+ Try<ResourceEstimator*> module =
+ modules::ModuleManager::create<ResourceEstimator>(type.get());
+
+ if (module.isError()) {
+ return Error(
+ "Failed to create resource estimator module '" + type.get() +
+ "': " + module.error());
+ }
+
+ return module.get();
}
} // namespace slave {
http://git-wip-us.apache.org/repos/asf/mesos/blob/5706b76c/src/slave/resource_estimators/fixed.cpp
----------------------------------------------------------------------
diff --git a/src/slave/resource_estimators/fixed.cpp b/src/slave/resource_estimators/fixed.cpp
new file mode 100644
index 0000000..fb7bb18
--- /dev/null
+++ b/src/slave/resource_estimators/fixed.cpp
@@ -0,0 +1,152 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <list>
+
+#include <mesos/resources.hpp>
+
+#include <mesos/module/resource_estimator.hpp>
+
+#include <mesos/slave/resource_estimator.hpp>
+
+#include <process/dispatch.hpp>
+#include <process/owned.hpp>
+#include <process/process.hpp>
+
+#include <stout/lambda.hpp>
+
+using namespace mesos;
+using namespace process;
+
+using mesos::modules::Module;
+
+using mesos::slave::ResourceEstimator;
+
+using std::list;
+
+
+class FixedResourceEstimatorProcess
+ : public Process<FixedResourceEstimatorProcess>
+{
+public:
+ FixedResourceEstimatorProcess(
+ const lambda::function<Future<list<ResourceUsage>>()>& _usages,
+ const Resources& _resources)
+ : usages(_usages),
+ resources(_resources) {}
+
+ Future<Resources> oversubscribable()
+ {
+ // TODO(jieyu): This is a stub implementation.
+ return resources;
+ }
+
+private:
+ const lambda::function<Future<list<ResourceUsage>>()>& usages;
+ const Resources resources;
+};
+
+
+class FixedResourceEstimator : public ResourceEstimator
+{
+public:
+ FixedResourceEstimator(const Resources& _resources)
+ : resources(_resources)
+ {
+ // Mark all resources as revocable.
+ foreach (Resource& resource, resources) {
+ resource.mutable_revocable();
+ }
+ }
+
+ virtual ~FixedResourceEstimator()
+ {
+ if (process.get() != NULL) {
+ terminate(process.get());
+ wait(process.get());
+ }
+ }
+
+ virtual Try<Nothing> initialize(
+ const lambda::function<Future<list<ResourceUsage>>()>& usages)
+ {
+ if (process.get() != NULL) {
+ return Error("Fixed resource estimator has already been initialized");
+ }
+
+ process.reset(new FixedResourceEstimatorProcess(usages, resources));
+ spawn(process.get());
+
+ return Nothing();
+ }
+
+ virtual Future<Resources> oversubscribable()
+ {
+ if (process.get() == NULL) {
+ return Failure("Fixed resource estimator is not initialized");
+ }
+
+ return dispatch(
+ process.get(),
+ &FixedResourceEstimatorProcess::oversubscribable);
+ }
+
+private:
+ Resources resources;
+ Owned<FixedResourceEstimatorProcess> process;
+};
+
+
+static bool compatible()
+{
+ // TODO(jieyu): Check compatibility.
+ return true;
+}
+
+
+static ResourceEstimator* create(const Parameters& parameters)
+{
+ // Obtain the *fixed* resources from parameters.
+ Option<Resources> resources;
+ foreach (const Parameter& parameter, parameters.parameter()) {
+ if (parameter.key() == "resources") {
+ Try<Resources> _resources = Resources::parse(parameter.value());
+ if (_resources.isError()) {
+ return NULL;
+ }
+
+ resources = _resources.get();
+ }
+ }
+
+ if (resources.isNone()) {
+ return NULL;
+ }
+
+ return new FixedResourceEstimator(resources.get());
+}
+
+
+Module<ResourceEstimator> org_apache_mesos_FixedResourceEstimator(
+ MESOS_MODULE_API_VERSION,
+ MESOS_VERSION,
+ "Apache Mesos",
+ "modules@mesos.apache.org",
+ "Fixed Resource Estimator Module.",
+ compatible,
+ create);
http://git-wip-us.apache.org/repos/asf/mesos/blob/5706b76c/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp b/src/tests/oversubscription_tests.cpp
index 43a13ee..a49cb39 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -28,6 +28,8 @@
#include <process/gtest.hpp>
#include <stout/gtest.hpp>
+#include <stout/os.hpp>
+#include <stout/path.hpp>
#include "common/resources_utils.hpp"
@@ -35,9 +37,12 @@
#include "messages/messages.hpp"
+#include "module/manager.hpp"
+
#include "slave/flags.hpp"
#include "slave/slave.hpp"
+#include "tests/flags.hpp"
#include "tests/mesos.hpp"
#include "tests/utils.hpp"
@@ -58,9 +63,58 @@ namespace mesos {
namespace internal {
namespace tests {
+const char FIXED_RESOURCE_ESTIMATOR_NAME[] =
+ "org_apache_mesos_FixedResourceEstimator";
+
+
class OversubscriptionTest : public MesosTest
{
protected:
+ virtual void SetUp()
+ {
+ MesosTest::SetUp();
+
+ // Get the current value of LD_LIBRARY_PATH.
+ originalLDLibraryPath = os::libraries::paths();
+
+ // Append our library path to LD_LIBRARY_PATH so that dlopen can
+ // search the library directory for module libraries.
+ os::libraries::appendPaths(
+ path::join(tests::flags.build_dir, "src", ".libs"));
+ }
+
+ virtual void TearDown()
+ {
+ // Unload modules.
+ foreach (const Modules::Library& library, modules.libraries()) {
+ foreach (const Modules::Library::Module& module, library.modules()) {
+ if (module.has_name()) {
+ ASSERT_SOME(modules::ModuleManager::unload(module.name()));
+ }
+ }
+ }
+
+ // Restore LD_LIBRARY_PATH environment variable.
+ os::libraries::setPaths(originalLDLibraryPath);
+
+ MesosTest::TearDown();
+ }
+
+ void loadFixedResourceEstimatorModule(const string& resources)
+ {
+ Modules::Library* library = modules.add_libraries();
+ library->set_name("fixed_resource_estimator");
+
+ Modules::Library::Module* module = library->add_modules();
+ module->set_name(FIXED_RESOURCE_ESTIMATOR_NAME);
+
+ Parameter* parameter = module->add_parameters();
+ parameter->set_key("resources");
+ parameter->set_value(resources);
+
+ ASSERT_SOME(modules::ModuleManager::load(modules));
+ }
+
// TODO(vinod): Make this a global helper that other tests (e.g.,
// hierarchical allocator tests) can use.
Resources createRevocableResources(
@@ -72,6 +126,10 @@ protected:
resource.mutable_revocable();
return resource;
}
+
+private:
+ string originalLDLibraryPath;
+ Modules modules;
};
@@ -291,6 +349,45 @@ TEST_F(OversubscriptionTest, RescindRevocableOffer)
Shutdown();
}
+
+// This test verifies the functionality of the fixed resource
+// estimator. The total oversubscribed resources on the slave that
+// uses a fixed resource estimator should stay the same.
+TEST_F(OversubscriptionTest, FixedResourceEstimator)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Future<SlaveRegisteredMessage> slaveRegistered =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ Future<UpdateSlaveMessage> update =
+ FUTURE_PROTOBUF(UpdateSlaveMessage(), _, _);
+
+ loadFixedResourceEstimatorModule("cpus(*):2");
+
+ slave::Flags flags = CreateSlaveFlags();
+ flags.resource_estimator = FIXED_RESOURCE_ESTIMATOR_NAME;
+
+ Try<PID<Slave>> slave = StartSlave(flags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(slaveRegistered);
+
+ // Advance the clock for the slave to send the estimate.
+ Clock::pause();
+ Clock::advance(flags.oversubscribed_resources_interval);
+ Clock::settle();
+
+ AWAIT_READY(update);
+
+ Resources resources = update.get().oversubscribed_resources();
+
+ EXPECT_SOME_EQ(2.0, resources.cpus());
+
+ Shutdown();
+}
+
} // namespace tests {
} // namespace internal {
} // namespace mesos {
[2/2] mesos git commit: Adjusted the NoopResourceEstimator to the new
slave semantics.
Posted by ji...@apache.org.
Adjusted the NoopResourceEstimator to the new slave semantics.
Review: https://reviews.apache.org/r/35082
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2197e039
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2197e039
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2197e039
Branch: refs/heads/master
Commit: 2197e039e278f194b1aeef4dd6d20c9394842919
Parents: 7b99908
Author: Jie Yu <yu...@gmail.com>
Authored: Thu Jun 4 10:52:06 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 4 15:01:33 2015 -0700
----------------------------------------------------------------------
src/slave/resource_estimators/noop.cpp | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2197e039/src/slave/resource_estimators/noop.cpp
----------------------------------------------------------------------
diff --git a/src/slave/resource_estimators/noop.cpp b/src/slave/resource_estimators/noop.cpp
index 772eb4e..5f135ff 100644
--- a/src/slave/resource_estimators/noop.cpp
+++ b/src/slave/resource_estimators/noop.cpp
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+#include <list>
+
#include <process/dispatch.hpp>
#include <process/process.hpp>
@@ -25,6 +27,8 @@
using namespace process;
+using std::list;
+
namespace mesos {
namespace internal {
namespace slave {
@@ -33,20 +37,10 @@ class NoopResourceEstimatorProcess :
public Process<NoopResourceEstimatorProcess>
{
public:
- NoopResourceEstimatorProcess() : sent(false) {}
-
Future<Resources> oversubscribable()
{
- if (!sent) {
- sent = true;
- return Resources();
- }
-
- return Future<Resources>();
+ return Resources();
}
-
-private:
- bool sent;
};
@@ -60,7 +54,7 @@ NoopResourceEstimator::~NoopResourceEstimator()
Try<Nothing> NoopResourceEstimator::initialize(
- const lambda::function<Future<std::list<ResourceUsage>>()>& usages)
+ const lambda::function<Future<list<ResourceUsage>>()>& usages)
{
if (process.get() != NULL) {
return Error("Noop resource estimator has already been initialized");