use of es.bsc.compss.types.resources.description.CloudMethodResourceDescription 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.CloudMethodResourceDescription 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.CloudMethodResourceDescription 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.CloudMethodResourceDescription in project compss by bsc-wdc.
the class ResourceOptimizer method reassignUnassignedConstraints.
private static void reassignUnassignedConstraints(Map<String, List<ConstraintsCore>> arch2Ctrs) {
/*
* ATTENTION: Since this method is only evaluated from constraints, there is only 1 PROCESSOR and 1 ARCHITECTURE
*/
List<ConstraintsCore> unassignedList = arch2Ctrs.get(CloudMethodResourceDescription.UNASSIGNED_STR);
if (unassignedList == null) {
return;
}
if (arch2Ctrs.size() == 1) {
return;
}
if (arch2Ctrs.size() == 2) {
for (Entry<String, List<ConstraintsCore>> ctrs : arch2Ctrs.entrySet()) {
if (ctrs.getKey().compareTo(CloudMethodResourceDescription.UNASSIGNED_STR) == 0) {
continue;
} else {
ctrs.getValue().addAll(unassignedList);
return;
}
}
}
List<ConstraintsCore> assignedList = new LinkedList<>();
for (Entry<String, List<ConstraintsCore>> ctrs : arch2Ctrs.entrySet()) {
if (ctrs.getKey().compareTo(CloudMethodResourceDescription.UNASSIGNED_STR) == 0) {
continue;
} else {
assignedList.addAll(ctrs.getValue());
}
}
while (!unassignedList.isEmpty()) {
ConstraintsCore unassigned = unassignedList.remove(0);
CloudMethodResourceDescription candidate = unassigned.desc;
String bestArch = CloudMethodResourceDescription.UNASSIGNED_STR;
Float bestDifference = Float.MAX_VALUE;
for (ConstraintsCore assigned : assignedList) {
CloudMethodResourceDescription option = assigned.desc;
float difference = candidate.difference(option);
if (bestDifference < 0) {
if (difference < 0) {
if (difference > bestDifference) {
List<String> avail_archs = option.getArchitectures();
if (avail_archs != null && !avail_archs.isEmpty()) {
bestArch = avail_archs.get(0);
}
bestDifference = difference;
}
}
} else if (difference < bestDifference) {
List<String> avail_archs = option.getArchitectures();
if (avail_archs != null && !avail_archs.isEmpty()) {
bestArch = avail_archs.get(0);
}
bestDifference = difference;
}
}
// Add
List<Processor> procs = unassigned.desc.getProcessors();
if (procs == null) {
procs = new LinkedList<>();
}
if (!procs.isEmpty()) {
procs.get(0).setArchitecture(bestArch);
} else {
Processor p = new Processor();
p.setArchitecture(bestArch);
procs.add(p);
}
arch2Ctrs.get(bestArch).add(unassigned);
}
}
use of es.bsc.compss.types.resources.description.CloudMethodResourceDescription in project compss by bsc-wdc.
the class ResourceOptimizer method optionalReduction.
private boolean optionalReduction(float[] destroyRecommendations) {
List<CloudMethodWorker> nonCritical = trimReductionOptions(ResourceManager.getNonCriticalDynamicResources(), destroyRecommendations);
if (DEBUG) {
RUNTIME_LOGGER.debug("[Resource Optimizer] Searching for best destruction");
}
Object[] nonCriticalSolution = getBestDestruction(nonCritical, destroyRecommendations);
CloudMethodWorker res;
float[] record;
CloudInstanceTypeDescription rd;
if (nonCriticalSolution == null || nonCriticalSolution[0] == null || nonCriticalSolution[1] == null || nonCriticalSolution[2] == null) {
if (DEBUG) {
RUNTIME_LOGGER.warn("[Resource Optimizer] No solution found");
}
return false;
}
res = (CloudMethodWorker) nonCriticalSolution[0];
rd = (CloudInstanceTypeDescription) nonCriticalSolution[1];
record = (float[]) nonCriticalSolution[2];
if (DEBUG) {
RUNTIME_LOGGER.debug("[Resource Optimizer] Best resource to remove is " + res.getName() + "and record is [" + record[0] + "," + record[1] + "," + record[2]);
}
if (record[1] > 0 && res.getUsedCPUTaskCount() > 0) {
RUNTIME_LOGGER.debug("[Resource Optimizer] Optional destroy recommendation not applied");
return false;
} else {
RUNTIME_LOGGER.debug("[Resource Optimizer] Optional destroy recommendation applied");
CloudMethodResourceDescription finalDescription = new CloudMethodResourceDescription(rd, res.getDescription().getImage());
finalDescription.setName(res.getName());
ResourceManager.reduceCloudWorker(res, finalDescription);
return true;
}
}
Aggregations