Skip to content

Instantly share code, notes, and snippets.

@scj7t4
Created July 9, 2013 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scj7t4/5961339 to your computer and use it in GitHub Desktop.
Save scj7t4/5961339 to your computer and use it in GitHub Desktop.
Load Balancing Prototype
class LBAgentBase
{
public:
// USER OVERLOADED FUNCTIONS
// USER OVERLOADABLE FUNCTIONS
void Init(); /// Called in run, sets any persistent user defined values like collected devices
void DetermineState(); /// Function which computes the state based on the current normal.
SignalValue ComputeNormal(vector uuid devicetype valuetype value); /// Using the collected state, compute normal.
SignalValue ComputeGateway(device state); /// Given the current state of local devices, compute & return agg
/// gateway.
std::vector<string> DraftSelect(DRAFT RESPONSES); /// Given a set of response messages from demand nodes,
///select which nodes the supply node will attempt to migrate with and the amount to migrate.
ptree DraftData(); /// Return a ptree of values for responding to draft requests.
std::string SelectGatewayDevice(draftingsource, migrationamount); // Given a drafting request select the gateway device that should accept the migration.
// USER CALLABLE FUNCTIONS
void LoadTable(); /// Puts a loadtable out to the logger.
void AddCollectedValue(devicetype,valuetype); /// Adds a new device type and value to collect
void RemoveCollectedValue(devicetype,valuetype); /// Adds a new device type and value to collect
// HIDDEN FUNCTIONS
private:
void Run(); /// Boostraps the Loadmanage and state collection request into the schedule.
void CollectState(); /// Makes the request to collect the state from the remote device. Bootstrapped by run, self scheduling.
void LoadManage(); /// Performs the actual migration behavior sequence. Bootstrapped by run, self-scheduling.
/// 1) Determines the nodes' new state. 2) Pushes out the node's state. 3) Determines how much time remains
/// and if it should schedule for same phase or next phase.
void StateChange(); /// Pushes out a nodes new state if it is changed, or if it is in DEMAND.
void SendDraftRequest(); /// Pushes out draft requests if this node is in the supply state
void Drafting(); /// After a timeout period, drafting should be called. This calls DraftSelect and then
/// Sends Drafting messages to the modules selected by draft select.
void Migrate(<device>,<amount>); /// Given a device and amount to migrate; migrates that device.
void ReadDevices(); /// Creates a mirror of the device buffer that this module can scratch on.
// MESSAGE FUNCTIONS
CMessage MessageSCRequest(); /// Generates a CMessage that will request state collection.
CMessage MessageDraftRequest(); /// Generates a CMessage that will request drafting messages from demand nodes.
CMessage MessageDraft(); /// Generates a draft message; includes the output of the DraftData function.
CMessage MessageDrafting(); /// Generates a CMessage describing how much the remote node should migrate.
CMessage MessageAccept(); /// Generates a CMessage accepting a proposed drafting.
// HANDLER FUNCTIONS
void HandleCollectedState();
void HandleRequestDraft();
void HandleDraft();
void HandleDrafting();
void HandleAccept();
void HandlePeerList();
void HandleNormal();
// Values
SignalValue m_normal;
ENUM LoadBalanceStatus m_status;
std::map<PeerNode, Device, MigrationAmnt> m_drafts;
std::map<deviceid, valuename, value> m_devices;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment