Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize memory shuffles over cpu #2049

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -54,8 +52,6 @@ public class SingularityUsageHelper {
private final TaskManager taskManager;
private final UsageManager usageManager;

private final ConcurrentHashMap<String, ReentrantLock> requestLocks;

@Inject
public SingularityUsageHelper(
MesosClient mesosClient,
Expand All @@ -72,8 +68,6 @@ public SingularityUsageHelper(
this.slaveManager = slaveManager;
this.taskManager = taskManager;
this.usageManager = usageManager;

this.requestLocks = new ConcurrentHashMap<>();
}

public List<SingularitySlave> getSlavesToTrackUsageFor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.hubspot.singularity.SingularityAction;
import com.hubspot.singularity.SingularityClusterUtilization;
import com.hubspot.singularity.SingularityDeploy;
import com.hubspot.singularity.SingularityManagedScheduledExecutorServiceFactory;
import com.hubspot.singularity.SingularityManagedThreadPoolFactory;
import com.hubspot.singularity.SingularityPendingRequest;
import com.hubspot.singularity.SingularityPendingRequest.PendingType;
Expand Down Expand Up @@ -160,6 +159,13 @@ private void shuffleTasksOnOverloadedHosts(Map<SingularitySlaveUsage, List<TaskI
.sorted((usage1, usage2) -> {
OverusedResource mostOverusedResource1 = getMostOverusedResource(usage1, getSystemLoadForShuffle(usage1), usage1.getMemoryBytesUsed());
OverusedResource mostOverusedResource2 = getMostOverusedResource(usage2, getSystemLoadForShuffle(usage2), usage2.getMemoryBytesUsed());
if (mostOverusedResource1.resourceType != mostOverusedResource2.resourceType) {
if (mostOverusedResource1.resourceType == Type.MEMORY) {
return -1;
} else {
return 1;
}
}
Comment on lines +162 to +168
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this short circuits all resource comparisons when the two resources being compared aren't the same. So like, if we're comparing DISK vs CPU, whichever one is mostOverusedResource1 would always sort as higher. Is that the intent? Should we scope this logic to the specific scenario when one of the resources being compared is MEMORY?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have shuffles for disk so far. Type can only be MEM or CPU

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, derp. cool


return Double.compare(mostOverusedResource2.overusage, mostOverusedResource1.overusage);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import com.hubspot.mesos.json.MesosSlaveMetricsSnapshotObject;
import com.hubspot.mesos.json.MesosTaskMonitorObject;
Expand Down Expand Up @@ -537,6 +538,69 @@ public void itCreatesTaskCleanupsWhenAMachineIsOverloadedOnMemory() {
}
}

@Test
public void itPrioritizesMemoryShuffleOverCpu() {
try {
configuration.setShuffleTasksForOverloadedSlaves(true);
configuration.setMinutesBeforeNewTaskEligibleForShuffle(0);
configuration.setMaxTasksToShuffleTotal(1);
configuration.setShuffleTasksWhenSlaveMemoryUtilizationPercentageExceeds(0.90);

initRequest();
initFirstDeployWithResources(configuration.getMesosConfiguration().getDefaultCpus(), configuration.getMesosConfiguration().getDefaultMemory());
saveAndSchedule(requestManager.getRequest(requestId).get().getRequest().toBuilder().setInstances(Optional.of(2)));
sms.resourceOffers(ImmutableList.of(
createOffer(1, 128, 50000, "slave1", "host1"),
createOffer(1, 128, 50000, "slave2", "host2")
)).join();
SingularitySlaveUsage highMemUsage = new SingularitySlaveUsage(10, 10, Optional.of(10.0), 1, 1, Optional.of(30L), 1, 1, Optional.of(1024L), 1, System.currentTimeMillis(), 200000, 10000, 10, 10, 10, 10, 0, 107374182);
SingularitySlaveUsage highCpuUsage = new SingularitySlaveUsage(15, 10, Optional.of(10.0), 1, 1, Optional.of(30L), 1, 1, Optional.of(1024L), 1, System.currentTimeMillis(), 200000, 30000, 10, 15, 15, 15, 0, 107374182);

usageManager.saveCurrentSlaveUsage(new SingularitySlaveUsageWithId(highMemUsage, "host1"));
usageManager.saveCurrentSlaveUsage(new SingularitySlaveUsageWithId(highCpuUsage, "host2"));

SingularityTaskId host1Task = null;
SingularityTaskId host2Task = null;
System.out.println(taskManager.getActiveTaskIds());
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
if (taskId.getSanitizedHost().equals("host1")) {
host1Task = taskId;
} else if (taskId.getSanitizedHost().equals("host2")) {
host2Task = taskId;
}
}

statusUpdate(taskManager.getTask(host1Task).get(), TaskState.TASK_STARTING, Optional.of(host1Task.getStartedAt()));
statusUpdate(taskManager.getTask(host2Task).get(), TaskState.TASK_STARTING, Optional.of(host2Task.getStartedAt()));
// task 1 using 3G mem
MesosTaskMonitorObject t1u1 = getTaskMonitor(host1Task.getId(), 2, TimeUnit.MILLISECONDS.toSeconds(host1Task.getStartedAt()) + 5, 199000);
// task 2 using 2G mem
MesosTaskMonitorObject t2u1 = getTaskMonitor(host2Task.getId(), 5, TimeUnit.MILLISECONDS.toSeconds(host2Task.getStartedAt()) + 5, 63333);
mesosClient.setSlaveResourceUsage("host1", Arrays.asList(t1u1));
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, 10, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 200000, 0, 1000, 0, 0, 0, 10, 0, 0, 0, 0)
);

mesosClient.setSlaveResourceUsage("host2", Arrays.asList(t2u1));
mesosClient.setSlaveMetricsSnapshot(
"host2",
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, 200000, 0, 30000, 0, 0, 0, 15, 0, 0, 0, 0)
);

usagePoller.runActionOnPoll();

System.out.println(taskManager.getCleanupTaskIds().toString());

// First task is cleaned up
Assertions.assertEquals(TaskCleanupType.REBALANCE_MEMORY_USAGE, taskManager.getTaskCleanup(host1Task.getId()).get().getCleanupType());
// Second task is not cleaned up because it is a cpu shuffle
Assertions.assertFalse(taskManager.getTaskCleanup(host2Task.getId()).isPresent());
} finally {
configuration.setShuffleTasksForOverloadedSlaves(false);
}
}

@Test
public void itCreatesTaskCleanupsWhenAMachineIsOverloadedOnCpu() {
try {
Expand Down