Search in sources :

Example 1 with CloudMethodWorker

use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.

the class ResourceOptimizer method getBestDestruction.

/**
 * Given a set of resources, it checks every possible modification of the resource and returns the one that better
 * fits with the destruction recommendations.
 *
 * The decision-making algorithm tries to minimize the number of affected CE that weren't recommended to be
 * modified, minimize the number of slots that weren't requested to be destroyed and maximize the number of slots
 * that can be removed and they were requested for.
 *
 * @param resourceSet
 *            set of resources
 * @param destroyRecommendations
 *            number of slots to be removed for each CE
 * @return an object array defining the best solution.
 *
 *         0-> (Resource) selected Resource.
 *
 *         1->(CloudTypeInstanceDescription) Type to be destroyed to be destroyed.
 *
 *         2-> (int[]) record of the #CE with removed slots and that they shouldn't be modified, #slots that will be
 *         destroyed and they weren't recommended, #slots that will be removed and they were asked to be.
 */
private Object[] getBestDestruction(Collection<CloudMethodWorker> resourceSet, float[] destroyRecommendations) {
    CloudProvider cp;
    float[] bestRecord = new float[3];
    bestRecord[0] = Float.MAX_VALUE;
    bestRecord[1] = Float.MAX_VALUE;
    bestRecord[2] = Float.MIN_VALUE;
    Resource bestResource = null;
    CloudInstanceTypeDescription bestType = null;
    for (CloudMethodWorker res : resourceSet) {
        cp = res.getProvider();
        if (cp == null) {
            // it's not a cloud machine
            if (DEBUG) {
                RUNTIME_LOGGER.debug("Resource " + res.getName() + " is not cloud. Skipping...");
            }
            continue;
        }
        Map<CloudInstanceTypeDescription, float[]> typeToPoints = getPossibleReductions(res, destroyRecommendations);
        for (Map.Entry<CloudInstanceTypeDescription, float[]> destruction : typeToPoints.entrySet()) {
            CloudInstanceTypeDescription type = destruction.getKey();
            float[] values = destruction.getValue();
            if (DEBUG) {
                RUNTIME_LOGGER.debug("Type: " + type.getName() + " value 0: " + values[0] + " (" + bestRecord[0] + ") " + " value 1: " + values[1] + " (" + bestRecord[1] + ") " + " value 2: " + values[2] + " (" + bestRecord[2] + ")");
            }
            if (bestRecord[0] == values[0]) {
                if (bestRecord[1] == values[1]) {
                    if (bestRecord[2] < values[2]) {
                        bestRecord = values;
                        bestResource = res;
                        bestType = type;
                    }
                } else if (bestRecord[1] > values[1]) {
                    bestRecord = values;
                    bestResource = res;
                    bestType = type;
                }
            } else if (bestRecord[0] > values[0]) {
                bestRecord = values;
                bestResource = res;
                bestType = type;
            }
        }
    }
    if (bestResource != null) {
        Object[] ret = new Object[3];
        ret[0] = bestResource;
        ret[1] = bestType;
        ret[2] = bestRecord;
        return ret;
    } else {
        RUNTIME_LOGGER.warn("Best resource to remove not found");
        return null;
    }
}
Also used : CloudProvider(es.bsc.compss.types.CloudProvider) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) Resource(es.bsc.compss.types.resources.Resource) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with CloudMethodWorker

use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.

the class ResourceOptimizer method trimReductionOptions.

private List<CloudMethodWorker> trimReductionOptions(Collection<CloudMethodWorker> options, float[] recommendations) {
    if (DEBUG) {
        RUNTIME_LOGGER.debug("[Resource Optimizer] * Trimming reduction options");
    }
    List<CloudMethodWorker> resources = new LinkedList<>();
    Iterator<CloudMethodWorker> it = options.iterator();
    while (it.hasNext()) {
        CloudMethodWorker resource = it.next();
        // (resource.getUsedTaskCount() == 0);
        boolean aggressive = false;
        boolean add = !aggressive;
        if (DEBUG) {
            RUNTIME_LOGGER.debug("\t Evaluating " + resource.getName() + ". Default reduction is " + add);
        }
        List<Integer> executableCores = resource.getExecutableCores();
        for (int coreId : executableCores) {
            if (!aggressive && recommendations[coreId] < 1) {
                if (DEBUG) {
                    RUNTIME_LOGGER.debug("\t\tVM not removed because of not agressive and recomendations < 1 (" + recommendations[coreId] + ")");
                }
                add = false;
                break;
            }
            if (aggressive && recommendations[coreId] > 0) {
                if (DEBUG) {
                    RUNTIME_LOGGER.debug("\t\tVM removed because of agressive and recomendations > 0 (" + recommendations[coreId] + ")");
                }
                add = true;
                break;
            }
        }
        if (add) {
            if (DEBUG) {
                RUNTIME_LOGGER.debug("\t\tVM added to candidate to remove.");
            }
            resources.add(resource);
        }
    }
    return resources;
}
Also used : CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) LinkedList(java.util.LinkedList)

Example 3 with CloudMethodWorker

use of es.bsc.compss.types.resources.CloudMethodWorker 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)

Example 4 with CloudMethodWorker

use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.

the class ReduceWorkerAction method doAction.

@Override
protected void doAction() {
    (new Thread() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            Thread.currentThread().setName(worker.getName() + " stopper");
            CloudMethodWorker w = (CloudMethodWorker) worker.getResource();
            PendingReduction<WorkerResourceDescription> crd = (PendingReduction<WorkerResourceDescription>) ru;
            ResourceManager.reduceResource(w, crd);
            w.endTask((MethodResourceDescription) getResourceConsumption());
            try {
                ru.waitForCompletion();
            } catch (Exception e) {
                LOGGER.error("ERROR: Exception raised on worker reduction", e);
                ErrorManager.warn("Exception reducing worker. Check runtime.log for more details", e);
                notifyError();
            }
            notifyCompleted();
        }
    }).start();
}
Also used : CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) WorkerResourceDescription(es.bsc.compss.types.resources.WorkerResourceDescription) PendingReduction(es.bsc.compss.types.resources.updates.PendingReduction) BlockedActionException(es.bsc.compss.scheduler.exceptions.BlockedActionException) UnassignedActionException(es.bsc.compss.scheduler.exceptions.UnassignedActionException) FailedActionException(es.bsc.compss.scheduler.exceptions.FailedActionException)

Example 5 with CloudMethodWorker

use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.

the class StopWorkerAction method removeResource.

private void removeResource() {
    Worker<? extends WorkerResourceDescription> w = worker.getResource();
    if (w instanceof CloudMethodWorker) {
        CloudMethodWorker cmw = (CloudMethodWorker) w;
        ResourceManager.terminateCloudResource(cmw, (CloudMethodResourceDescription) ru.getModification());
    } else {
        ResourceManager.removeWorker(w);
    }
}
Also used : CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker)

Aggregations

CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)22 CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)12 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)10 CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)9 HashMap (java.util.HashMap)8 FakeNode (es.bsc.compss.types.fake.FakeNode)7 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)7 Test (org.junit.Test)7 JSONObject (org.json.JSONObject)3 ConnectorException (es.bsc.compss.connectors.ConnectorException)2 BlockedActionException (es.bsc.compss.scheduler.exceptions.BlockedActionException)2 UnassignedActionException (es.bsc.compss.scheduler.exceptions.UnassignedActionException)2 CloudProvider (es.bsc.compss.types.CloudProvider)2 WorkerResourceDescription (es.bsc.compss.types.resources.WorkerResourceDescription)2 LinkedList (java.util.LinkedList)2 VM (es.bsc.compss.connectors.VM)1 FailedActionException (es.bsc.compss.scheduler.exceptions.FailedActionException)1 InvalidSchedulingException (es.bsc.compss.scheduler.exceptions.InvalidSchedulingException)1 Profile (es.bsc.compss.scheduler.types.Profile)1 StopWorkerAction (es.bsc.compss.scheduler.types.allocatableactions.StopWorkerAction)1