Search in sources :

Example 1 with CloudMethodResourceDescription

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);
}
Also used : CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) Implementation(es.bsc.compss.types.implementations.Implementation) ResourceCreationRequest(es.bsc.compss.types.ResourceCreationRequest) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) HashMap(java.util.HashMap) Map(java.util.Map) MOProfile(es.bsc.compss.scheduler.multiobjective.types.MOProfile)

Example 2 with CloudMethodResourceDescription

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;
}
Also used : CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) Implementation(es.bsc.compss.types.implementations.Implementation) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) HashMap(java.util.HashMap) Map(java.util.Map) MOProfile(es.bsc.compss.scheduler.multiobjective.types.MOProfile)

Example 3 with CloudMethodResourceDescription

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;
}
Also used : CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription)

Example 4 with CloudMethodResourceDescription

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);
    }
}
Also used : Processor(es.bsc.compss.types.resources.components.Processor) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 5 with CloudMethodResourceDescription

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;
    }
}
Also used : CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) JSONObject(org.json.JSONObject)

Aggregations

CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)45 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)23 CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)21 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)16 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)12 FakeNode (es.bsc.compss.types.fake.FakeNode)11 CloudProvider (es.bsc.compss.types.CloudProvider)9 ResourceCreationRequest (es.bsc.compss.types.ResourceCreationRequest)7 Implementation (es.bsc.compss.types.implementations.Implementation)5 ConnectorException (es.bsc.compss.connectors.ConnectorException)4 ExtendedCloudMethodWorker (es.bsc.compss.types.ExtendedCloudMethodWorker)4 Map (java.util.Map)4 MOProfile (es.bsc.compss.scheduler.multiobjective.types.MOProfile)3 VM (es.bsc.compss.connectors.VM)2 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)2 PerformedIncrease (es.bsc.compss.types.resources.updates.PerformedIncrease)2 VirtualResource (es.bsc.conn.types.VirtualResource)2 LinkedList (java.util.LinkedList)2