New ResourceManager for managing server load.

* Track abusive endpoints
* Gossip across cluster.
* Use resource manager's gossip support to share load reporting across a cluster
* Swtich from legacy fees to new Resource::Charge fees.
* Connect RPC to the new resource manager.
* Set load levels where needed in RPC/websocket commands.
* Disconnect abusive peer endpoints.
* Don't start conversations with abusive peer endpoints.
* Move Resource::Consumer to InfoSub and remove LoadSource
* Remove port from inbound Consumer keys
* Add details in getJson
* Fix doAccountCurrencies for the new resource manager.
This commit is contained in:
David Schwartz
2013-10-29 17:35:47 -07:00
committed by Vinnie Falco
parent a05f33f6a7
commit 58f07a573f
48 changed files with 665 additions and 759 deletions

View File

@@ -56,5 +56,15 @@ std::ostream& operator<< (std::ostream& os, Charge const& v)
return os;
}
bool Charge::operator== (Charge const& c) const
{
return c.m_cost == m_cost;
}
bool Charge::operator!= (Charge const& c) const
{
return c.m_cost != m_cost;
}
}
}

View File

@@ -87,11 +87,15 @@ std::string Consumer::to_string () const
bool Consumer::admin () const
{
return m_entry->admin();
if (m_entry != nullptr)
return m_entry->admin();
return false;
}
void Consumer::elevate (std::string const& name)
{
bassert (m_entry != nullptr);
m_entry = &m_logic->elevateToAdminEndpoint (*m_entry, name);
}
@@ -102,26 +106,31 @@ Disposition Consumer::disposition() const
Disposition Consumer::charge (Charge const& what)
{
bassert (m_entry != nullptr);
return m_logic->charge (*m_entry, what);
}
bool Consumer::warn ()
{
bassert (m_entry != nullptr);
return m_logic->warn (*m_entry);
}
bool Consumer::disconnect ()
{
bassert (m_entry != nullptr);
return m_logic->disconnect (*m_entry);
}
int Consumer::balance()
{
bassert (m_entry != nullptr);
return m_logic->balance (*m_entry);
}
Entry& Consumer::entry()
{
bassert (m_entry != nullptr);
return *m_entry;
}

View File

@@ -83,7 +83,7 @@ public:
Key key;
key.kind = kindInbound;
key.address = address;
key.address = address.withPort (0);
Entry* entry (nullptr);
@@ -202,6 +202,61 @@ public:
return *entry;
}
Json::Value getJson ()
{
return getJson (warningThreshold);
}
Json::Value getJson (int threshold)
{
DiscreteTime const now (m_clock());
Json::Value ret (Json::objectValue);
SharedState::Access state (m_state);
for (List <Entry>::iterator iter (state->inbound.begin());
iter != state->inbound.end(); ++iter)
{
int localBalance = iter->local_balance.value (now);
if ((localBalance + iter->remote_balance) >= threshold)
{
Json::Value& entry = (ret[iter->to_string()] = Json::objectValue);
entry["local"] = localBalance;
entry["remote"] = iter->remote_balance;
entry["type"] = "outbound";
}
}
for (List <Entry>::iterator iter (state->outbound.begin());
iter != state->outbound.end(); ++iter)
{
int localBalance = iter->local_balance.value (now);
if ((localBalance + iter->remote_balance) >= threshold)
{
Json::Value& entry = (ret[iter->to_string()] = Json::objectValue);
entry["local"] = localBalance;
entry["remote"] = iter->remote_balance;
entry["type"] = "outbound";
}
}
for (List <Entry>::iterator iter (state->admin.begin());
iter != state->admin.end(); ++iter)
{
int localBalance = iter->local_balance.value (now);
if ((localBalance + iter->remote_balance) >= threshold)
{
Json::Value& entry = (ret[iter->to_string()] = Json::objectValue);
entry["local"] = localBalance;
entry["remote"] = iter->remote_balance;
entry["type"] = "admin";
}
}
return ret;
}
Gossip exportConsumers ()
{
DiscreteTime const now (m_clock());
@@ -318,8 +373,8 @@ public:
}
}
for (Imports::iterator iter (state->import_table.begin());
iter != state->import_table.end(); ++iter)
Imports::iterator iter (state->import_table.begin());
while (iter != state->import_table.end())
{
Import& import (iter->second);
if (iter->second.whenExpires <= now)
@@ -332,6 +387,8 @@ public:
iter = state->import_table.erase (iter);
}
else
++iter;
}
}

View File

@@ -68,6 +68,18 @@ public:
//--------------------------------------------------------------------------
Json::Value getJson ()
{
return m_logic.getJson ();
}
Json::Value getJson (int threshold)
{
return m_logic.getJson (threshold);
}
//--------------------------------------------------------------------------
void onWrite (PropertyStream::Map& map)
{
m_logic.onWrite (map);