use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class MOResourceOptimizer method getContext.
// Get estimated cost (energy, price, time) of the current scheduling
private <T extends WorkerResourceDescription> ConfigurationCost getContext(Resource<?>[] allResources, int[] load, Collection<ResourceScheduler<? extends WorkerResourceDescription>> workers, List<ResourceCreationRequest> creations, HashMap<CloudInstanceTypeDescription, Integer> pendingCreations, HashMap<CloudInstanceTypeDescription, Integer> pendingDestructions, double[] elapsedTime, double[] elapsedEnergy, double[] elapsedCost, double[] elapsedPower, double[] elapsedPrice) {
elapsedTime[0] = 0;
elapsedEnergy[0] = 0;
elapsedCost[0] = 0;
elapsedPower[0] = 0;
elapsedPrice[0] = 0;
double time = 0;
double actionsCost = 0;
double idlePrice = 0;
double actionsEnergy = 0;
double idlePower = 0;
int resourceId = 0;
for (ResourceScheduler<?> w : workers) {
MOResourceScheduler<T> aw = (MOResourceScheduler<T>) w;
Resource<T> r = new Resource<>(aw);
allResources[resourceId] = r;
addToLog("\tName:" + aw.getName() + (r.hasPendingModifications() ? " (IS TO BE DELETED)" : "") + "\n");
time = Math.max(time, aw.getLastGapExpectedStart());
addToLog("\t\tTime:" + aw.getLastGapExpectedStart() + " ms -> total " + time + "\n");
elapsedCost[0] += aw.getRunActionsCost();
addToLog("\t\tExecuted Actions Cost:" + aw.getRunActionsCost() + " €.ms/h -> total " + elapsedCost[0] + "€.ms/h\n");
actionsCost += aw.getScheduledActionsCost();
addToLog("\t\tScheduled Actions Cost:" + aw.getScheduledActionsCost() + " €.ms/h -> total " + actionsCost + "€.ms/h\n");
r.idlePrice = aw.getIdlePrice();
idlePrice += r.idlePrice;
addToLog("\t\tIdle Price:" + r.idlePrice + " €/h -> total " + idlePrice + "€/h\n");
elapsedEnergy[0] += aw.getRunActionsEnergy();
addToLog("\t\tExecuted Actions Energy:" + aw.getRunActionsEnergy() + " mJ -> total " + elapsedEnergy[0] + "mJ\n");
actionsEnergy += aw.getScheduledActionsEnergy();
addToLog("\t\tScheduled Actions Energy:" + aw.getScheduledActionsEnergy() + " mJ -> total " + actionsEnergy + "mJ\n");
r.idlePower = aw.getIdlePower();
idlePower += r.idlePower;
addToLog("\t\tIdle Power:" + r.idlePower + " W -> total " + idlePower + "W\n");
r.startTime = aw.getExpectedEndTimeRunning();
r.startCost = aw.getRunningActionsCost();
r.startEnergy = aw.getRunningActionsEnergy();
int[][] implsCount = aw.getImplementationCounts();
int[][] runningCounts = aw.getRunningImplementationCounts();
addToLog("\t\tCore Information:\n");
StringBuilder[] coreInfo = new StringBuilder[CoreManager.getCoreCount()];
Implementation[] impls = new Implementation[CoreManager.getCoreCount()];
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
coreInfo[coreId] = new StringBuilder("\t\t\tCore " + coreId + "\n");
int favId = 0;
int favCount = implsCount[coreId][0];
load[coreId] += implsCount[coreId][0] - runningCounts[coreId][0];
coreInfo[coreId].append("\t\t\t\tImplementation 0: " + implsCount[coreId][0] + ", " + runningCounts[coreId][0] + " of'em already running\n");
for (int implId = 1; implId < CoreManager.getCoreImplementations(coreId).size(); implId++) {
coreInfo[coreId].append("\t\t\t\tImplementation " + implId + ": " + implsCount[coreId][implId] + ", " + runningCounts[coreId][implId] + " of'em already running\n");
load[coreId] += implsCount[coreId][implId] - runningCounts[coreId][implId];
if (implsCount[coreId][implId] > favCount) {
favId = implId;
}
}
if (favCount > 0) {
impls[coreId] = CoreManager.getCoreImplementations(coreId).get(favId);
} else {
List<Implementation> coreImpls = CoreManager.getCoreImplementations(coreId);
MOProfile[] profiles = new MOProfile[coreImpls.size()];
for (int i = 0; i < profiles.length; i++) {
profiles[i] = (MOProfile) aw.getProfile(coreImpls.get(i));
}
impls[coreId] = getBestImplementation(coreImpls, profiles);
}
coreInfo[coreId].append("\t\t\t\tFavorite Implementation " + favId + "\n");
}
r.profiles = new MOProfile[implsCount.length];
r.capacity = new int[implsCount.length];
for (int coreId = 0; coreId < implsCount.length; coreId++) {
r.profiles[coreId] = (MOProfile) aw.getProfile(impls[coreId]);
coreInfo[coreId].append("\t\t\t\tProfile " + r.profiles[coreId] + "\n");
r.capacity[coreId] = aw.getSimultaneousCapacity(impls[coreId]);
coreInfo[coreId].append("\t\t\t\tCapacity " + r.capacity[coreId] + "\n");
addToLog(coreInfo[coreId].toString());
}
if (r.hasPendingModifications()) {
for (ResourceUpdate<T> ru : r.getPendingModifications()) {
Map<CloudInstanceTypeDescription, int[]> modificationComposition = ((CloudMethodResourceDescription) ru.getModification()).getTypeComposition();
for (Map.Entry<CloudInstanceTypeDescription, int[]> entry : modificationComposition.entrySet()) {
CloudInstanceTypeDescription componentType = entry.getKey();
int count = entry.getValue()[0];
Integer pendingDestruction = pendingDestructions.get(componentType);
if (pendingDestruction == null) {
pendingDestruction = 0;
}
pendingDestruction += count;
pendingDestructions.put(componentType, pendingDestruction);
}
}
}
resourceId++;
}
// Convert time to secs
elapsedTime[0] = (double) (System.currentTimeMillis() - initialTimeStamp) / 1000;
// Convert energy from mJ to Wh
elapsedEnergy[0] = elapsedEnergy[0] / 3_600_000;
// Convert energy from €ms/h to €
elapsedCost[0] = elapsedCost[0] / 3_600_000;
for (ResourceCreationRequest rcr : creations) {
for (Map.Entry<CloudInstanceTypeDescription, int[]> entry : rcr.getRequested().getTypeComposition().entrySet()) {
CloudInstanceTypeDescription componentType = entry.getKey();
int count = entry.getValue()[0];
addToLog("\tName: REQUESTED " + componentType.getName() + "\n");
Integer pendingCreation = pendingCreations.get(componentType);
if (pendingCreation == null) {
pendingCreation = 0;
}
pendingCreation += count;
pendingCreations.put(componentType, pendingCreation);
}
Resource<?> r = createResourceForCreationRequest(rcr);
allResources[resourceId] = r;
addToLog("\t\tTime: 0 ms -> total " + time + "\n");
addToLog("\t\tactions Cost: 0 € -> total " + actionsCost + "€\n");
idlePrice += r.idlePrice;
addToLog("\t\tIdle Price:" + r.idlePrice + " € -> total " + idlePrice + "€\n");
addToLog("\t\tactions Energy:0 mJ -> total " + actionsEnergy + "mJ\n");
idlePower += r.idlePower;
addToLog("\t\tIdle Power:" + r.idlePower + " W -> total " + idlePower + "W\n");
// r.startTime = 0;
r.startCost = 0;
r.startEnergy = 0;
addToLog("\t\tCore Information:\n");
StringBuilder[] coreInfo = new StringBuilder[CoreManager.getCoreCount()];
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
coreInfo[coreId] = new StringBuilder("\t\t\tCore " + coreId + "\n");
load[coreId] += 0;
coreInfo[coreId].append("\t\t\t\tImplementation 0: 0, 0 of'em already running\n");
for (int implId = 1; implId < CoreManager.getCoreImplementations(coreId).size(); implId++) {
coreInfo[coreId].append("\t\t\t\tImplementation " + implId + ": 0, 0 of'em already running\n");
}
coreInfo[coreId].append("\t\t\t\tFavorite Implementation 0\n");
}
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
coreInfo[coreId].append("\t\t\t\tProfile " + r.profiles[coreId] + "\n");
coreInfo[coreId].append("\t\t\t\tCapacity " + r.capacity[coreId] + "\n");
addToLog(coreInfo[coreId].toString());
}
resourceId++;
}
return new ConfigurationCost(time, idlePower, actionsEnergy, idlePrice, actionsCost);
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class MOResourceOptimizer method createResourceForCreationRequest.
private Resource<?> createResourceForCreationRequest(ResourceCreationRequest rcr) {
CloudMethodResourceDescription cmrd = rcr.getRequested();
Resource<?> r = new Resource<>(null);
Map<CloudInstanceTypeDescription, int[]> composition = cmrd.getTypeComposition();
r.capacity = new int[CoreManager.getCoreCount()];
r.profiles = new MOProfile[CoreManager.getCoreCount()];
for (Map.Entry<CloudInstanceTypeDescription, int[]> component : composition.entrySet()) {
CloudInstanceTypeDescription type = component.getKey();
int count = component.getValue()[0];
MethodResourceDescription rd = type.getResourceDescription();
MOCloudTypeProfile moCloudTypeProf = (MOCloudTypeProfile) getCloudTypeProfile(type);
r.idlePower += moCloudTypeProf.getIdlePower() * count;
r.idlePrice += moCloudTypeProf.getIdlePrice() * count;
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
List<Implementation> impls = CoreManager.getCoreImplementations(coreId);
MOProfile[] profiles = new MOProfile[impls.size()];
for (int i = 0; i < impls.size(); i++) {
profiles[i] = (MOProfile) moCloudTypeProf.getImplProfiles(coreId, impls.get(i).getImplementationId());
}
Implementation impl = getBestImplementation(impls, profiles);
r.capacity[coreId] += rd.canHostSimultaneously((MethodResourceDescription) impl.getRequirements()) * count;
MOProfile bestImplProf = (MOProfile) moCloudTypeProf.getImplProfiles(coreId, impl.getImplementationId());
if (r.profiles[coreId] == null) {
r.profiles[coreId] = bestImplProf;
} else {
r.profiles[coreId].accumulate(bestImplProf);
}
}
}
r.startTime = (cmrd.getImage().getCreationTime() * 1000) - (System.currentTimeMillis() - rcr.getRequestedTime());
if (r.startTime < 0) {
r.startTime = 0;
}
r.clear();
return r;
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceOptimizer method getBestIncreaseOnProvider.
public static CloudMethodResourceDescription getBestIncreaseOnProvider(CloudProvider cp, Integer amount, MethodResourceDescription requirements, boolean contained) {
RUNTIME_LOGGER.debug("[Resource Optimizer] Getting best increase in provider " + cp.getName());
// Check Cloud capabilities
if (!cp.canHostMoreInstances()) {
RUNTIME_LOGGER.warn(WARN_NO_MORE_INSTANCES);
return null;
}
// Select all the compatible types
List<CloudInstanceTypeDescription> instances = cp.getCompatibleTypes(requirements);
RUNTIME_LOGGER.debug("[Resource Optimizer] There are " + instances.size() + " instances compatible.");
if (instances.isEmpty()) {
RUNTIME_LOGGER.warn(WARN_NO_COMPATIBLE_TYPE);
return null;
}
CloudMethodResourceDescription result = null;
CloudInstanceTypeDescription type = null;
if (contained) {
type = selectContainedInstance(instances, requirements, amount);
} else {
type = selectContainingInstance(instances, requirements, amount);
}
// Pick an image to be loaded in the Type (or return null)
if (type != null) {
// Select all the compatible images
List<CloudImageDescription> images = cp.getCompatibleImages(requirements);
RUNTIME_LOGGER.debug("[Resource Optimizer] There are " + images.size() + " images compatible.");
if (!images.isEmpty()) {
CloudImageDescription image = images.get(0);
result = new CloudMethodResourceDescription(type, image);
result.setValue(cp.getInstanceCostPerHour(result));
} else {
RUNTIME_LOGGER.warn(WARN_NO_COMPATIBLE_IMAGE);
}
} else {
RUNTIME_LOGGER.warn(WARN_NO_VALID_INSTANCE);
}
return result;
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceOptimizer method selectContainingInstance.
private static CloudInstanceTypeDescription selectContainingInstance(List<CloudInstanceTypeDescription> instances, MethodResourceDescription constraints, int amount) {
CloudInstanceTypeDescription result = null;
MethodResourceDescription bestDescription = null;
float bestDistance = Integer.MIN_VALUE;
for (CloudInstanceTypeDescription type : instances) {
MethodResourceDescription rd = type.getResourceDescription();
int slots = rd.canHostSimultaneously(constraints);
float distance = slots - amount;
RUNTIME_LOGGER.debug("[Resource Optimizer] Can host: slots = " + slots + " amount = " + amount + " distance = " + distance + " bestDistance = " + bestDistance);
if (distance > 0.0) {
continue;
}
if (distance > bestDistance) {
result = type;
bestDescription = type.getResourceDescription();
bestDistance = distance;
} else if (distance == bestDistance && bestDescription != null) {
if (bestDescription.getValue() != null && rd.getValue() != null && bestDescription.getValue() > rd.getValue()) {
// Evaluate optimal candidate
result = type;
bestDescription = type.getResourceDescription();
bestDistance = distance;
}
}
}
if (result == null) {
return null;
}
return result;
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceOptimizer method getPossibleReductions.
// Type -> [# modified CE that weren't requested,
// #slots removed that weren't requested,
// #slots removed that were requested]
private Map<CloudInstanceTypeDescription, float[]> getPossibleReductions(CloudMethodWorker res, float[] recommendedSlots) {
Map<CloudInstanceTypeDescription, float[]> reductions = new HashMap<>();
List<CloudInstanceTypeDescription> types = res.getDescription().getPossibleReductions();
for (CloudInstanceTypeDescription type : types) {
int[] reducedSlots = type.getSlotsCore();
float[] values = new float[3];
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
if (res.canRun(coreId)) {
if (recommendedSlots[coreId] < 1 && reducedSlots[coreId] > 0) {
// Adding a desired CE whose slots will be
values[0]++;
// destroyed
// all reduced slots
values[1] += reducedSlots[coreId];
// weren't requested
} else {
float dif = (float) reducedSlots[coreId] - recommendedSlots[coreId];
if (dif < 0) {
values[2] += reducedSlots[coreId];
} else {
values[2] += recommendedSlots[coreId];
values[1] += dif;
}
}
}
}
reductions.put(type, values);
}
return reductions;
}
Aggregations