hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel
Class ResourceSpreader

java.lang.Object
  extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceSpreader
Direct Known Subclasses:
MaxMinFairSpreader

public abstract class ResourceSpreader
extends Object

This class is part of the unified resource consumption model of DISSECT-CF. This class provides a foundation for ensuring equal access to resource limited devices (such as network interfaces, cpus or disks) for all ongoing resource consumptions. Resource processing is actually handled by the processSingleConsumption function which must be implemented externally for performance. This allows the resource consumption simulation code to run with less conditional statements in its core. While it also allows to efficiently add new features later on.

Author:
"Gabor Kecskemeti, Distributed and Parallel Systems Group, University of Innsbruck (c) 2013" "Gabor Kecskemeti, Laboratory of Parallel and Distributed Systems, MTA SZTAKI (c) 2012"

Nested Class Summary
static class ResourceSpreader.FreqSyncer
          This class is the core part of the unified resource consumption model of DISSECT-CF.
 
Field Summary
private  PowerState currentPowerBehavior
          The power behavior that currently models the resource spreader's energy characteristics.
(package private) static int hashCounter
          A continuously increasing simple hash value to be used by the next resource spreader object created
protected  long lastNotifTime
          The last time there were some processing operations done by this object.
private  int myHashCode
          The hashcode of the actual resource spreader to be used in java's built in hashCode function
private  ResourceSpreader.FreqSyncer mySyncer
          The influence group in which this resource spreader belongs.
protected  double negligableProcessing
          For floating point operations using the perTickProcessingPower this defines the precision, ie.
protected  double perTickProcessingPower
          Maximum amount of resources to be shared among the consumption objects during a single tick.
private  StateDependentEventHandler<PowerBehaviorChangeListener,org.apache.commons.lang3.tuple.Pair<ResourceSpreader,PowerState>> powerBehaviorListenerManager
          This is the notification handler object that belongs to this particular resource spreader.
private  boolean stillInDepGroup
          A helper field that allows the rapid discovery of influence groups by the group's freq syncer object
 List<ResourceConsumption> toBeAdded
          Public, unmodifiable list of just deregistered resource consumptions
 List<ResourceConsumption> toBeRemoved
          Public, unmodifiable list of just registered resource consumptions
private  ArrayList<ResourceConsumption> toProcess
          The array of consumption objects that will share the processing power of this spreader.
private  double totalProcessed
          Shows how much processing this spreader done in its lifetime.
private  ArrayList<ResourceConsumption> underAddition
          The resource consumptions that got registered to this spreader in the last tick
 List<ResourceConsumption> underProcessing
          The unalterable array of resource consumption objects.
(package private)  int underProcessingLen
          the length of the list of toProcess.
private  ArrayList<ResourceConsumption> underRemoval
          The resource consumptions that got deregistered from this spreader in the last tick
 
Constructor Summary
ResourceSpreader(double initialProcessingPower)
          This constructor just saves the processing power that can be spread in every tick by the newly instantiated spreader.
 
Method Summary
(package private) static void cancelConsumption(ResourceConsumption con)
          Organizes the coordinated removal of this consumption from the underProcessing list.
private  void doProcessing(long currentFireCount)
          The main resource processing loop.
protected abstract  ResourceSpreader getCounterPart(ResourceConsumption con)
          If it is unknown whether we are a provider or a consumer (this is usually the case in the generic resource spreader class or anyone outsed the actual provider/consumer implementations) then it is useful to figure out the counter part who also participates in the same resource consumption processing operation.
 PowerState getCurrentPowerBehavior()
          Queries the current power behavior object
(package private) static int getHashandIncCounter()
          Manages the increment of the hashCounter and offers the latest hash code for new objects WARNING: as this function does not check if a hash value is already given or not there might be hash collisions if there are so many resource spreaders created that the hashcounter overflows.
 double getPerTickProcessingPower()
          Determines the current processing power of this resource spreader
protected abstract  ResourceSpreader getSamePart(ResourceConsumption con)
          The function gets that particular resource spreader from the given resource consumption object that is the same kind (i.e., provider/consumer) as the resource spreader that calls for this function.
 ResourceSpreader.FreqSyncer getSyncer()
          Determines the influence group this resource spreader is participating in.
 double getTotalProcessed()
          Returns the total amount of resources processed (i.e., via all past and present resource consumption objects) by this resource spreader object at the time instance this call is made.
 int hashCode()
          Returns the constant hashcode that was generated for this object during its instantiation.
protected  boolean isAcceptableConsumption(ResourceConsumption con)
          Allows the rejection of the registration of some resource consumptions.
protected abstract  boolean isConsumer()
          Determines if a particular resource spreader is acting as a consumer or not.
protected abstract  double processSingleConsumption(ResourceConsumption con, long ticksPassed)
          This function is expected to realign the underProcessing and toBeProcessed fields of the ResourceConsumption object it receives.
(package private) static boolean registerConsumption(ResourceConsumption con)
          When a new consumption is initiated it must be registered to the corresponding spreader with this function.
protected  void removeTheseConsumptions(ResourceConsumption[] conList, int len)
          Allows the management of the underRemoval list.
 void setCurrentPowerBehavior(PowerState newPowerBehavior)
          Allows to change the power behavior of the resource spreader.
protected  void setPerTickProcessingPower(double perTickProcessingPower)
          Allows to set the current processing power of this resource spreader WARNING: this is not intended to be used for altering the performance of the spreader while it participates in resource consumption processing
protected abstract  long singleGroupwiseFreqUpdater()
          The entry to the lowest level schedulers in DISSECT-CF.
 void subscribePowerBehaviorChangeEvents(PowerBehaviorChangeListener pbcl)
          allows interested parties to receive power behavior change events by subscribing with a listener object.
 String toString()
          Provides a nice formatted single line representation of the spreader.
 void unsubscribePowerBehaviorChangeEvents(PowerBehaviorChangeListener pbcl)
          allows parties that got uninterested to cancel the reception of new power behavior change events by unsubscribing with a listener object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

perTickProcessingPower

protected double perTickProcessingPower
Maximum amount of resources to be shared among the consumption objects during a single tick.


negligableProcessing

protected double negligableProcessing
For floating point operations using the perTickProcessingPower this defines the precision, ie. the amount of processing to be considered 0. It is defined to be 1 billionth of the perTickProcessingPower.


toProcess

private final ArrayList<ResourceConsumption> toProcess
The array of consumption objects that will share the processing power of this spreader. The order is not guaranteed!


underProcessing

public final List<ResourceConsumption> underProcessing
The unalterable array of resource consumption objects.


underProcessingLen

int underProcessingLen
the length of the list of toProcess. This is updated for performance reasons.


mySyncer

private ResourceSpreader.FreqSyncer mySyncer
The influence group in which this resource spreader belongs.


underAddition

private ArrayList<ResourceConsumption> underAddition
The resource consumptions that got registered to this spreader in the last tick


underRemoval

private ArrayList<ResourceConsumption> underRemoval
The resource consumptions that got deregistered from this spreader in the last tick


toBeRemoved

public final List<ResourceConsumption> toBeRemoved
Public, unmodifiable list of just registered resource consumptions


toBeAdded

public final List<ResourceConsumption> toBeAdded
Public, unmodifiable list of just deregistered resource consumptions


currentPowerBehavior

private PowerState currentPowerBehavior
The power behavior that currently models the resource spreader's energy characteristics.


powerBehaviorListenerManager

private final StateDependentEventHandler<PowerBehaviorChangeListener,org.apache.commons.lang3.tuple.Pair<ResourceSpreader,PowerState>> powerBehaviorListenerManager
This is the notification handler object that belongs to this particular resource spreader. Resource spreaders use this object to handle power state related events.


lastNotifTime

protected long lastNotifTime
The last time there were some processing operations done by this object. The notification time is used to stop infinite loops in the doProcessing function.


totalProcessed

private double totalProcessed
Shows how much processing this spreader done in its lifetime.


stillInDepGroup

private boolean stillInDepGroup
A helper field that allows the rapid discovery of influence groups by the group's freq syncer object


hashCounter

static int hashCounter
A continuously increasing simple hash value to be used by the next resource spreader object created


myHashCode

private final int myHashCode
The hashcode of the actual resource spreader to be used in java's built in hashCode function

Constructor Detail

ResourceSpreader

public ResourceSpreader(double initialProcessingPower)
This constructor just saves the processing power that can be spread in every tick by the newly instantiated spreader.

Parameters:
initialProcessingPower - Maximum usable bandwidth in a during a single timing event
Method Detail

getSyncer

public final ResourceSpreader.FreqSyncer getSyncer()
Determines the influence group this resource spreader is participating in. If null, then this spreader is not having any resource consumptions registered.

Returns:
the object representing this spreader's influence group.

singleGroupwiseFreqUpdater

protected abstract long singleGroupwiseFreqUpdater()
The entry to the lowest level schedulers in DISSECT-CF. This function is expected to calculate for each resource consumption of this spreader the amount of resource share it could receive.

Returns:
the duration (in ticks) one has to wait before any of the resource consumptions in this spreader complete

removeTheseConsumptions

protected final void removeTheseConsumptions(ResourceConsumption[] conList,
                                             int len)
Allows the management of the underRemoval list. When some objects are removed the influence groups are reevaluated.

Parameters:
conList - the resource consumptions that must be dropped (either because they complete or because they are cancelled)
len - the number of items in the consumption list.

registerConsumption

static boolean registerConsumption(ResourceConsumption con)
When a new consumption is initiated it must be registered to the corresponding spreader with this function. The consumption object is added to the array of current consumptions. This function also makes sure that the timing events arrive if this is the first object in the array. WARNING: This function should not be called by anyone else but the registration function of the resource consumption! (Otherwise duplicate registrations could happen!)

Parameters:
con - The consumption object to be registered
Returns:
  • true if the registration was successful
  • false if the consumption was already registered or if the consumption is not acceptable by its set provider or consumer.

isAcceptableConsumption

protected boolean isAcceptableConsumption(ResourceConsumption con)
Allows the rejection of the registration of some resource consumptions. By default this function this function only checks whether the registration is actually happening for the resource spreader that the consumption refers to. Also the default function stops registrations if the processing power of this spreader is 0. NOTE: by further implementing this function one can block registrations in even more cases (e.g. no registration of CPU utilization is possible for DESTROYED virtual machines). WARNING: when overriding this method, always combine the original's decision

Parameters:
con - the consumption that is asked to be registered
Returns:
true if the consumption can be registered in this spreader's underprocessing list

cancelConsumption

static void cancelConsumption(ResourceConsumption con)
Organizes the coordinated removal of this consumption from the underProcessing list.

Parameters:
con - the consumption to be removed from its processing consumer/provider pair.

doProcessing

private void doProcessing(long currentFireCount)
The main resource processing loop. This loop is responsible for actually offering resources to consumers in case of providers or in case of consumers it is responsible to actually utilize the offered resources. The loop does not make decisions on how much resources to use/offer for a particular resource consumption, it is assumed that by the time this function is called all resource consumption objects are allocated their share of the complete available resource set. The loop also uses the lastNotiftime field to determine how much time passed since it last shared the resources to all its consumption objects.

Parameters:
currentFireCount - the time at which this processing task must take place.

processSingleConsumption

protected abstract double processSingleConsumption(ResourceConsumption con,
                                                   long ticksPassed)
This function is expected to realign the underProcessing and toBeProcessed fields of the ResourceConsumption object it receives. It is expected to do the realignment depending on whether this resource spreader is a consumer or a provider. All subclasses that embody consumer/provider roles must implement this method so the doProcessing function above could uniformly process all resource consumptions independently from being a provider/consumer.

Parameters:
con - the resource consumption to be realigned
ticksPassed - the time passed since the last processing request
Returns:
Its absolute value represents the amount of actually processed resources. If negative then the 'con' has completed its processing.

getCounterPart

protected abstract ResourceSpreader getCounterPart(ResourceConsumption con)
If it is unknown whether we are a provider or a consumer (this is usually the case in the generic resource spreader class or anyone outsed the actual provider/consumer implementations) then it is useful to figure out the counter part who also participates in the same resource consumption processing operation.

Parameters:
con - The consumption object for which we would like to know the other party that participates in the processing with us.
Returns:
the other resource spreader that does the processing with us

getSamePart

protected abstract ResourceSpreader getSamePart(ResourceConsumption con)
The function gets that particular resource spreader from the given resource consumption object that is the same kind (i.e., provider/consumer) as the resource spreader that calls for this function. This function is useful to collect the same kind of resource spreaders identified through a set of resource consumption objects. Or just to know if a particular resource spreader is the one that is set in the expected role in a resource consumption object (e.g., am I really registered as a consumer as I expected?).

Parameters:
con - The consumption object on which this call will operate
Returns:
the resource spreader set to be in the same role (provider/consumer) as this resource spreader object (i.e., the spreader on which the function was calleD)

isConsumer

protected abstract boolean isConsumer()
Determines if a particular resource spreader is acting as a consumer or not.

Returns:
true if this resource spreader is a consumer, false otherwise

getTotalProcessed

public double getTotalProcessed()
Returns the total amount of resources processed (i.e., via all past and present resource consumption objects) by this resource spreader object at the time instance this call is made. WARNING: this operation could be rather expensive to call as it first has to ensure all consumption processing is done before the query to the totalProcessed field can be actually accomplished.

Returns:
the amount of processing done so far. The unit of the processed value is application specific here it is not relevant. For example if this function is used on a PhysicalMachine then it will report the amount of instructions executed so far by the PM.

getPerTickProcessingPower

public double getPerTickProcessingPower()
Determines the current processing power of this resource spreader

Returns:
the processing power of this resource spreader. The returned value has no unit, the unit depends on the user of the spreader (e.g. in networking it could be bytes/tick)

setPerTickProcessingPower

protected void setPerTickProcessingPower(double perTickProcessingPower)
Allows to set the current processing power of this resource spreader WARNING: this is not intended to be used for altering the performance of the spreader while it participates in resource consumption processing

Parameters:
perTickProcessingPower - the new processing power of this resource spreader. The new value has no unit, the unit depends on the user of the spreader (e.g. in networking it could be bytes/tick)

getCurrentPowerBehavior

public PowerState getCurrentPowerBehavior()
Queries the current power behavior object

Returns:
the current power behavior

setCurrentPowerBehavior

public void setCurrentPowerBehavior(PowerState newPowerBehavior)
Allows to change the power behavior of the resource spreader. Once the change is done it notifies the listeners interested in power behavior changes.

Parameters:
newPowerBehavior - the new power behavior to be set. Null values are not allowed!

subscribePowerBehaviorChangeEvents

public void subscribePowerBehaviorChangeEvents(PowerBehaviorChangeListener pbcl)
allows interested parties to receive power behavior change events by subscribing with a listener object. Note: Internally the state dependent event handling framework is used for this operation.

Parameters:
pbcl - the new listener object

unsubscribePowerBehaviorChangeEvents

public void unsubscribePowerBehaviorChangeEvents(PowerBehaviorChangeListener pbcl)
allows parties that got uninterested to cancel the reception of new power behavior change events by unsubscribing with a listener object. Note: Internally the state dependent event handling framework is used for this operation.

Parameters:
pbcl - the old listener object

toString

public String toString()
Provides a nice formatted single line representation of the spreader. It lists the currently processed resource consumptions and the power behavior as well. Useful for debugging and tracing purposes.

Overrides:
toString in class Object

getHashandIncCounter

static int getHashandIncCounter()
Manages the increment of the hashCounter and offers the latest hash code for new objects WARNING: as this function does not check if a hash value is already given or not there might be hash collisions if there are so many resource spreaders created that the hashcounter overflows.

Returns:
the hash code to be used by the newest object

hashCode

public final int hashCode()
Returns the constant hashcode that was generated for this object during its instantiation.

Overrides:
hashCode in class Object


Copyright © 2012–2015 University of Innsbruck & MTA SZTAKI. All rights reserved.