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

java.lang.Object
  extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceConsumption
Direct Known Subclasses:
NetworkNode.SingleTransfer

public class ResourceConsumption
extends Object

This class is part of the unified resource consumption model of DISSECT-CF. The instances of this class represent an individual resource consumption in the system. The visibility of the class and its members are defined so the compiler does not need to generate access methods for the members thus allowing fast and prompt changes in its contents. Upon setting up the consumption, every instance is registered at the provider and the consumer resource spreaders. Once the consumption is completed these registrations should be dropped. WARNING this is an internal representation of the consumption. This class is not supposed to be used outside of the context of the Unified resource consumption model of DISSECT-CF. Instead one should use: VirtualMachine.newComputeTask(), NetworkNode.initTransfer() and similar functions.

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

Nested Class Summary
static interface ResourceConsumption.ConsumptionEvent
          This interface allows its implementors to get notified when a consumption completes.
 
Field Summary
private  long completionDistance
          The number of ticks it is expected to take that renders both underProcessing and toBeProcessed as 0 (i.e., the time when the initially specified amount of resources are completely utilized).
private  ResourceSpreader consumer
          The consumer which receives the resources of this consumption.
(package private)  double consumerLimit
          the processing limit imposed because of the consumer WARNING: this is necessary for the internal behavior of MaxMinFairSpreader
(package private)  ResourceConsumption.ConsumptionEvent ev
          The event to be fired when there is nothing left to process in this consumption.
private  double halfRealLimit
          1/2*realLimit
private  double hardLimit
          the minimum of the perTickProcessing power of the provider/consumer
(package private)  boolean inassginmentprocess
          A helper field to show if the consumer/providerLimit fields are under update by MaxMinFairSpreader.assignProcessingPower() WARNING: this is necessary for the internal behavior of MaxMinFairSpreader
static Comparator<ResourceConsumption> limitComparator
          This comparator class provides a simple comparison tool for two resource consumptions based on their real limits.
(package private)  double limithelper
          the amount of processing that can be surely done by both the provider and the consumer.
private  double processingLimit
          the maximum amount of processing that could be sent from toBeProcessed to underProcessing in a tick
private  ResourceSpreader provider
          The provider which offers the resources for this consumption.
(package private)  double providerLimit
          The processing limit imposed because of the provider WARNING: this is necessary for the internal behavior of MaxMinFairSpreader
private  double realLimit
          The processing limit at the particular moment of time (this is set by the scheduler) This limit is derived from the provider/consumerLimits.
private  boolean registered
          shows if the consumption object actually participates in the resource sharing machanism.
private  double requestedLimit
          the user requested processing limit
private  boolean resumable
          shows if the consumption was suspended (true) or not.
private  double toBeProcessed
          The remaining unprocessed entities (e.g., remaining bytes of a transfer) NOTE: as this consumption is generic, it is actually the provider/consumer pair that determines what is the unit of this field
(package private)  boolean unassigned
          A helper field to show if the particular resource consumption still participates in the scheduling process or if it has already finalized its realLimit value.
private  double underProcessing
          The currently processing entities (e.g., a network buffer) NOTE: as this consumption is generic, it is actually the provider/consumer pair that determines what is the unit of this field
static double unlimitedProcessing
          If a resource consumption is not supposed to be limited by anything but the actual resource providers/consumers then this limit could be used in its constructor.
 
Constructor Summary
ResourceConsumption(double total, double limit, ResourceSpreader consumer, ResourceSpreader provider, ResourceConsumption.ConsumptionEvent e)
          This constructor describes the basic properties of an individual resource consumption.
 
Method Summary
private  void calcCompletionDistance()
          Updates the completion distance field, should be called every time the real limit is updated or when the amount of unprocessed consumption changes.
 void cancel()
          terminates the consumption, deregisters it from its consumer/provider pair and ensures that it can no longer be registered
(package private)  double doConsumerProcessing(long ticksPassed)
          This function simulates how the consumer utilizes the resources from its provider.
(package private)  double doProviderProcessing(long ticksPassed)
          This function simulates how the provider offers the resources for its consumer.
 long getCompletionDistance()
          Retrieves the number of ticks it is expected to take that renders both underProcessing and toBeProcessed as 0 (i.e., the time when the initially specified amount of resources are completely utilized).
 ResourceSpreader getConsumer()
          Queries the consumer associated with this resource consumption.
 double getHardLimit()
          Determines the hard processing limit for this resource consumption.
 double getProcessingLimit()
          Retrieves the maximum amount of processing that could be sent from toBeProcessed to underProcessing in a single tick
 ResourceSpreader getProvider()
          Queries the provider associated with this resource consumption.
 double getRealLimit()
          Retrieves the processing limit at the particular moment of time (just queries the value last set by the scheduler)
 double getToBeProcessed()
          Determines the amount of processing for which no resources were offered from the provider so far.
 double getUnderProcessing()
          Determines the amount of resoruces already offered by the provider but not yet used by the consumer.
 double getUnProcessed()
          Returns the amount of processing still remaining in this resource consumption.
 boolean isRegistered()
          Determines if the object is registered and resources are used because of this consumption object
 boolean isResumable()
          Allows to query whether this resource consumption was cancelled or not
 boolean registerConsumption()
          Initiates the processing of a resource consumption.
 void setConsumer(ResourceSpreader consumer)
          Allows to set a consumer for the consumption if the consumption is not yet under way.
 void setProvider(ResourceSpreader provider)
          Allows to set a provider for the consumption if the consumption is not yet under way.
private  void setRealLimit(double rL)
          Simultaneously updates the real limit (the instantaneous processing limit determined by the low level scheduler of the unified resoruce sharing model of DISSECT-CF) value as well as the halfreallimit field.
 void suspend()
          Terminates the consumption but ensures that it will be resumable later on.
 String toString()
          Provides a nice formatted output of the resource consumption showing how much processing is under way, how much is still held back and what is the current real limit set by the scheduler.
private  void updateHardLimit()
          Provides a unified update method for the hard processing limit (which will become the minimum of the provider's/consumer's per tick processing power) of this consumption.
(package private)  double updateRealLimit(boolean updateCD)
          Sets the real limit based on the scheduler set provider and consumer limits (the smaller is used as real).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

limitComparator

public static final Comparator<ResourceConsumption> limitComparator
This comparator class provides a simple comparison tool for two resource consumptions based on their real limits. Useful for sorting the consumptions.


unlimitedProcessing

public static final double unlimitedProcessing
If a resource consumption is not supposed to be limited by anything but the actual resource providers/consumers then this limit could be used in its constructor.

See Also:
Constant Field Values

underProcessing

private double underProcessing
The currently processing entities (e.g., a network buffer) NOTE: as this consumption is generic, it is actually the provider/consumer pair that determines what is the unit of this field


toBeProcessed

private double toBeProcessed
The remaining unprocessed entities (e.g., remaining bytes of a transfer) NOTE: as this consumption is generic, it is actually the provider/consumer pair that determines what is the unit of this field


processingLimit

private double processingLimit
the maximum amount of processing that could be sent from toBeProcessed to underProcessing in a tick


requestedLimit

private double requestedLimit
the user requested processing limit


hardLimit

private double hardLimit
the minimum of the perTickProcessing power of the provider/consumer


realLimit

private double realLimit
The processing limit at the particular moment of time (this is set by the scheduler) This limit is derived from the provider/consumerLimits. WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


halfRealLimit

private double halfRealLimit
1/2*realLimit


completionDistance

private long completionDistance
The number of ticks it is expected to take that renders both underProcessing and toBeProcessed as 0 (i.e., the time when the initially specified amount of resources are completely utilized).


providerLimit

double providerLimit
The processing limit imposed because of the provider WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


consumerLimit

double consumerLimit
the processing limit imposed because of the consumer WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


limithelper

double limithelper
the amount of processing that can be surely done by both the provider and the consumer. This is a temporary variable used by the MaxMinFairSpreader to determine the provider/consumerLimits. WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


unassigned

boolean unassigned
A helper field to show if the particular resource consumption still participates in the scheduling process or if it has already finalized its realLimit value. WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


inassginmentprocess

boolean inassginmentprocess
A helper field to show if the consumer/providerLimit fields are under update by MaxMinFairSpreader.assignProcessingPower() WARNING: this is necessary for the internal behavior of MaxMinFairSpreader


ev

final ResourceConsumption.ConsumptionEvent ev
The event to be fired when there is nothing left to process in this consumption.


consumer

private ResourceSpreader consumer
The consumer which receives the resources of this consumption. If null, then the consumer must be set before proper operation of the consumption. As this can be null the resource consumption objects could be created in multiple phases allowing to first determine the amount of consumption to be made before actually assigning to a particular consumer.


provider

private ResourceSpreader provider
The provider which offers the resources for this consumption. If null, then the provider must be set before proper operation of the consumption. As this can be null the resource consumption objects could be created in multiple phases allowing to first determine the amount of consumption to be made before actually assigning to a particular provider.


resumable

private boolean resumable
shows if the consumption was suspended (true) or not.


registered

private boolean registered
shows if the consumption object actually participates in the resource sharing machanism.

Constructor Detail

ResourceConsumption

public ResourceConsumption(double total,
                           double limit,
                           ResourceSpreader consumer,
                           ResourceSpreader provider,
                           ResourceConsumption.ConsumptionEvent e)
This constructor describes the basic properties of an individual resource consumption.

Parameters:
total - The amount of processing to be done during the lifetime of the just created object
limit - the maximum amount of processing allowable for this particular resource consumption (this allows the specification of an upper limit of any consumption). If there is no upper limit needed then this value should be set with the value of the unlimitedProcessing field.
consumer - the consumer that will benefit from the resource consumption. This field could be null, then the consumer must be set with the setConsumer() function.
provider - the provider which will offer its resources for the consumer. This field could be null, then the provider must be set with the setProvider() function.
e - Specify here the event to be fired when the just created object completes its transfers. With this event it is possible to notify the entity who initiated the transfer. This event object cannot be null. If there is no special event handling is needed then just create a ConsumptionEventAdapter.
Method Detail

updateHardLimit

private void updateHardLimit()
Provides a unified update method for the hard processing limit (which will become the minimum of the provider's/consumer's per tick processing power) of this consumption. All values that depend on hard limit (the real and processing limits) are also updated. This function can be called even if the provider/consumer is not set yet in that case the processing limit for the non-set spreader will be unlimited.


registerConsumption

public boolean registerConsumption()
Initiates the processing of a resource consumption. By calling this function the resource consumption object will be participating in the unified resource sharing mechanism's scheduling and spreading operations. Before the registration actually happens, it updates the hard limit of the consumption so the spreaders could now operate using its values. NOTE: this function is also used for resuming a suspended consumption

Returns:
  • true if the registration was successful
  • false otherwise. For example: if the provider/consumer is not yet set, if the consumption cannot be registered between the particular provider/consumer pair or if the consumption was already registered.

getUnProcessed

public double getUnProcessed()
Returns the amount of processing still remaining in this resource consumption.

Returns:
the remaining processing

cancel

public void cancel()
terminates the consumption, deregisters it from its consumer/provider pair and ensures that it can no longer be registered


suspend

public void suspend()
Terminates the consumption but ensures that it will be resumable later on. If a consumption needs to be resumed then it must be re-registered, there is no special function for resume.


setProvider

public void setProvider(ResourceSpreader provider)
Allows to set a provider for the consumption if the consumption is not yet under way.

Parameters:
provider - the provider to be used for offering the resources for the consumption

setConsumer

public void setConsumer(ResourceSpreader consumer)
Allows to set a consumer for the consumption if the consumption is not yet under way.

Parameters:
consumer - the consumer to be used for utilizing the resources received through this resource consumption object.

calcCompletionDistance

private void calcCompletionDistance()
Updates the completion distance field, should be called every time the real limit is updated or when the amount of unprocessed consumption changes.


doProviderProcessing

double doProviderProcessing(long ticksPassed)
This function simulates how the provider offers the resources for its consumer. The offered resources are put in the underprocessing field from the toBeprocessed. If the processing is really close to completion (determined by using halfreallimit), then this function cheats a bit and offers the resources for the last remaining processable consumption. This is actually ensuring that we don't need to simulate sub-tick processing operations. WARNING: this is necessary for the internal behavior of MaxMinFairSpreader

Parameters:
ticksPassed - the number of ticks to be simulated (i.e. how many times we should multiply realLimit) before offering the resources to the underprocessing field.
Returns:
the amount of resources actually offered for consumption. Negative values mark the end of this resource consumption (i.e. when there is no more processing to be done for this consumption). Albeit such values are negative, their negativeness is just used as a flag and their absolute value still represent the amount of offered resources.

doConsumerProcessing

double doConsumerProcessing(long ticksPassed)
This function simulates how the consumer utilizes the resources from its provider. The utilized resources are used from the underprocessing field. If the processing is really close to completion (determined by calculating the completion distance), then this function cheats a bit and utilizes the resources for the last remaining underprocessing. This is actually ensuring that we don't need to simulate sub-tick processing operations. WARNING: this is necessary for the internal behavior of MaxMinFairSpreader

Parameters:
ticksPassed - the number of ticks to be simulated (i.e. how many times we should multiply realLimit) before utilizing the resources from the underprocessing field.
Returns:
the amount of resources actually utilized by the consumer. Negative values mark the end of this resource consumption (i.e. when there is no more processing to be done for this consumption). Albeit such values are negative, their negativeness is just used as a flag and their absolute value still represent the amount of utilized resources.

getToBeProcessed

public double getToBeProcessed()
Determines the amount of processing for which no resources were offered from the provider so far.

Returns:
the tobeprocessed value

getUnderProcessing

public double getUnderProcessing()
Determines the amount of resoruces already offered by the provider but not yet used by the consumer.

Returns:
the underprocessing value

getProcessingLimit

public double getProcessingLimit()
Retrieves the maximum amount of processing that could be sent from toBeProcessed to underProcessing in a single tick


getRealLimit

public double getRealLimit()
Retrieves the processing limit at the particular moment of time (just queries the value last set by the scheduler)


getCompletionDistance

public long getCompletionDistance()
Retrieves the number of ticks it is expected to take that renders both underProcessing and toBeProcessed as 0 (i.e., the time when the initially specified amount of resources are completely utilized). This is again just the value that is derived from the real limit last set by the scheduler.


getConsumer

public ResourceSpreader getConsumer()
Queries the consumer associated with this resource consumption.

Returns:
the consumer which will utilize the resources received through this consumption object

getProvider

public ResourceSpreader getProvider()
Queries the provider associated with this resource consumption.

Returns:
the provider which will offer the resources for this particular resource consumption object.

setRealLimit

private void setRealLimit(double rL)
Simultaneously updates the real limit (the instantaneous processing limit determined by the low level scheduler of the unified resoruce sharing model of DISSECT-CF) value as well as the halfreallimit field.

Parameters:
rL - the value to be set as real limit

updateRealLimit

double updateRealLimit(boolean updateCD)
Sets the real limit based on the scheduler set provider and consumer limits (the smaller is used as real). Updates the completion distance if instructed.

Parameters:
updateCD - true tells the system to update the completion distance alongside the real limit setup. This more frequent update on the real limit than the completion distance is calculated. IMPORTANT: if set to false then it is expected that the scheduler will call the updateRealLimit at least once more with a true parameter. Failing to do so the consumption object will become broken.
Returns:
the real limit that was actually determined and set by this function
Throws:
IllegalStateException - if the real limit would become 0

toString

public String toString()
Provides a nice formatted output of the resource consumption showing how much processing is under way, how much is still held back and what is the current real limit set by the scheduler. Intended for debugging and tracing outputs.

Overrides:
toString in class Object

isRegistered

public boolean isRegistered()
Determines if the object is registered and resources are used because of this consumption object

Returns:
true if the object is registered.

isResumable

public boolean isResumable()
Allows to query whether this resource consumption was cancelled or not

Returns:
false if the resource consumption was cancelled and it can no longer be registered within the unified resource sharing model of the simulator.

getHardLimit

public double getHardLimit()
Determines the hard processing limit for this resource consumption.

Returns:
the hard limit


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