Skip to content

Commit 0c05cb3

Browse files
sboryanavina
authored andcommitted
SAMZA-1309; Debounce time config
Author: Boris Shkolnik <[email protected]> Reviewers: Navina Ramesh <[email protected]> Closes apache#203 from sborya/DebounceConfig
1 parent 8f1609d commit 0c05cb3

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

docs/learn/documentation/versioned/jobs/configuration-table.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,18 @@ <h1>Samza Configuration Reference</h1>
461461
How long each processor will wait for all the processors to report acceptance of the new job model before rolling back.
462462
</td>
463463
</tr>
464+
<tr>
465+
<td class="property" id="job.debounce.time.ms">job.debounce.time.ms</td>
466+
<td class="default"> 2000 </td>
467+
<td class="description">
468+
How long the Leader processor will wait before recalculating the JobModel on change of registered processors.
469+
</td>
470+
</tr>
464471
<tr>
465472
<th colspan="3" class="section" id="task"><a href="../api/overview.html">Task configuration</a></th>
466473
</tr>
467474

475+
468476
<tr>
469477
<td class="property" id="task-class">task.class</td>
470478
<td class="default"></td>

samza-core/src/main/java/org/apache/samza/zk/ScheduleAfterDebounceTime.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public class ScheduleAfterDebounceTime {
4848
// Action name when the Processor membership changes
4949
public static final String ON_PROCESSOR_CHANGE = "OnProcessorChange";
5050

51-
public static final int DEBOUNCE_TIME_MS = 2000;
52-
5351
private final ScheduledTaskFailureCallback scheduledTaskFailureCallback;
5452

5553
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(

samza-core/src/main/java/org/apache/samza/zk/ZkJobCoordinator.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
*/
1919
package org.apache.samza.zk;
2020

21+
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.List;
2124
import org.apache.samza.config.ApplicationConfig;
2225
import org.apache.samza.config.Config;
2326
import org.apache.samza.config.ConfigException;
27+
import org.apache.samza.config.JobConfig;
2428
import org.apache.samza.config.ZkConfig;
2529
import org.apache.samza.coordinator.JobCoordinator;
2630
import org.apache.samza.coordinator.JobCoordinatorListener;
@@ -34,10 +38,6 @@
3438
import org.slf4j.Logger;
3539
import org.slf4j.LoggerFactory;
3640

37-
import java.util.ArrayList;
38-
import java.util.Collections;
39-
import java.util.List;
40-
4141
/**
4242
* JobCoordinator for stand alone processor managed via Zookeeper.
4343
*/
@@ -47,6 +47,7 @@ public class ZkJobCoordinator implements JobCoordinator, ZkControllerListener {
4747
// with locality. Since host-affinity is not yet implemented, this can be fixed as part of SAMZA-1197
4848
private static final int METADATA_CACHE_TTL_MS = 5000;
4949

50+
5051
private final ZkUtils zkUtils;
5152
private final String processorId;
5253
private final ZkController zkController;
@@ -59,6 +60,8 @@ public class ZkJobCoordinator implements JobCoordinator, ZkControllerListener {
5960
private JobCoordinatorListener coordinatorListener = null;
6061
private JobModel newJobModel;
6162

63+
private int debounceTimeMs;
64+
6265
public ZkJobCoordinator(Config config) {
6366
this.config = config;
6467
ZkConfig zkConfig = new ZkConfig(config);
@@ -79,11 +82,14 @@ public ZkJobCoordinator(Config config) {
7982
keyBuilder.getJobModelVersionBarrierPrefix(),
8083
zkUtils,
8184
new ZkBarrierListenerImpl());
85+
this.debounceTimeMs = new JobConfig(config).getDebounceTimeMs();
86+
8287
}
8388

8489
@Override
8590
public void start() {
8691
streamMetadataCache = StreamMetadataCache.apply(METADATA_CACHE_TTL_MS, config);
92+
8793
debounceTimer = new ScheduleAfterDebounceTime(throwable -> {
8894
LOG.error("Received exception from in JobCoordinator Processing!", throwable);
8995
stop();
@@ -126,7 +132,7 @@ public String getProcessorId() {
126132
public void onProcessorChange(List<String> processors) {
127133
LOG.info("ZkJobCoordinator::onProcessorChange - list of processors changed! List size=" + processors.size());
128134
debounceTimer.scheduleAfterDebounceTime(ScheduleAfterDebounceTime.ON_PROCESSOR_CHANGE,
129-
ScheduleAfterDebounceTime.DEBOUNCE_TIME_MS, () -> doOnProcessorChange(processors));
135+
debounceTimeMs, () -> doOnProcessorChange(processors));
130136
}
131137

132138
void doOnProcessorChange(List<String> processors) {
@@ -232,8 +238,8 @@ public void onBecomingLeader() {
232238
zkController.subscribeToProcessorChange();
233239
debounceTimer.scheduleAfterDebounceTime(
234240
ScheduleAfterDebounceTime.ON_PROCESSOR_CHANGE,
235-
ScheduleAfterDebounceTime.DEBOUNCE_TIME_MS, () -> {
236-
// actual actions to do are the same as onProcessorChange()
241+
debounceTimeMs, () -> {
242+
// actual actions to do are the same as onProcessorChange
237243
doOnProcessorChange(new ArrayList<>());
238244
});
239245
}

samza-core/src/main/scala/org/apache/samza/config/JobConfig.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ object JobConfig {
4747
val JOB_CONTAINER_THREAD_POOL_SIZE = "job.container.thread.pool.size"
4848
val JOB_CONTAINER_SINGLE_THREAD_MODE = "job.container.single.thread.mode"
4949
val JOB_INTERMEDIATE_STREAM_PARTITIONS = "job.intermediate.stream.partitions"
50+
val JOB_DEBOUNCE_TIME_MS = "job.debounce.time.ms"
51+
val DEFAULT_DEBOUNCE_TIME_MS = 2000
5052

5153
val SSP_GROUPER_FACTORY = "job.systemstreampartition.grouper.factory"
5254

@@ -172,4 +174,6 @@ class JobConfig(config: Config) extends ScalaMapConfig(config) with Logging {
172174
case Some(mode) => mode.toBoolean
173175
case _ => false
174176
}
177+
178+
def getDebounceTimeMs = getInt(JobConfig.JOB_DEBOUNCE_TIME_MS, JobConfig.DEFAULT_DEBOUNCE_TIME_MS)
175179
}

0 commit comments

Comments
 (0)