-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pending task based resource management strategy (#2086)
- Loading branch information
1 parent
bf5e5e7
commit c29cb7d
Showing
23 changed files
with
1,437 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...java/io/druid/indexing/overlord/autoscaling/AbstractWorkerResourceManagementStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you 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 io.druid.indexing.overlord.autoscaling; | ||
|
||
import com.metamx.common.concurrent.ScheduledExecutors; | ||
import com.metamx.emitter.EmittingLogger; | ||
import io.druid.granularity.PeriodGranularity; | ||
import io.druid.indexing.overlord.WorkerTaskRunner; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.Duration; | ||
import org.joda.time.Period; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
*/ | ||
public abstract class AbstractWorkerResourceManagementStrategy implements ResourceManagementStrategy<WorkerTaskRunner> | ||
{ | ||
private static final EmittingLogger log = new EmittingLogger(AbstractWorkerResourceManagementStrategy.class); | ||
|
||
private final ResourceManagementSchedulerConfig resourceManagementSchedulerConfig; | ||
private final ScheduledExecutorService exec; | ||
private final Object lock = new Object(); | ||
|
||
private volatile boolean started = false; | ||
|
||
protected AbstractWorkerResourceManagementStrategy( | ||
ResourceManagementSchedulerConfig resourceManagementSchedulerConfig, | ||
ScheduledExecutorService exec | ||
) | ||
{ | ||
this.resourceManagementSchedulerConfig = resourceManagementSchedulerConfig; | ||
this.exec = exec; | ||
} | ||
|
||
@Override | ||
public void startManagement(final WorkerTaskRunner runner) | ||
{ | ||
synchronized (lock) { | ||
if (started) { | ||
return; | ||
} | ||
|
||
log.info("Started Resource Management Scheduler"); | ||
|
||
ScheduledExecutors.scheduleAtFixedRate( | ||
exec, | ||
resourceManagementSchedulerConfig.getProvisionPeriod().toStandardDuration(), | ||
new Runnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
// Any Errors are caught by ScheduledExecutors | ||
doProvision(runner); | ||
} | ||
} | ||
); | ||
|
||
// Schedule termination of worker nodes periodically | ||
Period period = resourceManagementSchedulerConfig.getTerminatePeriod(); | ||
PeriodGranularity granularity = new PeriodGranularity( | ||
period, | ||
resourceManagementSchedulerConfig.getOriginTime(), | ||
null | ||
); | ||
final long startTime = granularity.next(granularity.truncate(new DateTime().getMillis())); | ||
|
||
ScheduledExecutors.scheduleAtFixedRate( | ||
exec, | ||
new Duration(System.currentTimeMillis(), startTime), | ||
resourceManagementSchedulerConfig.getTerminatePeriod().toStandardDuration(), | ||
new Runnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
// Any Errors are caught by ScheduledExecutors | ||
doTerminate(runner); | ||
} | ||
} | ||
); | ||
|
||
started = true; | ||
|
||
} | ||
} | ||
|
||
abstract boolean doTerminate(WorkerTaskRunner runner); | ||
|
||
abstract boolean doProvision(WorkerTaskRunner runner); | ||
|
||
@Override | ||
public void stopManagement() | ||
{ | ||
synchronized (lock) { | ||
if (!started) { | ||
return; | ||
} | ||
log.info("Stopping Resource Management Scheduler"); | ||
exec.shutdown(); | ||
started = false; | ||
} | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...o/druid/indexing/overlord/autoscaling/PendingTaskBasedWorkerResourceManagementConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you 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 io.druid.indexing.overlord.autoscaling; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.joda.time.Period; | ||
|
||
/** | ||
*/ | ||
public class PendingTaskBasedWorkerResourceManagementConfig extends SimpleWorkerResourceManagementConfig | ||
{ | ||
@JsonProperty | ||
private int maxScalingStep = 10; | ||
|
||
|
||
public int getMaxScalingStep() | ||
{ | ||
return maxScalingStep; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setMaxScalingStep(int maxScalingStep) | ||
{ | ||
this.maxScalingStep = maxScalingStep; | ||
return this; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setWorkerIdleTimeout(Period workerIdleTimeout) | ||
{ | ||
super.setWorkerIdleTimeout(workerIdleTimeout); | ||
return this; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setMaxScalingDuration(Period maxScalingDuration) | ||
{ | ||
super.setMaxScalingDuration(maxScalingDuration); | ||
return this; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setNumEventsToTrack(int numEventsToTrack) | ||
{ | ||
super.setNumEventsToTrack(numEventsToTrack); | ||
return this; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setWorkerVersion(String workerVersion) | ||
{ | ||
super.setWorkerVersion(workerVersion); | ||
return this; | ||
} | ||
|
||
public PendingTaskBasedWorkerResourceManagementConfig setPendingTaskTimeout(Period pendingTaskTimeout) | ||
{ | ||
super.setPendingTaskTimeout(pendingTaskTimeout); | ||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.