Log when we would disconnected, but don't actually disconnect for now.

This commit is contained in:
JoelKatz
2013-03-10 19:15:28 -07:00
parent 4b449b5c99
commit 92318a47bd
3 changed files with 16 additions and 2 deletions

View File

@@ -124,7 +124,10 @@ void LoadManager::canonicalize(LoadSource& source, int now) const
{ {
source.mBalance += mCreditRate * (now - source.mLastUpdate); source.mBalance += mCreditRate * (now - source.mLastUpdate);
if (source.mBalance > mCreditLimit) if (source.mBalance > mCreditLimit)
{
source.mBalance = mCreditLimit; source.mBalance = mCreditLimit;
source.mLogged = false;
}
} }
source.mLastUpdate = now; source.mLastUpdate = now;
} }
@@ -154,6 +157,9 @@ bool LoadManager::shouldCutoff(LoadSource& source) const
canonicalize(source, now); canonicalize(source, now);
if (source.isPrivileged() || (source.mBalance > mDebitLimit)) if (source.isPrivileged() || (source.mBalance > mDebitLimit))
return false; return false;
if (source.mLogged)
return true;
source.mLogged = true;
} }
logDisconnect(source.getName()); logDisconnect(source.getName());
return true; return true;

View File

@@ -66,11 +66,14 @@ protected:
int mFlags; int mFlags;
int mLastUpdate; int mLastUpdate;
int mLastWarning; int mLastWarning;
bool mLogged;
public: public:
LoadSource(bool admin) : mBalance(0), mFlags(admin ? lsfPrivileged : 0), mLastUpdate(upTime()), mLastWarning(0) LoadSource(bool admin) :
mBalance(0), mFlags(admin ? lsfPrivileged : 0), mLastUpdate(upTime()), mLastWarning(0), mLogged(false)
{ ; } { ; }
LoadSource(const std::string& name) : mName(name), mBalance(0), mFlags(0), mLastUpdate(upTime()), mLastWarning(0) LoadSource(const std::string& name) :
mName(name), mBalance(0), mFlags(0), mLastUpdate(upTime()), mLastWarning(0), mLogged(false)
{ ; } { ; }
void rename(const std::string& name) { mName = name; } void rename(const std::string& name) { mName = name; }
@@ -80,6 +83,9 @@ public:
void setPrivileged() { mFlags |= lsfPrivileged; } void setPrivileged() { mFlags |= lsfPrivileged; }
int getBalance() const { return mBalance; } int getBalance() const { return mBalance; }
bool isLogged() const { return mLogged; }
void clearLogged() { mLogged = false; }
void setOutbound() { mFlags |= lsfOutbound; } void setOutbound() { mFlags |= lsfOutbound; }
bool isOutbound() const { return (mFlags & lsfOutbound) != 0; } bool isOutbound() const { return (mFlags & lsfOutbound) != 0; }
}; };

View File

@@ -90,10 +90,12 @@ public:
{ {
if (theApp->getLoadManager().shouldCutoff(mLoadSource)) if (theApp->getLoadManager().shouldCutoff(mLoadSource))
{ {
#if SHOULD_DISCONNECT
connection_ptr ptr = mConnection.lock(); connection_ptr ptr = mConnection.lock();
if (ptr) if (ptr)
ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload"); ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload");
return rpcError(rpcSLOW_DOWN); return rpcError(rpcSLOW_DOWN);
#endif
} }
if (!jvRequest.isMember("command")) if (!jvRequest.isMember("command"))