Skip to content

Commit

Permalink
ResourceManager: Set percent limit as configurable
Browse files Browse the repository at this point in the history
Change-Id: Icbf5f88bef01188add510195b8fa637442bb4345
  • Loading branch information
jcaden committed May 23, 2016
1 parent f76c5e5 commit 8272a6a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
5 changes: 5 additions & 0 deletions kurento.conf.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
mediaServer
{
; resources
; {
; ; Resources usage limit for raising an exception when an object creation is attempted
; exceptionLimit 0.8
; }
net
{
websocket
Expand Down
3 changes: 3 additions & 0 deletions kurento.conf.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
; [mediaServer.resources]
; Resources usage limit for raising an exception when an object creation is attempted
; exceptionLimit=0.8
[mediaServer.net.websocket]
port=8888
path=kurento
Expand Down
4 changes: 4 additions & 0 deletions kurento.conf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"mediaServer" : {
//"resources": {
// //Resources usage limit for raising an exception when an object creation is attempted
// "exceptionLimit": "0.8",
//},
"net" : {
// Uncomment just one of them
/*
Expand Down
20 changes: 9 additions & 11 deletions server/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
namespace kurento
{

static const float LIMIT_PERCENT = 0.8;

static int maxOpenFiles = 0;
static int maxThreads = 0;

Expand Down Expand Up @@ -69,20 +67,20 @@ getMaxThreads ()
struct rlimit limits;
getrlimit (RLIMIT_NPROC, &limits);

maxThreads = limits.rlim_cur * LIMIT_PERCENT;
maxThreads = limits.rlim_cur;
}

return maxThreads;
}

static void
checkThreads ()
checkThreads (float limit_percent)
{
int nThreads;

nThreads = getNumberOfThreads ();

if (nThreads > getMaxThreads () ) {
if (nThreads > getMaxThreads () * limit_percent ) {
throw KurentoException (NOT_ENOUGH_RESOURCES, "Too many threads");
}
}
Expand All @@ -94,7 +92,7 @@ getMaxOpenFiles ()
struct rlimit limits;
getrlimit (RLIMIT_NOFILE, &limits);

maxOpenFiles = limits.rlim_cur * LIMIT_PERCENT;
maxOpenFiles = limits.rlim_cur;
}

return maxOpenFiles;
Expand All @@ -119,22 +117,22 @@ getNumberOfOpenFiles ()
}

static void
checkOpenFiles ()
checkOpenFiles (float limit_percent)
{
int nOpenFiles;

nOpenFiles = getNumberOfOpenFiles ();

if (nOpenFiles > getMaxOpenFiles () ) {
if (nOpenFiles > getMaxOpenFiles () * limit_percent ) {
throw KurentoException (NOT_ENOUGH_RESOURCES, "Too many open files");
}
}

void
checkResources (void)
checkResources (float limit_percent)
{
checkThreads ();
checkOpenFiles ();
checkThreads (limit_percent);
checkOpenFiles (limit_percent);
}

} /* kurento */
Expand Down
4 changes: 3 additions & 1 deletion server/ResourceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
namespace kurento
{

void checkResources (void);
static const float DEFAULT_RESOURCE_LIMIT_PERCENT = 0.8;

void checkResources (float limit_percent);

} /* kurento */

Expand Down
9 changes: 8 additions & 1 deletion server/ServerMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ ServerMethods::ServerMethods (const boost::property_tree::ptree &config) :
std::shared_ptr <ServerInfo> serverInfo;
std::shared_ptr<MediaObjectImpl> serverManager;

resourceLimitPercent =
config.get<float> ("mediaServer.resources.exceptionLimit",
DEFAULT_RESOURCE_LIMIT_PERCENT);

GST_INFO ("Not enough resources exception will be raised when resources reach %f ",
resourceLimitPercent);

instanceId = generateUUID();

for (auto moduleIt : moduleManager.getModules () ) {
Expand Down Expand Up @@ -545,7 +552,7 @@ ServerMethods::create (const Json::Value &params,
try {
factory = moduleManager.getFactory (type);

checkResources();
checkResources (resourceLimitPercent);

std::shared_ptr <MediaObjectImpl> object;

Expand Down
2 changes: 2 additions & 0 deletions server/ServerMethods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ServerMethods : public Processor
const boost::property_tree::ptree &config;
JsonRpc::Handler handler;

float resourceLimitPercent;

std::function<std::string (std::shared_ptr<MediaObjectImpl> obj, const std::string &sessionId, const std::string &eventType, const Json::Value &params) >
eventSubscriptionHandler;

Expand Down

0 comments on commit 8272a6a

Please sign in to comment.