Updates to load monitoring and source load tracking.

This commit is contained in:
JoelKatz
2013-03-08 09:48:54 -08:00
parent 2b2e93eef6
commit 7621feda7b
9 changed files with 203 additions and 158 deletions

View File

@@ -88,6 +88,14 @@ public:
// Utilities
Json::Value invokeCommand(Json::Value& jvRequest)
{
if (theApp->getLoadManager().shouldCutoff(mLoadSource))
{
connection_ptr ptr = mConnection.lock();
if (ptr)
ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload");
return rpcError(rpcTOO_BUSY);
}
if (!jvRequest.isMember("command"))
{
Json::Value jvResult(Json::objectValue);
@@ -102,11 +110,12 @@ public:
jvResult["id"] = jvRequest["id"];
}
theApp->getLoadManager().adjust(mLoadSource, 5);
return jvResult;
}
RPCHandler mRPCHandler(&mNetwork,
boost::shared_polymorphic_downcast<InfoSub>(this->shared_from_this()), mLoadSource);
int cost = 10;
RPCHandler mRPCHandler(&mNetwork, boost::shared_polymorphic_downcast<InfoSub>(this->shared_from_this()));
Json::Value jvResult(Json::objectValue);
int iRole = mHandler->getPublic()
@@ -119,9 +128,12 @@ public:
}
else
{
jvResult["result"] = mRPCHandler.doCommand(jvRequest, iRole);
jvResult["result"] = mRPCHandler.doCommand(jvRequest, iRole, cost);
}
if (theApp->getLoadManager().adjust(mLoadSource, cost) && theApp->getLoadManager().shouldWarn(mLoadSource))
jvResult["warning"] = "load";
// Currently we will simply unwrap errors returned by the RPC
// API, in the future maybe we can make the responses
// consistent.