From 4a21095cf0936183f38b2fc094d658451b2e7435 Mon Sep 17 00:00:00 2001 From: Jose Antonio Santos Cadenas Date: Fri, 15 May 2015 14:35:23 +0200 Subject: [PATCH] ResourceManager: Add configuration for killing server when low resources Change-Id: I46ecc8288cd38d9019e7337f8fab471c4539022e --- kurento.conf.info | 2 ++ kurento.conf.ini | 3 +++ kurento.conf.json | 2 ++ server/ResourceManager.cpp | 17 +++++++++++++++++ server/ResourceManager.hpp | 2 ++ server/main.cpp | 15 +++++++++++++-- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/kurento.conf.info b/kurento.conf.info index 2924e5e81..a5c798732 100644 --- a/kurento.conf.info +++ b/kurento.conf.info @@ -4,6 +4,8 @@ mediaServer ; { ; ; Resources usage limit for raising an exception when an object creation is attempted ; exceptionLimit 0.8 +; ; Resources usage limit for restarting the server when no objects are alive +; killLimit 0.7 ; } net { diff --git a/kurento.conf.ini b/kurento.conf.ini index 383ad49ce..3189f5732 100644 --- a/kurento.conf.ini +++ b/kurento.conf.ini @@ -1,6 +1,9 @@ ; [mediaServer.resources] ; Resources usage limit for raising an exception when an object creation is attempted ; exceptionLimit=0.8 +; Resources usage limit for restarting the server when no objects are alive +; killLimit=0.7 + [mediaServer.net.websocket] port=8888 path=kurento diff --git a/kurento.conf.json b/kurento.conf.json index c8d79da9b..4fd924665 100644 --- a/kurento.conf.json +++ b/kurento.conf.json @@ -3,6 +3,8 @@ //"resources": { // //Resources usage limit for raising an exception when an object creation is attempted // "exceptionLimit": "0.8", + // // Resources usage limit for restarting the server when no objects are alive + // "killLimit": "0.7" //}, "net" : { // Uncomment just one of them diff --git a/server/ResourceManager.cpp b/server/ResourceManager.cpp index b29e99bca..f2b90391e 100644 --- a/server/ResourceManager.cpp +++ b/server/ResourceManager.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -135,6 +136,22 @@ checkResources (float limit_percent) checkOpenFiles (limit_percent); } +void killServerOnLowResources (float limit_percent) +{ + MediaSet::getMediaSet()->signalEmptyLocked.connect ([limit_percent] () { + GST_DEBUG ("MediaSet empty, checking resources"); + + try { + checkResources (limit_percent); + } catch (KurentoException &e) { + if (e.getCode() == NOT_ENOUGH_RESOURCES) { + GST_ERROR ("Resources over the limit, server will be killed"); + exit (1); + } + } + }); +} + } /* kurento */ static void init_debug (void) __attribute__ ( (constructor) ); diff --git a/server/ResourceManager.hpp b/server/ResourceManager.hpp index 21a556f14..adc1fc451 100644 --- a/server/ResourceManager.hpp +++ b/server/ResourceManager.hpp @@ -23,6 +23,8 @@ static const float DEFAULT_RESOURCE_LIMIT_PERCENT = 0.8; void checkResources (float limit_percent); +void killServerOnLowResources (float limit_percent); + } /* kurento */ #endif /* __RESOURCE_MANAGER_H__ */ diff --git a/server/main.cpp b/server/main.cpp index eb39ce17b..7b5c2e6f2 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -25,6 +25,7 @@ #include #include "TransportFactory.hpp" +#include "ResourceManager.hpp" #include #include @@ -32,6 +33,7 @@ #include #include +#include #include "logging.hpp" #include "modules.hpp" @@ -148,7 +150,8 @@ main (int argc, char **argv) boost::program_options::store (boost::program_options::parse_environment (desc, [&desc] (std::string & input) -> std::string { /* Look for KURENTO_ prefix and change to lower case */ - if (input.find (ENV_PREFIX) == 0) { + if (input.find (ENV_PREFIX) == 0) + { std::string aux = input.substr (ENV_PREFIX.size() ); std::transform (aux.begin(), aux.end(), aux.begin(), [] (int c) -> int { return (c == '_') ? '-' : tolower (c); @@ -201,7 +204,6 @@ main (int argc, char **argv) print_version(); exit (0); } - } catch (boost::program_options::error &e) { std::cerr << "Error : " << e.what() << std::endl; exit (1); @@ -219,6 +221,15 @@ main (int argc, char **argv) GST_INFO ("Kmsc version: %s", get_version () ); loadConfig (config, confFile, modulesConfigPath); + + boost::optional killResourceLimit = + config.get_optional ("mediaServer.resources.killLimit"); + + if (killResourceLimit) { + GST_INFO ("Resource limit is: %f", *killResourceLimit); + killServerOnLowResources (*killResourceLimit); + } + transport = createTransportFromConfig (config); /* Start transport */