Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
fix scalar resource accounting for single lease mode (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
corindwyer authored Jan 22, 2020
1 parent b15bc32 commit 66ecaca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,25 @@ private void removeResourcesOf(TaskRequest request) {
currTotalNetworkMbps -= request.getNetworkMbps();
final Map<String, Double> scalarRequests = request.getScalarRequests();
if(scalarRequests != null && !scalarRequests.isEmpty()) {
for(Map.Entry<String, Double> entry: scalarRequests.entrySet()) {
for (Map.Entry<String, Double> entry : scalarRequests.entrySet()) {
Double oldVal = currTotalScalars.get(entry.getKey());
if(oldVal != null) {
double newVal = oldVal - entry.getValue();
if(newVal < 0.0) {
logger.warn(hostname + ": Scalar resource " + entry.getKey() + " is " + newVal + " after removing " +
entry.getValue() + " from task " + request.getId());
currTotalScalars.put(entry.getKey(), 0.0);
if (singleLeaseMode) {
// resources must be able to be negative in single lease mode
if (oldVal == null) {
oldVal = 0.0;
}
currTotalScalars.put(entry.getKey(), oldVal - entry.getValue());
} else {
if (oldVal != null) {
double newVal = oldVal - entry.getValue();
if (newVal < 0.0) {
logger.warn(hostname + ": Scalar resource " + entry.getKey() + " is " + newVal + " after removing " +
entry.getValue() + " from task " + request.getId());
currTotalScalars.put(entry.getKey(), 0.0);
} else {
currTotalScalars.put(entry.getKey(), newVal);
}
}
else
currTotalScalars.put(entry.getKey(), newVal);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
public class ScalarResourceTests {

private TaskScheduler getScheduler() {
return getScheduler(false);
}

private TaskScheduler getScheduler(boolean singleLeaseMode) {
return new TaskScheduler.Builder()
.withLeaseOfferExpirySecs(1000000)
.withSingleOfferPerVM(singleLeaseMode)
.withLeaseRejectAction(new Action1<VirtualMachineLease>() {
@Override
public void call(VirtualMachineLease virtualMachineLease) {
Expand Down Expand Up @@ -131,4 +136,18 @@ public void testMultipleScalarResources() throws Exception {
}
Assert.assertEquals((int)(scalars2OnHost*2.0), tasksAssigned);
}

@Test
public void testInsufficientScalarResourcesWithSingleLeaseMode() {
final TaskScheduler scheduler = getScheduler(true);
final double scalarsOnHost=4.0;
final TaskRequest task = TaskRequestProvider.getTaskRequest(null, 1, 100, 1, 1, 1, null, null, null, Collections.singletonMap("gpu", scalarsOnHost+1.0));
final VirtualMachineLease host1 = LeaseProvider.getLeaseOffer("host1", 4.0, 4000.0, 100, 1024,
Collections.singletonList(new VirtualMachineLease.Range(1, 10)), null, Collections.singletonMap("gpu", scalarsOnHost));
final SchedulingResult result = scheduler.scheduleOnce(Collections.singletonList(task), Collections.singletonList(host1));
Assert.assertEquals(1, result.getFailures().size());
Assert.assertEquals(0, result.getResultMap().size());
Assert.assertEquals(VMResource.Other, result.getFailures().values().iterator().next().get(0).getFailures().get(0).getResource());
System.out.println(result.getFailures().values().iterator().next().get(0).getFailures().get(0));
}
}

0 comments on commit 66ecaca

Please sign in to comment.