From b9c4efbaf84ee0f94a4455f88b6a8f86066869ed Mon Sep 17 00:00:00 2001 From: jsteemann Date: Wed, 24 May 2017 22:00:16 +0200 Subject: [PATCH] added environmentfeature --- arangod/RestServer/arangod.cpp | 2 + .../EnvironmentFeature.cpp | 105 ++++++++++++++++++ lib/ApplicationFeatures/EnvironmentFeature.h | 38 +++++++ lib/ApplicationFeatures/JemallocFeature.cpp | 2 - lib/CMakeLists.txt | 1 + 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 lib/ApplicationFeatures/EnvironmentFeature.cpp create mode 100644 lib/ApplicationFeatures/EnvironmentFeature.h diff --git a/arangod/RestServer/arangod.cpp b/arangod/RestServer/arangod.cpp index 200c0f6603..176f23598f 100644 --- a/arangod/RestServer/arangod.cpp +++ b/arangod/RestServer/arangod.cpp @@ -30,6 +30,7 @@ #include "Agency/AgencyFeature.h" #include "ApplicationFeatures/ConfigFeature.h" #include "ApplicationFeatures/DaemonFeature.h" +#include "ApplicationFeatures/EnvironmentFeature.h" #include "ApplicationFeatures/GreetingsFeature.h" #include "ApplicationFeatures/JemallocFeature.h" #include "ApplicationFeatures/LanguageFeature.h" @@ -144,6 +145,7 @@ static int runServer(int argc, char** argv, ArangoGlobalContext &context) { server.addFeature(new DatabasePathFeature(&server)); server.addFeature(new EndpointFeature(&server)); server.addFeature(new EngineSelectorFeature(&server)); + server.addFeature(new EnvironmentFeature(&server)); server.addFeature(new FeatureCacheFeature(&server)); server.addFeature(new FileDescriptorsFeature(&server)); server.addFeature(new FoxxQueuesFeature(&server)); diff --git a/lib/ApplicationFeatures/EnvironmentFeature.cpp b/lib/ApplicationFeatures/EnvironmentFeature.cpp new file mode 100644 index 0000000000..30969edf5a --- /dev/null +++ b/lib/ApplicationFeatures/EnvironmentFeature.cpp @@ -0,0 +1,105 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2016 ArangoDB GmbH, Cologne, Germany +/// +/// Licensed 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. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Jan Steemann +//////////////////////////////////////////////////////////////////////////////// + +#include "EnvironmentFeature.h" +#include "Basics/FileUtils.h" +#include "Basics/StringUtils.h" +#include "Logger/Logger.h" + +using namespace arangodb; +using namespace arangodb::basics; + +EnvironmentFeature::EnvironmentFeature( + application_features::ApplicationServer* server) + : ApplicationFeature(server, "Environment") { + setOptional(false); + requiresElevatedPrivileges(false); + startsAfter("Greetings"); + startsAfter("Logger"); +} + +void EnvironmentFeature::prepare() { +#if 0 + if (sizeof(void*) == 4) { + // 32 bit build + LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "this is a 32 bit build of ArangoDB. " + << "it is recommended to run a 64 bit build instead because it can " + << "address significantly bigger regions of memory."; + } + +#ifdef __linux__ + try { + std::string value = basics::FileUtils::slurp("/proc/sys/vm/overcommit_memory"); + uint64_t v = basics::StringUtils::uint64(value); + if (v == 2) { + // from https://www.kernel.org/doc/Documentation/sysctl/vm.txt: + // + // When this flag is 0, the kernel attempts to estimate the amount + // of free memory left when userspace requests more memory. + // When this flag is 1, the kernel pretends there is always enough + // memory until it actually runs out. + // When this flag is 2, the kernel uses a "never overcommit" + // policy that attempts to prevent any overcommit of memory. + LOG_TOPIC(WARN, Logger::FIXME) << "/proc/sys/vm/overcommit_memory is set to '" + << v << "'. it is recommended to set it to a value of 0 or 1"; + } + } catch (...) { + // file not found or value not convertible into integer + } + + try { + std::string value = basics::FileUtils::slurp("/proc/sys/vm/zone_reclaim_mode"); + uint64_t v = basics::StringUtils::uint64(value); + if (v != 0) { + // from https://www.kernel.org/doc/Documentation/sysctl/vm.txt: + // + // This is value ORed together of + // 1 = Zone reclaim on + // 2 = Zone reclaim writes dirty pages out + // 4 = Zone reclaim swaps pages + // + // https://www.poempelfox.de/blog/2010/03/19/ + LOG_TOPIC(WARN, Logger::FIXME) << "/proc/sys/vm/zone_reclaim_mode is set to '" + << v << "'. it is recommended to set it to a value of 0"; + } + } catch (...) { + // file not found or value not convertible into integer + } + + try { + std::string value = basics::FileUtils::slurp("/sys/kernel/mm/transparent_hugepage/enabled"); + size_t start = value.find('['); + size_t end = value.find(']'); + if (start != std::string::npos && end != std::string::npos && start < end && end - start >= 4) { + value = value.substr(start + 1, end - start - 1); + if (value == "always") { + LOG_TOPIC(WARN, Logger::FIXME) << "/sys/kernel/mm/transparent_hugepage/enabled is set to '" + << value << "'. it is recommended to set it to a value of 'never' or 'madvise'"; + } + } + } catch (...) { + // file not found + } +#endif + +#endif +} diff --git a/lib/ApplicationFeatures/EnvironmentFeature.h b/lib/ApplicationFeatures/EnvironmentFeature.h new file mode 100644 index 0000000000..c450fe79cc --- /dev/null +++ b/lib/ApplicationFeatures/EnvironmentFeature.h @@ -0,0 +1,38 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2016 ArangoDB GmbH, Cologne, Germany +/// +/// Licensed 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. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Jan Steemann +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGODB_APPLICATION_FEATURES_ENVIRONMENT_FEATURE_H +#define ARANGODB_APPLICATION_FEATURES_ENVIRONMENT_FEATURE_H 1 + +#include "ApplicationFeatures/ApplicationFeature.h" + +namespace arangodb { +class EnvironmentFeature final : public application_features::ApplicationFeature { + public: + explicit EnvironmentFeature(application_features::ApplicationServer* server); + + public: + void prepare() override final; +}; +} + +#endif diff --git a/lib/ApplicationFeatures/JemallocFeature.cpp b/lib/ApplicationFeatures/JemallocFeature.cpp index 94e85f9a03..408bdb2395 100644 --- a/lib/ApplicationFeatures/JemallocFeature.cpp +++ b/lib/ApplicationFeatures/JemallocFeature.cpp @@ -28,8 +28,6 @@ #include "Logger/Logger.h" #include "ProgramOptions/ProgramOptions.h" -#include - using namespace arangodb; using namespace arangodb::basics; using namespace arangodb::options; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index dc0e9ab25c..efd302f847 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -110,6 +110,7 @@ add_library(${LIB_ARANGO} STATIC ApplicationFeatures/ApplicationFeature.cpp ApplicationFeatures/ApplicationServer.cpp ApplicationFeatures/ConfigFeature.cpp + ApplicationFeatures/EnvironmentFeature.cpp ApplicationFeatures/GreetingsFeature.cpp ApplicationFeatures/JemallocFeature.cpp ApplicationFeatures/LanguageFeature.cpp