Search in sources :

Example 1 with SingularityClusterUtilization

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

the class SingularityUsageTest method itCorrectlyTracksMaxAndMinUtilizedPerRequest.

@Test
public void itCorrectlyTracksMaxAndMinUtilizedPerRequest() {
    initRequest();
    double cpuReserved = 10;
    double memMbReserved = .001;
    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 10 cpu
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1.getId(), 50, getTimestampSeconds(t1, 5), 800);
    // used 8 cpu
    MesosTaskMonitorObject t2u1 = getTaskMonitor(t2.getId(), 40, getTimestampSeconds(t2, 5), 700);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u1, t2u1));
    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(1, t1TaskUsages);
    Assert.assertEquals(1, t2TaskUsages);
    Assert.assertEquals(1, utilization.getRequestUtilizations().size());
    double maxCpu = utilization.getRequestUtilizations().get(0).getMaxCpuUsed();
    double minCpu = utilization.getRequestUtilizations().get(0).getMinCpuUsed();
    long maxMemBytes = utilization.getRequestUtilizations().get(0).getMaxMemBytesUsed();
    long minMemBytes = utilization.getRequestUtilizations().get(0).getMinMemBytesUsed();
    Assert.assertEquals(10, maxCpu, 0);
    Assert.assertEquals(8, minCpu, 0);
    Assert.assertEquals(800, maxMemBytes);
    Assert.assertEquals(700, minMemBytes);
    // new max and min after 2nd run
    // used 12 cpu
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1.getId(), 110, getTimestampSeconds(t1, 10), 850);
    // used 7 cpu
    MesosTaskMonitorObject t2u2 = getTaskMonitor(t2.getId(), 75, getTimestampSeconds(t2, 10), 600);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u2, t2u2));
    usagePoller.runActionOnPoll();
    Assert.assertTrue("Couldn't find cluster utilization", usageManager.getClusterUtilization().isPresent());
    utilization = usageManager.getClusterUtilization().get();
    t1TaskUsages = usageManager.getTaskUsage(t1.getId()).size();
    t2TaskUsages = usageManager.getTaskUsage(t2.getId()).size();
    Assert.assertEquals(2, t1TaskUsages);
    Assert.assertEquals(2, t2TaskUsages);
    Assert.assertEquals(1, utilization.getRequestUtilizations().size());
    maxCpu = utilization.getRequestUtilizations().get(0).getMaxCpuUsed();
    minCpu = utilization.getRequestUtilizations().get(0).getMinCpuUsed();
    maxMemBytes = utilization.getRequestUtilizations().get(0).getMaxMemBytesUsed();
    minMemBytes = utilization.getRequestUtilizations().get(0).getMinMemBytesUsed();
    Assert.assertEquals(12, maxCpu, 0);
    Assert.assertEquals(7, minCpu, 0);
    Assert.assertEquals(850, maxMemBytes);
    Assert.assertEquals(600, minMemBytes);
    // same max and min after 3rd run
    // used 8 cpu
    MesosTaskMonitorObject t1u3 = getTaskMonitor(t1.getId(), 150, getTimestampSeconds(t1, 15), 750);
    // used 8 cpu
    MesosTaskMonitorObject t2u3 = getTaskMonitor(t2.getId(), 120, getTimestampSeconds(t2, 15), 700);
    mesosClient.setSlaveResourceUsage(host, Arrays.asList(t1u3, t2u3));
    usagePoller.runActionOnPoll();
    Assert.assertTrue("Couldn't find cluster utilization", usageManager.getClusterUtilization().isPresent());
    utilization = usageManager.getClusterUtilization().get();
    t1TaskUsages = usageManager.getTaskUsage(t1.getId()).size();
    t2TaskUsages = usageManager.getTaskUsage(t2.getId()).size();
    Assert.assertEquals(3, t1TaskUsages);
    Assert.assertEquals(3, t2TaskUsages);
    Assert.assertEquals(1, utilization.getRequestUtilizations().size());
    maxCpu = utilization.getRequestUtilizations().get(0).getMaxCpuUsed();
    minCpu = utilization.getRequestUtilizations().get(0).getMinCpuUsed();
    maxMemBytes = utilization.getRequestUtilizations().get(0).getMaxMemBytesUsed();
    minMemBytes = utilization.getRequestUtilizations().get(0).getMinMemBytesUsed();
    Assert.assertEquals(12, maxCpu, 0);
    Assert.assertEquals(7, minCpu, 0);
    Assert.assertEquals(850, maxMemBytes);
    Assert.assertEquals(600, minMemBytes);
}
Also used : SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 2 with SingularityClusterUtilization

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

the class SingularityUsagePoller method getClusterUtilization.

private SingularityClusterUtilization getClusterUtilization(Map<String, RequestUtilization> utilizationPerRequestId, long totalMemBytesUsed, long totalMemBytesAvailable, double totalCpuUsed, double totalCpuAvailable, long totalDiskBytesUsed, long totalDiskBytesAvailable, long now) {
    int numRequestsWithUnderUtilizedCpu = 0;
    int numRequestsWithOverUtilizedCpu = 0;
    int numRequestsWithUnderUtilizedMemBytes = 0;
    int numRequestsWithUnderUtilizedDiskBytes = 0;
    double totalUnderUtilizedCpu = 0;
    double totalOverUtilizedCpu = 0;
    long totalUnderUtilizedMemBytes = 0;
    long totalUnderUtilizedDiskBytes = 0;
    double maxUnderUtilizedCpu = 0;
    double maxOverUtilizedCpu = 0;
    long maxUnderUtilizedMemBytes = 0;
    long maxUnderUtilizedDiskBytes = 0;
    String maxUnderUtilizedCpuRequestId = null;
    String maxOverUtilizedCpuRequestId = null;
    String maxUnderUtilizedMemBytesRequestId = null;
    String maxUnderUtilizedDiskBytesRequestId = null;
    double minUnderUtilizedCpu = Double.MAX_VALUE;
    double minOverUtilizedCpu = Double.MAX_VALUE;
    long minUnderUtilizedMemBytes = Long.MAX_VALUE;
    long minUnderUtilizedDiskBytes = Long.MAX_VALUE;
    for (RequestUtilization utilization : utilizationPerRequestId.values()) {
        Optional<SingularityDeploy> maybeDeploy = deployManager.getDeploy(utilization.getRequestId(), utilization.getDeployId());
        if (maybeDeploy.isPresent() && maybeDeploy.get().getResources().isPresent()) {
            String requestId = utilization.getRequestId();
            long memoryBytesReserved = (long) (maybeDeploy.get().getResources().get().getMemoryMb() * SingularitySlaveUsage.BYTES_PER_MEGABYTE);
            double cpuReserved = maybeDeploy.get().getResources().get().getCpus();
            long diskBytesReserved = (long) maybeDeploy.get().getResources().get().getDiskMb() * SingularitySlaveUsage.BYTES_PER_MEGABYTE;
            double unusedCpu = cpuReserved - utilization.getAvgCpuUsed();
            long unusedMemBytes = (long) (memoryBytesReserved - utilization.getAvgMemBytesUsed());
            long unusedDiskBytes = (long) (diskBytesReserved - utilization.getAvgDiskBytesUsed());
            if (unusedCpu > 0) {
                numRequestsWithUnderUtilizedCpu++;
                totalUnderUtilizedCpu += unusedCpu;
                if (unusedCpu > maxUnderUtilizedCpu) {
                    maxUnderUtilizedCpu = unusedCpu;
                    maxUnderUtilizedCpuRequestId = requestId;
                }
                minUnderUtilizedCpu = Math.min(unusedCpu, minUnderUtilizedCpu);
            } else if (unusedCpu < 0) {
                double overusedCpu = Math.abs(unusedCpu);
                numRequestsWithOverUtilizedCpu++;
                totalOverUtilizedCpu += overusedCpu;
                if (overusedCpu > maxOverUtilizedCpu) {
                    maxOverUtilizedCpu = overusedCpu;
                    maxOverUtilizedCpuRequestId = requestId;
                }
                minOverUtilizedCpu = Math.min(overusedCpu, minOverUtilizedCpu);
            }
            if (unusedMemBytes > 0) {
                numRequestsWithUnderUtilizedMemBytes++;
                totalUnderUtilizedMemBytes += unusedMemBytes;
                if (unusedMemBytes > maxUnderUtilizedMemBytes) {
                    maxUnderUtilizedMemBytes = unusedMemBytes;
                    maxUnderUtilizedMemBytesRequestId = requestId;
                }
                minUnderUtilizedMemBytes = Math.min(unusedMemBytes, minUnderUtilizedMemBytes);
            }
            if (unusedDiskBytes > 0) {
                numRequestsWithUnderUtilizedDiskBytes++;
                totalUnderUtilizedDiskBytes += unusedDiskBytes;
                if (unusedDiskBytes > maxUnderUtilizedDiskBytes) {
                    maxUnderUtilizedDiskBytes = unusedDiskBytes;
                    maxUnderUtilizedDiskBytesRequestId = requestId;
                }
                minUnderUtilizedDiskBytes = Math.min(unusedDiskBytes, minUnderUtilizedMemBytes);
            }
        }
    }
    double avgUnderUtilizedCpu = numRequestsWithUnderUtilizedCpu != 0 ? totalUnderUtilizedCpu / numRequestsWithUnderUtilizedCpu : 0;
    double avgOverUtilizedCpu = numRequestsWithOverUtilizedCpu != 0 ? totalOverUtilizedCpu / numRequestsWithOverUtilizedCpu : 0;
    long avgUnderUtilizedMemBytes = numRequestsWithUnderUtilizedMemBytes != 0 ? totalUnderUtilizedMemBytes / numRequestsWithUnderUtilizedMemBytes : 0;
    long avgUnderUtilizedDiskBytes = numRequestsWithUnderUtilizedDiskBytes != 0 ? totalUnderUtilizedDiskBytes / numRequestsWithUnderUtilizedDiskBytes : 0;
    return new SingularityClusterUtilization(new ArrayList<>(utilizationPerRequestId.values()), numRequestsWithUnderUtilizedCpu, numRequestsWithOverUtilizedCpu, numRequestsWithUnderUtilizedMemBytes, numRequestsWithUnderUtilizedDiskBytes, totalUnderUtilizedCpu, totalOverUtilizedCpu, totalUnderUtilizedMemBytes, totalUnderUtilizedDiskBytes, avgUnderUtilizedCpu, avgOverUtilizedCpu, avgUnderUtilizedMemBytes, avgUnderUtilizedDiskBytes, maxUnderUtilizedCpu, maxOverUtilizedCpu, maxUnderUtilizedMemBytes, maxUnderUtilizedDiskBytes, maxUnderUtilizedCpuRequestId, maxOverUtilizedCpuRequestId, maxUnderUtilizedMemBytesRequestId, maxUnderUtilizedDiskBytesRequestId, getMin(minUnderUtilizedCpu), getMin(minOverUtilizedCpu), getMin(minUnderUtilizedMemBytes), getMin(minUnderUtilizedDiskBytes), totalMemBytesUsed, totalMemBytesAvailable, totalDiskBytesUsed, totalDiskBytesAvailable, totalCpuUsed, totalCpuAvailable, now);
}
Also used : RequestUtilization(com.hubspot.singularity.RequestUtilization) SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) SingularityDeploy(com.hubspot.singularity.SingularityDeploy)

Example 3 with SingularityClusterUtilization

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

the class SingularityUsageTest method itTracksOverusedCpuInClusterUtilization.

@Test
public void itTracksOverusedCpuInClusterUtilization() {
    initRequest();
    double cpuReserved = 2;
    double memMbReserved = .0009;
    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();
    // 4 cpus used
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 20, getTimestampSeconds(taskId, 5), 1024);
    mesosClient.setSlaveResourceUsage(host, Collections.singletonList(t1u1));
    usagePoller.runActionOnPoll();
    // 4 cpus used
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1, 40, getTimestampSeconds(taskId, 10), 1024);
    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, 1, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0);
    Assert.assertEquals(requestId, utilization.getMaxOverUtilizedCpuRequestId());
}
Also used : SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 4 with SingularityClusterUtilization

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

the class SingularityUsageTest method itDoesntIncludePerfectlyUtilizedRequestsInClusterUtilization.

@Test
public void itDoesntIncludePerfectlyUtilizedRequestsInClusterUtilization() {
    initRequest();
    double cpuReserved = 2;
    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();
    // 2 cpus used
    MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 10, getTimestampSeconds(taskId, 5), 1024);
    mesosClient.setSlaveResourceUsage(host, Collections.singletonList(t1u1));
    usagePoller.runActionOnPoll();
    // 2 cpus used
    MesosTaskMonitorObject t1u2 = getTaskMonitor(t1, 20, getTimestampSeconds(taskId, 10), 900);
    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, 0, 1, 0, 0, 86, 0, 0, 86, 0, 0, 86);
    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 5 with SingularityClusterUtilization

use of com.hubspot.singularity.SingularityClusterUtilization 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)

Aggregations

SingularityClusterUtilization (com.hubspot.singularity.SingularityClusterUtilization)6 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)5 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)5 Test (org.junit.Test)5 RequestUtilization (com.hubspot.singularity.RequestUtilization)1 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1