Search in sources :

Example 1 with AgentMatchState

use of com.hubspot.singularity.AgentMatchState in project Singularity by HubSpot.

the class SingularityMesosOfferScheduler method score.

private double score(SingularityOfferHolder offerHolder, SingularityTaskRequestHolder taskRequestHolder, Optional<SingularityAgentUsageWithCalculatedScores> maybeUsage, List<SingularityTaskId> activeTaskIdsForRequest, RequestUtilization requestUtilization, Map<SingularityDeployKey, Optional<SingularityDeployStatistics>> deployStatsCache, Set<String> overloadedHosts) {
    final SingularityTaskRequest taskRequest = taskRequestHolder.getTaskRequest();
    final SingularityPendingTaskId pendingTaskId = taskRequest.getPendingTask().getPendingTaskId();
    double estimatedCpusToAdd = taskRequestHolder.getTotalResources().getCpus();
    if (requestUtilization != null) {
        estimatedCpusToAdd = agentAndRackHelper.getEstimatedCpuUsageForRequest(requestUtilization);
    }
    if (mesosConfiguration.isOmitOverloadedHosts() && maybeUsage.isPresent() && maybeUsage.get().isCpuOverloaded(estimatedCpusToAdd)) {
        overloadedHosts.add(offerHolder.getHostname());
        LOG.debug("Agent {} is overloaded (load5 {}/{}, load1 {}/{}, estimated cpus to add: {}, already committed cpus: {}), ignoring offer", offerHolder.getHostname(), maybeUsage.get().getAgentUsage().getSystemLoad5Min(), maybeUsage.get().getAgentUsage().getSystemCpusTotal(), maybeUsage.get().getAgentUsage().getSystemLoad1Min(), maybeUsage.get().getAgentUsage().getSystemCpusTotal(), estimatedCpusToAdd, maybeUsage.get().getEstimatedAddedCpusUsage());
        return 0;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Attempting to match task {} resources {} with required role '{}' ({} for task + {} for executor) with remaining offer resources {}", pendingTaskId, taskRequestHolder.getTotalResources(), taskRequest.getRequest().getRequiredRole().orElse("*"), taskRequestHolder.getTaskResources(), taskRequestHolder.getExecutorResources(), MesosUtils.formatForLogging(offerHolder.getCurrentResources()));
    }
    final boolean matchesResources = MesosUtils.doesOfferMatchResources(taskRequest.getRequest().getRequiredRole(), taskRequestHolder.getTotalResources(), offerHolder.getCurrentResources(), taskRequestHolder.getRequestedPorts());
    if (!matchesResources) {
        return 0;
    }
    final AgentMatchState agentMatchState = agentAndRackManager.doesOfferMatch(offerHolder, taskRequest, activeTaskIdsForRequest, isPreemptibleTask(taskRequest, deployStatsCache), requestUtilization);
    if (agentMatchState.isMatchAllowed()) {
        return score(offerHolder.getHostname(), maybeUsage, agentMatchState);
    } else if (LOG.isTraceEnabled()) {
        LOG.trace("Ignoring offer on host {} with roles {} on {} for task {}; matched resources: {}, agent match state: {}", offerHolder.getHostname(), offerHolder.getRoles(), offerHolder.getHostname(), pendingTaskId, matchesResources, agentMatchState);
    }
    return 0;
}
Also used : SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) AgentMatchState(com.hubspot.singularity.AgentMatchState)

Aggregations

AgentMatchState (com.hubspot.singularity.AgentMatchState)1 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)1