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.
+522 鈭128
Diff settings

Always

Just for now

@@ -1,22 +1,40 @@
package com.hubspot.singularity;
import java.util.Map;
import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SingularitySlaveUsage {
public static final String CPU_USED = "cpusUsed";
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> memoryMbTotal;
private final Optional<Double> cpuTotal;
private final Map<RequestType, Map<String, Number>> usagePerRequestType;
@JsonCreator
public SingularitySlaveUsage(@JsonProperty("memoryBytesUsed") long memoryBytesUsed, @JsonProperty("timestamp") long timestamp, @JsonProperty("cpusUsed") double cpusUsed,
@JsonProperty("numTasks") int numTasks) {
public SingularitySlaveUsage(@JsonProperty("memoryBytesUsed") long memoryBytesUsed,
@JsonProperty("timestamp") long timestamp,
@JsonProperty("cpusUsed") double cpusUsed,
@JsonProperty("numTasks") int numTasks,
@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.memoryMbTotal = memoryMbTotal;
this.cpuTotal = cpuTotal;
this.usagePerRequestType = usagePerRequestType;
}
public long getMemoryBytesUsed() {
@@ -35,6 +53,30 @@ public int getNumTasks() {
return numTasks;
}
public Optional<Long> getMemoryBytesTotal() {
return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get() * BYTES_PER_MEGABYTE) : Optional.empty();
}
public Optional<Long> getMemoryMbTotal() {
return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get()) : Optional.empty();
}
public Optional<Double> getCpuTotal() {
return cpuTotal;
}
public Map<RequestType, Map<String, Number>> getUsagePerRequestType() {
return usagePerRequestType;
}
public double getCpusUsedForRequestType(RequestType type) {

This comment has been minimized.

@ssalinas

ssalinas Apr 20, 2017

Member

this and getMemBytesUsedForRequestType are unused methods

@ssalinas

ssalinas Apr 20, 2017

Member

this and getMemBytesUsedForRequestType are unused methods

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 getMemBytesUsedForRequestType(RequestType type) {
return usagePerRequestType.get(type).get(MEMORY_BYTES_USED).longValue();
}
@Override
public String toString() {
return "SingularitySlaveUsage [memoryBytesUsed=" + memoryBytesUsed + ", numTasks=" + numTasks + ", timestamp=" + timestamp + ", cpusUsed=" + cpusUsed + "]";
@@ -8,7 +8,7 @@
private final String slaveId;
public SingularitySlaveUsageWithId(SingularitySlaveUsage usage, String slaveId) {
super(usage.getMemoryBytesUsed(), usage.getTimestamp(), usage.getCpusUsed(), usage.getNumTasks());
super(usage.getMemoryBytesUsed(), usage.getTimestamp(), usage.getCpusUsed(), usage.getNumTasks(), usage.getMemoryMbTotal(), usage.getCpuTotal(), usage.getUsagePerRequestType());
this.slaveId = slaveId;
}
@@ -158,10 +158,9 @@ public int compare(SingularityTaskUsage o1, SingularityTaskUsage o2) {
return children;
}
public List<SingularitySlaveUsageWithId> getAllCurrentSlaveUsage() {
List<String> slaves = getSlavesWithUsage();
List<String> paths = new ArrayList<>(slaves.size());
for (String slaveId : slaves) {
public List<SingularitySlaveUsageWithId> getCurrentSlaveUsages(List<String> slaveIds) {
List<String> paths = new ArrayList<>(slaveIds.size());
for (String slaveId : slaveIds) {
paths.add(getCurrentSlaveUsagePath(slaveId));
}
@@ -174,6 +173,10 @@ public int compare(SingularityTaskUsage o1, SingularityTaskUsage o2) {
return slaveUsageWithIds;
}
public List<SingularitySlaveUsageWithId> getAllCurrentSlaveUsage() {
return getCurrentSlaveUsages(getSlavesWithUsage());
}
public List<Long> getSlaveUsageTimestamps(String slaveId) {
List<String> timestampStrings = getChildren(getSlaveUsageHistoryPath(slaveId));
List<Long> timestamps = new ArrayList<>(timestampStrings.size());
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.