Search in sources :

Example 96 with SingularityTaskId

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

the class SingularityUsageTest method testUsagePollerComplex.

@Test
public void testUsagePollerComplex() throws InterruptedException {
    initRequest();
    initFirstDeploy();
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
    resourceOffers(1);
    configuration.setNumUsageToKeep(2);
    configuration.setUsageIntervalSeconds(1);
    configuration.setCheckUsageEveryMillis(1);
    List<SingularityTaskId> taskIds = taskManager.getActiveTaskIds();
    String t1 = taskIds.get(0).getId();
    String t2 = taskIds.get(1).getId();
    String slaveId = slaveManager.getObjectIds().get(0);
    String host = slaveManager.getObjects().get(0).getHost();
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 2, 5, 100);
    MesosTaskMonitorObject t2u1 = getTaskMonitor(t2, 10, 5, 1024);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u1, t2u1));
    usagePoller.runActionOnPoll();
    cleaner.runActionOnPoll();
    Thread.sleep(2);
    // 5 seconds have elapsed, t1 has used 1 CPU the whole time = 5 + 2
    // t2 has used 2.5 CPUs the whole time =
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1, 7, 10, 125);
    MesosTaskMonitorObject t2u2 = getTaskMonitor(t2, 22.5, 10, 750);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u2, t2u2));
    usagePoller.runActionOnPoll();
    cleaner.runActionOnPoll();
    // check usage now
    Assert.assertEquals(3.5, usageManager.getSlaveUsage(slaveId).get(1).getCpusUsed(), 0);
    Assert.assertEquals(875, usageManager.getSlaveUsage(slaveId).get(1).getMemoryBytesUsed(), 0);
    Assert.assertEquals(2, usageManager.getSlaveUsage(slaveId).get(1).getNumTasks(), 0);
    // check task usage
    Assert.assertEquals(22.5, usageManager.getTaskUsage(t2).get(1).getCpuSeconds(), 0);
    Assert.assertEquals(10, usageManager.getTaskUsage(t2).get(0).getCpuSeconds(), 0);
    Thread.sleep(2);
    MesosTaskMonitorObject t1u3 = getTaskMonitor(t1, 8, 11, 125);
    MesosTaskMonitorObject t2u3 = getTaskMonitor(t2, 23.5, 11, 1024);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u3, t2u3));
    usagePoller.runActionOnPoll();
    cleaner.runActionOnPoll();
    // check that there is only 2 usages
    Assert.assertEquals(2, usageManager.getSlaveUsage(slaveId).size());
    Assert.assertEquals(2, usageManager.getTaskUsage(t1).size());
    Assert.assertEquals(2, usageManager.getTaskUsage(t2).size());
    Assert.assertEquals(22.5, usageManager.getTaskUsage(t2).get(0).getCpuSeconds(), 0);
    Assert.assertEquals(23.5, usageManager.getTaskUsage(t2).get(1).getCpuSeconds(), 0);
    Assert.assertEquals(875, usageManager.getSlaveUsage(slaveId).get(0).getMemoryBytesUsed(), 0);
    Assert.assertEquals(1149, usageManager.getSlaveUsage(slaveId).get(1).getMemoryBytesUsed(), 0);
    Assert.assertEquals(slaveId, usageManager.getAllCurrentSlaveUsage().get(0).getSlaveId());
    Assert.assertEquals(1149, usageManager.getAllCurrentSlaveUsage().get(0).getMemoryBytesUsed());
    List<SingularityTaskCurrentUsageWithId> taskCurrentUsages = usageManager.getTaskCurrentUsages(taskManager.getActiveTaskIds());
    Assert.assertEquals(2, taskCurrentUsages.size());
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIds();
    for (SingularityTaskCurrentUsageWithId taskCurrentUsage : taskCurrentUsages) {
        activeTaskIds.remove(taskCurrentUsage.getTaskId());
    }
    Assert.assertTrue(activeTaskIds.isEmpty());
}
Also used : SingularityTaskCurrentUsageWithId(com.hubspot.singularity.SingularityTaskCurrentUsageWithId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 97 with SingularityTaskId

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

the class SingularityUsageTest method itLimitsTheNumberOfTaskCleanupsToCreate.

@Test
public void itLimitsTheNumberOfTaskCleanupsToCreate() {
    try {
        configuration.setShuffleTasksForOverloadedSlaves(true);
        configuration.setMaxTasksToShuffleTotal(1);
        initRequest();
        initFirstDeployWithResources(configuration.getMesosConfiguration().getDefaultCpus(), configuration.getMesosConfiguration().getDefaultMemory());
        saveAndSchedule(requestManager.getRequest(requestId).get().getRequest().toBuilder().setInstances(Optional.of(3)));
        resourceOffers(1);
        SingularitySlaveUsage highUsage = new SingularitySlaveUsage(15, 10, Optional.of(10.0), 1, 1, Optional.of(30L), 1, 1, Optional.of(1024L), Collections.emptyMap(), 1, System.currentTimeMillis(), 1, 30000, 10, 15, 15, 15, 0, 107374182);
        usageManager.saveSpecificSlaveUsageAndSetCurrent("host1", highUsage);
        SingularityTaskId taskId1 = taskManager.getActiveTaskIds().get(0);
        String t1 = taskId1.getId();
        SingularityTaskId taskId2 = taskManager.getActiveTaskIds().get(1);
        String t2 = taskId2.getId();
        statusUpdate(taskManager.getTask(taskId1).get(), TaskState.TASK_STARTING, Optional.of(taskId1.getStartedAt()));
        statusUpdate(taskManager.getTask(taskId2).get(), TaskState.TASK_STARTING, Optional.of(taskId2.getStartedAt()));
        // task 1 using 3 cpus
        MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 15, TimeUnit.MILLISECONDS.toSeconds(taskId1.getStartedAt()) + 5, 1024);
        // task 2 using 2 cpus
        MesosTaskMonitorObject t2u1 = getTaskMonitor(t2, 10, TimeUnit.MILLISECONDS.toSeconds(taskId2.getStartedAt()) + 5, 1024);
        mesosClient.setSlaveResourceUsage("host1", Arrays.asList(t1u1, t2u1));
        mesosClient.setSlaveMetricsSnapshot("host1", new MesosSlaveMetricsSnapshotObject(0, 0, 0, 10.0, 0, 0, 0, 0, 0, 0, 0, 0, 10.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0));
        usagePoller.runActionOnPoll();
        // First task is cleaned up
        Assert.assertEquals(taskManager.getTaskCleanup(taskId1.getId()).get().getCleanupType(), TaskCleanupType.REBALANCE_CPU_USAGE);
        // Second task doesn't get cleaned up dur to cluster wide limit
        Assert.assertFalse(taskManager.getTaskCleanup(taskId2.getId()).isPresent());
    } finally {
        configuration.setShuffleTasksForOverloadedSlaves(false);
        configuration.setMaxTasksToShuffleTotal(6);
    }
}
Also used : SingularitySlaveUsage(com.hubspot.singularity.SingularitySlaveUsage) MesosSlaveMetricsSnapshotObject(com.hubspot.mesos.json.MesosSlaveMetricsSnapshotObject) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 98 with SingularityTaskId

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

the class SingularityUsageTest method itTracksClusterUtilizationSimple.

@Test
public void itTracksClusterUtilizationSimple() {
    initRequest();
    double cpuReserved = 10;
    double memMbReserved = .001;
    initFirstDeployWithResources(cpuReserved, memMbReserved);
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(1)));
    resourceOffers(1);
    SingularityTaskId taskId = taskManager.getActiveTaskIds().get(0);
    String t1 = taskId.getId();
    String host = slaveManager.getObjects().get(0).getHost();
    // used 8 cpu
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 40, getTimestampSeconds(taskId, 5), 800);
    mesosClient.setSlaveResourceUsage(host, Collections.singletonList(t1u1));
    usagePoller.runActionOnPoll();
    // used 8 cpu
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1, 80, getTimestampSeconds(taskId, 10), 850);
    mesosClient.setSlaveResourceUsage(host, Collections.singletonList(t1u2));
    usagePoller.runActionOnPoll();
    Assert.assertTrue("Couldn't find cluster utilization", usageManager.getClusterUtilization().isPresent());
    SingularityClusterUtilization utilization = usageManager.getClusterUtilization().get();
    int taskUsages = usageManager.getTaskUsage(t1).size();
    testUtilization(utilization, 2, taskUsages, cpuReserved, memMbReserved, 0, 1, 1, 0, 2, 223, 0, 2, 223, 0, 2, 223);
    Assert.assertEquals(requestId, utilization.getMaxUnderUtilizedCpuRequestId());
    Assert.assertEquals(requestId, utilization.getMaxUnderUtilizedMemBytesRequestId());
}
Also used : SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 99 with SingularityTaskId

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

the class SingularityUsageTest method itCorrectlyDeterminesResourcesReservedForRequestsWithMultipleTasks.

@Test
public void itCorrectlyDeterminesResourcesReservedForRequestsWithMultipleTasks() {
    initRequest();
    double cpuReserved = 10;
    double memMbReserved = .0009;
    initFirstDeployWithResources(cpuReserved, memMbReserved);
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
    resourceOffers(1);
    List<SingularityTaskId> taskIds = taskManager.getActiveTaskIds();
    SingularityTaskId t1 = taskIds.get(0);
    SingularityTaskId t2 = taskIds.get(1);
    String host = slaveManager.getObjects().get(0).getHost();
    // used 6 cpu
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1.getId(), 30, getTimestampSeconds(t1, 5), 800);
    // used 6 cpu
    MesosTaskMonitorObject t2u1 = getTaskMonitor(t2.getId(), 30, getTimestampSeconds(t2, 5), 800);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u1, t2u1));
    usagePoller.runActionOnPoll();
    // used 8 cpu
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1.getId(), 70, getTimestampSeconds(t1, 10), 850);
    // used 8 cpu
    MesosTaskMonitorObject t2u2 = getTaskMonitor(t2.getId(), 70, getTimestampSeconds(t2, 10), 850);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u2, t2u2));
    usagePoller.runActionOnPoll();
    Assert.assertTrue("Couldn't find cluster utilization", usageManager.getClusterUtilization().isPresent());
    SingularityClusterUtilization utilization = usageManager.getClusterUtilization().get();
    int t1TaskUsages = usageManager.getTaskUsage(t1.getId()).size();
    int t2TaskUsages = usageManager.getTaskUsage(t2.getId()).size();
    Assert.assertEquals(2, t1TaskUsages);
    Assert.assertEquals(2, t2TaskUsages);
    Assert.assertEquals(1, utilization.getRequestUtilizations().size());
    Assert.assertEquals(cpuReserved * (t1TaskUsages + t2TaskUsages), utilization.getRequestUtilizations().get(0).getCpuReserved(), 0);
    Assert.assertEquals(Math.round(memMbReserved * SingularitySlaveUsage.BYTES_PER_MEGABYTE * (t1TaskUsages + t2TaskUsages)), utilization.getRequestUtilizations().get(0).getMemBytesReserved(), 1);
}
Also used : SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 100 with SingularityTaskId

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

the class TaskManager method getNumLaunchingTasks.

public int getNumLaunchingTasks() {
    List<SingularityTaskId> activeTaskIds = getActiveTaskIds();
    final Map<String, SingularityTaskId> paths = Maps.newHashMapWithExpectedSize(activeTaskIds.size());
    for (SingularityTaskId taskId : activeTaskIds) {
        paths.put(getUpdatePath(taskId, ExtendedTaskState.TASK_RUNNING), taskId);
    }
    return notExists("getNumLaunchingTasks", paths).size();
}
Also used : SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6