aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Make the offer hold jitter window configurable.
Date Wed, 10 Sep 2014 22:47:23 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 373a3928f -> cc701362a


Make the offer hold jitter window configurable.

Bugs closed: AURORA-313

Reviewed at https://reviews.apache.org/r/25398/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/cc701362
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/cc701362
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/cc701362

Branch: refs/heads/master
Commit: cc701362a475b50740937887fa96707179f73a36
Parents: 373a392
Author: Joshua Cohen <jcohen@twopensource.com>
Authored: Wed Sep 10 15:38:56 2014 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Wed Sep 10 15:38:56 2014 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/async/AsyncModule.java     | 29 ++++----
 .../async/RandomJitterReturnDelay.java          | 50 +++++++++++++
 .../async/RandomJitterReturnDelayTest.java      | 77 ++++++++++++++++++++
 3 files changed, 140 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/cc701362/src/main/java/org/apache/aurora/scheduler/async/AsyncModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/async/AsyncModule.java b/src/main/java/org/apache/aurora/scheduler/async/AsyncModule.java
index 5a38a1f..e72961a 100644
--- a/src/main/java/org/apache/aurora/scheduler/async/AsyncModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/async/AsyncModule.java
@@ -33,6 +33,7 @@ import com.google.inject.PrivateModule;
 import com.google.inject.TypeLiteral;
 import com.twitter.common.args.Arg;
 import com.twitter.common.args.CmdLine;
+import com.twitter.common.args.constraints.NotNegative;
 import com.twitter.common.args.constraints.Positive;
 import com.twitter.common.quantity.Amount;
 import com.twitter.common.quantity.Time;
@@ -92,9 +93,16 @@ public class AsyncModule extends AbstractModule {
 
   @CmdLine(name = "min_offer_hold_time",
       help = "Minimum amount of time to hold a resource offer before declining.")
+  @NotNegative
   private static final Arg<Amount<Integer, Time>> MIN_OFFER_HOLD_TIME =
       Arg.create(Amount.of(5, Time.MINUTES));
 
+  @CmdLine(name = "offer_hold_jitter_window",
+      help = "Maximum amount of random jitter to add to the offer hold time window.")
+  @NotNegative
+  private static final Arg<Amount<Integer, Time>> OFFER_HOLD_JITTER_WINDOW =
+      Arg.create(Amount.of(1, Time.MINUTES));
+
   @CmdLine(name = "history_prune_threshold",
       help = "Time after which the scheduler will prune terminated task history.")
   private static final Arg<Amount<Long, Time>> HISTORY_PRUNE_THRESHOLD =
@@ -238,7 +246,11 @@ public class AsyncModule extends AbstractModule {
     install(new PrivateModule() {
       @Override
       protected void configure() {
-        bind(OfferReturnDelay.class).to(RandomJitterReturnDelay.class);
+        bind(OfferReturnDelay.class).toInstance(
+            new RandomJitterReturnDelay(
+                MIN_OFFER_HOLD_TIME.get().as(Time.MILLISECONDS),
+                OFFER_HOLD_JITTER_WINDOW.get().as(Time.MILLISECONDS),
+                new Random.SystemRandom(new java.util.Random())));
         bind(ScheduledExecutorService.class).toInstance(executor);
         bind(OfferQueue.class).to(OfferQueueImpl.class);
         bind(OfferQueueImpl.class).in(Singleton.class);
@@ -313,19 +325,4 @@ public class AsyncModule extends AbstractModule {
         });
         PubsubEventModule.bindSubscriber(binder, TaskScheduler.class);
   }
-
-  /**
-   * Returns offers after a random duration within a fixed window.
-   */
-  private static class RandomJitterReturnDelay implements OfferReturnDelay {
-    private static final int JITTER_WINDOW_MS = Amount.of(1, Time.MINUTES).as(Time.MILLISECONDS);
-
-    private final int minHoldTimeMs = MIN_OFFER_HOLD_TIME.get().as(Time.MILLISECONDS);
-    private final Random random = new Random.SystemRandom(new java.util.Random());
-
-    @Override
-    public Amount<Integer, Time> get() {
-      return Amount.of(minHoldTimeMs + random.nextInt(JITTER_WINDOW_MS), Time.MILLISECONDS);
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/cc701362/src/main/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelay.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelay.java
b/src/main/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelay.java
new file mode 100644
index 0000000..1a65a34
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelay.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.async;
+
+import java.util.Objects;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import com.twitter.common.quantity.Amount;
+import com.twitter.common.quantity.Time;
+import com.twitter.common.util.Random;
+
+import org.apache.aurora.scheduler.async.OfferQueue.OfferReturnDelay;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Returns offers after a random duration within a fixed window.
+ */
+@VisibleForTesting
+class RandomJitterReturnDelay implements OfferReturnDelay {
+  private final int minHoldTimeMs;
+  private final int maxJitterWindowMs;
+  private final Random random;
+
+  RandomJitterReturnDelay(int minHoldTimeMs, int maxJitterWindowMs, Random random) {
+    checkArgument(minHoldTimeMs >= 0);
+    checkArgument(maxJitterWindowMs >= 0);
+
+    this.minHoldTimeMs = minHoldTimeMs;
+    this.maxJitterWindowMs = maxJitterWindowMs;
+    this.random = Objects.requireNonNull(random);
+  }
+
+  @Override
+  public Amount<Integer, Time> get() {
+    return Amount.of(minHoldTimeMs + random.nextInt(maxJitterWindowMs), Time.MILLISECONDS);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/cc701362/src/test/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelayTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelayTest.java
b/src/test/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelayTest.java
new file mode 100644
index 0000000..1aed40c
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/async/RandomJitterReturnDelayTest.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.async;
+
+import com.twitter.common.testing.easymock.EasyMockTest;
+import com.twitter.common.util.Random;
+
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+public class RandomJitterReturnDelayTest extends EasyMockTest {
+  private void assertRandomJitterReturnDelay(
+      int minHoldTimeMs,
+      int jitterWindowMs,
+      boolean shouldThrow) {
+
+    int randomValue = 123;
+
+    Random mockRandom = control.createMock(Random.class);
+
+    if (!shouldThrow) {
+      expect(mockRandom.nextInt(jitterWindowMs)).andReturn(randomValue);
+    }
+
+    control.replay();
+
+    assertEquals(
+        minHoldTimeMs + randomValue,
+        new RandomJitterReturnDelay(
+            minHoldTimeMs,
+            jitterWindowMs,
+            mockRandom).get().getValue().intValue());
+  }
+
+  @Test
+  public void testRandomJitterReturnDelay() throws Exception {
+    assertRandomJitterReturnDelay(100, 200, false);
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testNegativeHoldTimeThrowsIllegalArgumentException() throws Exception {
+    assertRandomJitterReturnDelay(-1, 200, true);
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testNegativeWindowThrowsIllegalArgumentException() throws Exception {
+    assertRandomJitterReturnDelay(100, -1, true);
+  }
+
+  @Test
+  public void testZeroHoldTime() throws Exception {
+    assertRandomJitterReturnDelay(0, 200, false);
+  }
+
+  @Test
+  public void testZeroWindow() throws Exception {
+    assertRandomJitterReturnDelay(100, 0, false);
+  }
+
+  @Test
+  public void testZeroHoldTimeZeroWindow() throws Exception {
+    assertRandomJitterReturnDelay(0, 0, false);
+  }
+}


Mime
View raw message