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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better task balancing #1482

Merged
merged 73 commits into from Jun 8, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+19 鈭20
Diff settings

Always

Just for now

Viewing a subset of changes. View all

specifiy mb vs bytes

  • Loading branch information...
darcatron committed Apr 14, 2017
commit b56d6f8f63ff667fe56f0584e10bf3da9c9d04a7
@@ -9,14 +9,14 @@
public class SingularitySlaveUsage {
public static final String CPU_USED = "cpusUsed";
public static final String MEMORY_USED = "memoryRssBytes";
public static final String MEMORY_BYTES_USED = "memoryRssBytes";
public static final long BYTES_PER_MEGABYTE = 1024L * 1024L;

This comment has been minimized.

@ssalinas

ssalinas Apr 20, 2017

Member

was about to comment that there must be some type of easy class/enum for this like there is with TimeUnit, but apparently there isn't... weird...

@ssalinas

ssalinas Apr 20, 2017

Member

was about to comment that there must be some type of easy class/enum for this like there is with TimeUnit, but apparently there isn't... weird...

This comment has been minimized.

@darcatron

darcatron Apr 20, 2017

Contributor

Yeah, I was sad to see there wasn't a lib method for this too 馃槩

@darcatron

darcatron Apr 20, 2017

Contributor

Yeah, I was sad to see there wasn't a lib method for this too 馃槩

private final long memoryBytesUsed;
private final int numTasks;
private final long timestamp;
private final double cpusUsed;
private final Optional<Long> memoryTotal;
private final Optional<Long> memoryMbTotal;
private final Optional<Double> cpuTotal;
private final Map<RequestType, Map<String, Number>> usagePerRequestType;
@@ -25,14 +25,14 @@ public SingularitySlaveUsage(@JsonProperty("memoryBytesUsed") long memoryBytesUs
@JsonProperty("timestamp") long timestamp,
@JsonProperty("cpusUsed") double cpusUsed,
@JsonProperty("numTasks") int numTasks,
@JsonProperty("memoryTotal") Optional<Long> memoryTotal,
@JsonProperty("memoryMbTotal") Optional<Long> memoryMbTotal,
@JsonProperty("cpuTotal") Optional<Double> cpuTotal,
@JsonProperty("usagePerRequestType") Map<RequestType, Map<String, Number>> usagePerRequestType) {
this.memoryBytesUsed = memoryBytesUsed;
this.timestamp = timestamp;
this.cpusUsed = cpusUsed;
this.numTasks = numTasks;
this.memoryTotal = memoryTotal;
this.memoryMbTotal = memoryMbTotal;
this.cpuTotal = cpuTotal;
this.usagePerRequestType = usagePerRequestType;
}
@@ -54,11 +54,11 @@ public int getNumTasks() {
}
public Optional<Long> getMemoryBytesTotal() {
if (memoryTotal.isPresent()) {
return Optional.of(memoryTotal.get() * BYTES_PER_MEGABYTE);
}
return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get() * BYTES_PER_MEGABYTE) : Optional.empty();
}
return Optional.empty();
public Optional<Long> getMemoryMbTotal() {
return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get()) : Optional.empty();
}
public Optional<Double> getCpuTotal() {
@@ -73,8 +73,8 @@ public double getCpusUsedForRequestType(RequestType type) {
return usagePerRequestType.get(type).get(CPU_USED).doubleValue();

This comment has been minimized.

@ssalinas

ssalinas Apr 20, 2017

Member

Maybe another enum is more appropriate for CPU_USED/MEMORY_BYTES_USED ?

@ssalinas

ssalinas Apr 20, 2017

Member

Maybe another enum is more appropriate for CPU_USED/MEMORY_BYTES_USED ?

This comment has been minimized.

@darcatron

darcatron Apr 20, 2017

Contributor

agreed, mapping would be clearer then too 馃憤

@darcatron

darcatron Apr 20, 2017

Contributor

agreed, mapping would be clearer then too 馃憤

}
public long getMemUsedForRequestType(RequestType type) {
return usagePerRequestType.get(type).get(MEMORY_USED).longValue();
public long getMemBytesUsedForRequestType(RequestType type) {
return usagePerRequestType.get(type).get(MEMORY_BYTES_USED).longValue();
}
@Override
@@ -8,7 +8,7 @@
private final String slaveId;
public SingularitySlaveUsageWithId(SingularitySlaveUsage usage, String slaveId) {
super(usage.getMemoryBytesUsed(), usage.getTimestamp(), usage.getCpusUsed(), usage.getNumTasks(), usage.getMemoryBytesTotal(), usage.getCpuTotal(), usage.getUsagePerRequestType());
super(usage.getMemoryBytesUsed(), usage.getTimestamp(), usage.getCpusUsed(), usage.getNumTasks(), usage.getMemoryMbTotal(), usage.getCpuTotal(), usage.getUsagePerRequestType());
this.slaveId = slaveId;
}
@@ -58,7 +58,7 @@ public void runActionOnPoll() {
Map<RequestType, Map<String, Number>> usagesPerRequestType = new HashMap<>();

This comment has been minimized.

@ssalinas

ssalinas Apr 20, 2017

Member

wouldn't we want this to be per-slave, not overall?

@ssalinas

ssalinas Apr 20, 2017

Member

wouldn't we want this to be per-slave, not overall?

This comment has been minimized.

@darcatron

darcatron Apr 20, 2017

Contributor

This should be per slave. This poller loops through each slave and creates a new SingularitySlaveUsage with the stats for that slave

@darcatron

darcatron Apr 20, 2017

Contributor

This should be per slave. This poller loops through each slave and creates a new SingularitySlaveUsage with the stats for that slave

for (SingularitySlave slave : usageHelper.getSlavesToTrackUsageFor()) {
Optional<Long> memoryTotal = Optional.empty();
Optional<Long> memoryMbTotal = Optional.empty();
Optional<Double> cpuTotal = Optional.empty();
long memoryBytesUsed = 0;
double cpusUsed = 0;
@@ -99,11 +99,11 @@ public void runActionOnPoll() {
!slave.getResources().get().getNumCpus().isPresent()) {
LOG.debug("Could not find slave or resources for slave {}", slave.getId());
} else {
memoryTotal = Optional.of(slave.getResources().get().getMemoryMegaBytes().get().longValue());
memoryMbTotal = Optional.of(slave.getResources().get().getMemoryMegaBytes().get().longValue());
cpuTotal = Optional.of(slave.getResources().get().getNumCpus().get().doubleValue());
}
SingularitySlaveUsage slaveUsage = new SingularitySlaveUsage(memoryBytesUsed, now, cpusUsed, allTaskUsage.size(), memoryTotal, cpuTotal, usagesPerRequestType);
SingularitySlaveUsage slaveUsage = new SingularitySlaveUsage(memoryBytesUsed, now, cpusUsed, allTaskUsage.size(), memoryMbTotal, cpuTotal, usagesPerRequestType);
List<Long> slaveTimestamps = usageManager.getSlaveUsageTimestamps(slave.getId());
if (slaveTimestamps.size() + 1 > configuration.getNumUsageToKeep()) {
usageManager.deleteSpecificSlaveUsage(slave.getId(), slaveTimestamps.get(0));
@@ -126,26 +126,25 @@ private SingularityTaskUsage getUsage(MesosTaskMonitorObject taskUsage) {
}
private RequestType getRequestType(MesosTaskMonitorObject task) {
//todo: check optional.get()
return requestManager.getRequest(SingularityTaskId.valueOf(task.getSource()).getRequestId()).get().getRequest().getRequestType();
}
private void updateUsagesPerRequestType(Map<RequestType, Map<String, Number>> usagePerRequestType, RequestType type, long memUsed, double cpuUsed) {
private void updateUsagesPerRequestType(Map<RequestType, Map<String, Number>> usagePerRequestType, RequestType type, long memBytesUsed, double cpuUsed) {
if (usagePerRequestType.containsKey(type)) {
long oldMemUsed = 0L;
double oldCpuUsed = 0;
if (usagePerRequestType.get(type).containsKey(SingularitySlaveUsage.MEMORY_USED)) {
oldMemUsed = usagePerRequestType.get(type).get(SingularitySlaveUsage.MEMORY_USED).longValue();
if (usagePerRequestType.get(type).containsKey(SingularitySlaveUsage.MEMORY_BYTES_USED)) {
oldMemUsed = usagePerRequestType.get(type).get(SingularitySlaveUsage.MEMORY_BYTES_USED).longValue();
}
if (usagePerRequestType.get(type).containsKey(SingularitySlaveUsage.CPU_USED)) {
oldCpuUsed = usagePerRequestType.get(type).get(SingularitySlaveUsage.CPU_USED).doubleValue();
}
usagePerRequestType.get(type).put(SingularitySlaveUsage.MEMORY_USED, oldMemUsed + memUsed);
usagePerRequestType.get(type).put(SingularitySlaveUsage.MEMORY_BYTES_USED, oldMemUsed + memBytesUsed);
usagePerRequestType.get(type).put(SingularitySlaveUsage.CPU_USED, oldCpuUsed + cpuUsed);
} else {
usagePerRequestType.put(type, ImmutableMap.of(SingularitySlaveUsage.MEMORY_USED, memUsed));
usagePerRequestType.put(type, ImmutableMap.of(SingularitySlaveUsage.MEMORY_BYTES_USED, memBytesUsed));
usagePerRequestType.put(type, ImmutableMap.of(SingularitySlaveUsage.CPU_USED, cpuUsed));
}
}
ProTip! Use n and p to navigate between commits in a pull request.