use of org.joda.time.Duration in project druid by druid-io.
the class RetryPolicyFactoryTest method testMakeRetryPolicy.
@Test
public void testMakeRetryPolicy() {
RetryPolicyConfig config = new RetryPolicyConfig().setMinWait(new Period("PT1S")).setMaxWait(new Period("PT10S")).setMaxRetryCount(1);
RetryPolicyFactory retryPolicyFactory = new RetryPolicyFactory(config);
RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
Assert.assertEquals(new Duration("PT1S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertTrue(retryPolicy.hasExceededRetryThreshold());
}
use of org.joda.time.Duration in project druid by druid-io.
the class RetryPolicyTest method testGetAndIncrementRetryDelay.
@Test
public void testGetAndIncrementRetryDelay() throws Exception {
RetryPolicy retryPolicy = new RetryPolicy(new RetryPolicyConfig().setMinWait(new Period("PT1S")).setMaxWait(new Period("PT10S")).setMaxRetryCount(6));
Assert.assertEquals(new Duration("PT1S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(new Duration("PT2S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(new Duration("PT4S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(new Duration("PT8S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(new Duration("PT10S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(new Duration("PT10S"), retryPolicy.getAndIncrementRetryDelay());
Assert.assertEquals(null, retryPolicy.getAndIncrementRetryDelay());
Assert.assertTrue(retryPolicy.hasExceededRetryThreshold());
}
use of org.joda.time.Duration in project druid by druid-io.
the class PendingTaskBasedWorkerResourceManagementStrategy method doTerminate.
@Override
public boolean doTerminate(WorkerTaskRunner runner) {
Collection<ImmutableWorkerInfo> zkWorkers = runner.getWorkers();
synchronized (lock) {
final WorkerBehaviorConfig workerConfig = workerConfigRef.get();
if (workerConfig == null) {
log.warn("No workerConfig available, cannot terminate workers.");
return false;
}
if (!currentlyProvisioning.isEmpty()) {
log.debug("Already provisioning nodes, Not Terminating any nodes.");
return false;
}
boolean didTerminate = false;
final Collection<String> workerNodeIds = getWorkerNodeIDs(runner.getLazyWorkers(), workerConfig);
final Set<String> stillExisting = Sets.newHashSet();
for (String s : currentlyTerminating) {
if (workerNodeIds.contains(s)) {
stillExisting.add(s);
}
}
currentlyTerminating.clear();
currentlyTerminating.addAll(stillExisting);
if (currentlyTerminating.isEmpty()) {
final int maxWorkersToTerminate = maxWorkersToTerminate(zkWorkers, workerConfig);
final Predicate<ImmutableWorkerInfo> isLazyWorker = ResourceManagementUtil.createLazyWorkerPredicate(config);
final List<String> laziestWorkerIps = Lists.newArrayList(Collections2.transform(runner.markWorkersLazy(isLazyWorker, maxWorkersToTerminate), new Function<Worker, String>() {
@Override
public String apply(Worker zkWorker) {
return zkWorker.getIp();
}
}));
if (laziestWorkerIps.isEmpty()) {
log.debug("Found no lazy workers");
} else {
log.info("Terminating %,d lazy workers: %s", laziestWorkerIps.size(), Joiner.on(", ").join(laziestWorkerIps));
final AutoScalingData terminated = workerConfig.getAutoScaler().terminate(laziestWorkerIps);
if (terminated != null) {
currentlyTerminating.addAll(terminated.getNodeIds());
lastTerminateTime = new DateTime();
scalingStats.addTerminateEvent(terminated);
didTerminate = true;
}
}
} else {
Duration durSinceLastTerminate = new Duration(lastTerminateTime, new DateTime());
log.info("%s terminating. Current wait time: %s", currentlyTerminating, durSinceLastTerminate);
if (durSinceLastTerminate.isLongerThan(config.getMaxScalingDuration().toStandardDuration())) {
log.makeAlert("Worker node termination taking too long!").addData("millisSinceLastTerminate", durSinceLastTerminate.getMillis()).addData("terminatingCount", currentlyTerminating.size()).emit();
currentlyTerminating.clear();
}
}
return didTerminate;
}
}
use of org.joda.time.Duration in project druid by druid-io.
the class SimpleWorkerResourceManagementStrategy method doProvision.
protected boolean doProvision(WorkerTaskRunner runner) {
Collection<? extends TaskRunnerWorkItem> pendingTasks = runner.getPendingTasks();
Collection<ImmutableWorkerInfo> workers = getWorkers(runner);
synchronized (lock) {
boolean didProvision = false;
final WorkerBehaviorConfig workerConfig = workerConfigRef.get();
if (workerConfig == null || workerConfig.getAutoScaler() == null) {
log.warn("No workerConfig available, cannot provision new workers.");
return false;
}
final Predicate<ImmutableWorkerInfo> isValidWorker = ResourceManagementUtil.createValidWorkerPredicate(config);
final int currValidWorkers = Collections2.filter(workers, isValidWorker).size();
final List<String> workerNodeIds = workerConfig.getAutoScaler().ipToIdLookup(Lists.newArrayList(Iterables.transform(workers, new Function<ImmutableWorkerInfo, String>() {
@Override
public String apply(ImmutableWorkerInfo input) {
return input.getWorker().getIp();
}
})));
currentlyProvisioning.removeAll(workerNodeIds);
updateTargetWorkerCount(workerConfig, pendingTasks, workers);
int want = targetWorkerCount - (currValidWorkers + currentlyProvisioning.size());
while (want > 0) {
final AutoScalingData provisioned = workerConfig.getAutoScaler().provision();
final List<String> newNodes;
if (provisioned == null || (newNodes = provisioned.getNodeIds()).isEmpty()) {
break;
} else {
currentlyProvisioning.addAll(newNodes);
lastProvisionTime = new DateTime();
scalingStats.addProvisionEvent(provisioned);
want -= provisioned.getNodeIds().size();
didProvision = true;
}
}
if (!currentlyProvisioning.isEmpty()) {
Duration durSinceLastProvision = new Duration(lastProvisionTime, new DateTime());
log.info("%s provisioning. Current wait time: %s", currentlyProvisioning, durSinceLastProvision);
if (durSinceLastProvision.isLongerThan(config.getMaxScalingDuration().toStandardDuration())) {
log.makeAlert("Worker node provisioning taking too long!").addData("millisSinceLastProvision", durSinceLastProvision.getMillis()).addData("provisioningCount", currentlyProvisioning.size()).emit();
workerConfig.getAutoScaler().terminateWithIds(Lists.newArrayList(currentlyProvisioning));
currentlyProvisioning.clear();
}
}
return didProvision;
}
}
use of org.joda.time.Duration in project druid by druid-io.
the class BaseQuery method getDuration.
@Override
public Duration getDuration() {
if (duration == null) {
Duration totalDuration = new Duration(0);
for (Interval interval : querySegmentSpec.getIntervals()) {
if (interval != null) {
totalDuration = totalDuration.plus(interval.toDuration());
}
}
duration = totalDuration;
}
return duration;
}
Aggregations