Skip to content

Commit 90703bd

Browse files
authored
Added configs for fetching throughput info (#834)
1 parent 873a25d commit 90703bd

File tree

6 files changed

+66
-17
lines changed

6 files changed

+66
-17
lines changed

datastream-server/src/main/java/com/linkedin/datastream/server/assignment/LoadBasedPartitionAssigner.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
* Performs partition assignment based on partition throughput information
2727
*/
2828
public class LoadBasedPartitionAssigner {
29-
// TODO: move these to config class
30-
private static final Integer DEFAULT_KB_RATE = 5;
31-
private static final Integer DEFAULT_MESSAGE_RATE = 5;
32-
3329
/**
3430
* Performs partition assignment based on partition throughput information.
3531
* <p>
@@ -61,7 +57,9 @@ public Map<String, Set<DatastreamTask>> assignPartitions(ClusterThroughputInfo t
6157

6258
// sort the current assignment's tasks on total throughput
6359
Map<String, Integer> taskThroughputMap = new HashMap<>();
64-
PartitionThroughputInfo defaultPartitionInfo = new PartitionThroughputInfo(DEFAULT_KB_RATE, DEFAULT_MESSAGE_RATE, "");
60+
PartitionThroughputInfo defaultPartitionInfo = new PartitionThroughputInfo(
61+
PartitionAssignmentStrategyConfig.PARTITION_BYTES_IN_KB_RATE_DEFAULT,
62+
PartitionAssignmentStrategyConfig.PARTITION_MESSAGES_IN_RATE_DEFAULT, "");
6563
newPartitions.forEach((task, partitions) -> {
6664
int totalThroughput = partitions.stream()
6765
.mapToInt(p -> partitionInfoMap.getOrDefault(p, defaultPartitionInfo).getBytesInKBRate())

datastream-server/src/main/java/com/linkedin/datastream/server/assignment/LoadBasedPartitionAssignmentStrategy.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
public class LoadBasedPartitionAssignmentStrategy extends StickyPartitionAssignmentStrategy {
3838
private static final Logger LOG = LoggerFactory.getLogger(LoadBasedPartitionAssignmentStrategy.class.getName());
3939

40-
// TODO Make these constants configurable
41-
private static final long THROUGHPUT_INFO_FETCH_TIMEOUT_MS_DEFAULT = Duration.ofSeconds(10).toMillis();
42-
private static final long THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_DEFAULT = Duration.ofSeconds(1).toMillis();
40+
private static final int THROUGHPUT_INFO_FETCH_TIMEOUT_MS_DEFAULT = (int) Duration.ofSeconds(10).toMillis();
41+
private static final int THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_DEFAULT = (int) Duration.ofSeconds(1).toMillis();
4342

4443
private static final int TASK_CAPACITY_MBPS_DEFAULT = 4;
4544
private static final int TASK_CAPACITY_UTILIZATION_PCT_DEFAULT = 90;
@@ -48,6 +47,8 @@ public class LoadBasedPartitionAssignmentStrategy extends StickyPartitionAssignm
4847
private final DatastreamSourceClusterResolver _sourceClusterResolver;
4948
private final int _taskCapacityMBps;
5049
private final int _taskCapacityUtilizationPct;
50+
private final int _throughputInfoFetchTimeoutMs;
51+
private final int _throughputInfoFetchRetryPeriodMs;
5152

5253

5354
/**
@@ -57,14 +58,19 @@ public LoadBasedPartitionAssignmentStrategy(PartitionThroughputProvider throughp
5758
DatastreamSourceClusterResolver sourceClusterResolver, Optional<Integer> maxTasks,
5859
Optional<Integer> imbalanceThreshold, Optional<Integer> maxPartitionPerTask, boolean enableElasticTaskAssignment,
5960
Optional<Integer> partitionsPerTask, Optional<Integer> partitionFullnessFactorPct,
60-
Optional<Integer> taskCapacityMBps, Optional<Integer> taskCapacityUtilizationPct, Optional<ZkClient> zkClient,
61+
Optional<Integer> taskCapacityMBps, Optional<Integer> taskCapacityUtilizationPct,
62+
Optional<Integer> throughputInfoFetchTimeoutMs, Optional<Integer> throughputInfoFetchRetryPeriodMs,
63+
Optional<ZkClient> zkClient,
6164
String clusterName) {
6265
super(maxTasks, imbalanceThreshold, maxPartitionPerTask, enableElasticTaskAssignment, partitionsPerTask,
6366
partitionFullnessFactorPct, zkClient, clusterName);
6467
_throughputProvider = throughputProvider;
6568
_sourceClusterResolver = sourceClusterResolver;
6669
_taskCapacityMBps = taskCapacityMBps.orElse(TASK_CAPACITY_MBPS_DEFAULT);
6770
_taskCapacityUtilizationPct = taskCapacityUtilizationPct.orElse(TASK_CAPACITY_UTILIZATION_PCT_DEFAULT);
71+
_throughputInfoFetchTimeoutMs = throughputInfoFetchTimeoutMs.orElse(THROUGHPUT_INFO_FETCH_TIMEOUT_MS_DEFAULT);
72+
_throughputInfoFetchRetryPeriodMs = throughputInfoFetchRetryPeriodMs.
73+
orElse(THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_DEFAULT);
6874
}
6975

7076
@Override
@@ -123,7 +129,7 @@ private Map<String, ClusterThroughputInfo> fetchPartitionThroughputInfo() {
123129
LOG.warn("Failed to fetch partition throughput info.");
124130
return null;
125131
}
126-
}, Objects::nonNull, THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_DEFAULT, THROUGHPUT_INFO_FETCH_TIMEOUT_MS_DEFAULT)
132+
}, Objects::nonNull, _throughputInfoFetchRetryPeriodMs, _throughputInfoFetchTimeoutMs)
127133
.orElseThrow(RetriesExhaustedException::new);
128134
}
129135
}

datastream-server/src/main/java/com/linkedin/datastream/server/assignment/LoadBasedPartitionAssignmentStrategyFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public AssignmentStrategy createStrategy(Properties assignmentStrategyProperties
4545
return new LoadBasedPartitionAssignmentStrategy(provider, clusterResolver, _config.getMaxTasks(),
4646
_config.getImbalanceThreshold(), _config.getMaxPartitions(), enableElasticTaskAssignment,
4747
_config.getPartitionsPerTask(), _config.getPartitionFullnessThresholdPct(), _config.getTaskCapacityMBps(),
48-
_config.getTaskCapacityUtilizationPct(), zkClient, _config.getCluster());
48+
_config.getTaskCapacityUtilizationPct(), _config.getThroughputInfoFetchTimeoutMs(),
49+
_config.getThroughputInfoFetchRetryPeriodMs(), zkClient, _config.getCluster());
4950
}
5051

5152
protected PartitionThroughputProvider constructPartitionThroughputProvider() {

datastream-server/src/main/java/com/linkedin/datastream/server/assignment/LoadBasedTaskCountEstimator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
*/
2828
public class LoadBasedTaskCountEstimator {
2929
private static final Logger LOG = LoggerFactory.getLogger(LoadBasedTaskCountEstimator.class.getName());
30-
// TODO Move these to config class
31-
private static final int BYTES_IN_KB_RATE_DEFAULT = 5;
32-
private static final int MESSAGES_IN_RATE_DEFAULT = 5;
33-
3430
private final int _taskCapacityMBps;
3531
private final int _taskCapacityUtilizationPct;
3632

@@ -64,8 +60,9 @@ public int getTaskCount(ClusterThroughputInfo throughputInfo, List<String> assig
6460
Set<String> allPartitions = new HashSet<>(assignedPartitions);
6561
allPartitions.addAll(unassignedPartitions);
6662

67-
PartitionThroughputInfo defaultThroughputInfo = new PartitionThroughputInfo(BYTES_IN_KB_RATE_DEFAULT,
68-
MESSAGES_IN_RATE_DEFAULT, "");
63+
PartitionThroughputInfo defaultThroughputInfo = new PartitionThroughputInfo(
64+
PartitionAssignmentStrategyConfig.PARTITION_BYTES_IN_KB_RATE_DEFAULT,
65+
PartitionAssignmentStrategyConfig.PARTITION_MESSAGES_IN_RATE_DEFAULT, "");
6966
// total throughput in KB/sec
7067
int totalThroughput = allPartitions.stream()
7168
.map(p -> throughputMap.getOrDefault(p, defaultThroughputInfo))

datastream-server/src/main/java/com/linkedin/datastream/server/assignment/PartitionAssignmentStrategyConfig.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public final class PartitionAssignmentStrategyConfig {
2222
public static final String CFG_MAX_PARTITION_PER_TASK = "maxPartitionsPerTask";
2323
public static final String CFG_PARTITIONS_PER_TASK = "partitionsPerTask";
2424
public static final String CFG_PARTITION_FULLNESS_THRESHOLD_PCT = "partitionFullnessThresholdPct";
25+
public static final String CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS = "throughputInfoFetchTimeoutMs";
26+
public static final String CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS = "throughputInfoFetchRetryPeriodMs";
2527
public static final String CFG_TASK_CAPACITY_MBPS = "taskCapacityMBps";
2628
public static final String CFG_TASK_CAPACITY_UTILIZATION_PCT = "taskCapacityUtilizationPct";
2729
public static final String CFG_ENABLE_ELASTIC_TASK_ASSIGNMENT = "enableElasticTaskAssignment";
@@ -30,6 +32,9 @@ public final class PartitionAssignmentStrategyConfig {
3032
public static final String CFG_ZK_SESSION_TIMEOUT = "zkSessionTimeout";
3133
public static final String CFG_ZK_CONNECTION_TIMEOUT = "zkConnectionTimeout";
3234

35+
public static final int PARTITION_BYTES_IN_KB_RATE_DEFAULT = 5;
36+
public static final int PARTITION_MESSAGES_IN_RATE_DEFAULT = 5;
37+
3338
public static final boolean DEFAULT_ENABLE_ELASTIC_TASK_ASSIGNMENT = false;
3439

3540
private final Properties _config;
@@ -40,6 +45,8 @@ public final class PartitionAssignmentStrategyConfig {
4045
private final Optional<Integer> _partitionFullnessThresholdPct;
4146
private final Optional<Integer> _taskCapacityMBps;
4247
private final Optional<Integer> _taskCapacityUtilizationPct;
48+
private final Optional<Integer> _throughputInfoFetchTimeoutMs;
49+
private final Optional<Integer> _throughputInfoFetchRetryPeriodMs;
4350
private final String _cluster;
4451
private final String _zkAddress;
4552
private final int _zkSessionTimeout;
@@ -60,6 +67,8 @@ public PartitionAssignmentStrategyConfig(Properties config) {
6067
int cfgPartitionFullnessThresholdPct = props.getIntInRange(CFG_PARTITION_FULLNESS_THRESHOLD_PCT, 0, 0, 100);
6168
int cfgTaskCapacityMBps = props.getInt(CFG_TASK_CAPACITY_MBPS, 0);
6269
int cfgTaskCapacityUtilizationPct = props.getIntInRange(CFG_TASK_CAPACITY_UTILIZATION_PCT, 0, 0, 100);
70+
int cfgThroughputInfoFetchTimeoutMs = props.getInt(CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS, 0);
71+
int cfgThroughputInfoFetchRetryPeriodMs = props.getInt(CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS, 0);
6372

6473
// Set to Optional.empty() if the value is 0
6574
_maxTasks = cfgMaxTasks > 0 ? Optional.of(cfgMaxTasks) : Optional.empty();
@@ -74,6 +83,10 @@ public PartitionAssignmentStrategyConfig(Properties config) {
7483
_taskCapacityMBps = cfgTaskCapacityMBps > 0 ? Optional.of(cfgTaskCapacityMBps) : Optional.empty();
7584
_taskCapacityUtilizationPct = cfgTaskCapacityUtilizationPct > 0 ? Optional.of(cfgTaskCapacityUtilizationPct) :
7685
Optional.empty();
86+
_throughputInfoFetchTimeoutMs = cfgThroughputInfoFetchTimeoutMs > 0 ?
87+
Optional.of(cfgThroughputInfoFetchTimeoutMs) : Optional.empty();
88+
_throughputInfoFetchRetryPeriodMs = cfgThroughputInfoFetchRetryPeriodMs > 0 ?
89+
Optional.of(cfgThroughputInfoFetchRetryPeriodMs) : Optional.empty();
7790
_cluster = props.getString(CFG_CLUSTER_NAME, null);
7891
_zkAddress = props.getString(CFG_ZK_ADDRESS, null);
7992
_zkSessionTimeout = props.getInt(CFG_ZK_SESSION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT);
@@ -136,6 +149,22 @@ public Optional<Integer> getTaskCapacityUtilizationPct() {
136149
return _taskCapacityUtilizationPct;
137150
}
138151

152+
/**
153+
* Gets throughput info fetch timeout in milliseconds
154+
* @return Throughput info fetch timeout in milliseconds
155+
*/
156+
public Optional<Integer> getThroughputInfoFetchTimeoutMs() {
157+
return _throughputInfoFetchTimeoutMs;
158+
}
159+
160+
/**
161+
* Gets the throughput info fetch retry period in milliseconds
162+
* @return Throughput info fetch retry period in milliseconds
163+
*/
164+
public Optional<Integer> getThroughputInfoFetchRetryPeriodMs() {
165+
return _throughputInfoFetchRetryPeriodMs;
166+
}
167+
139168
/**
140169
* Gets cluster
141170
* @return Cluster

datastream-server/src/test/java/com/linkedin/datastream/server/assignment/TestPartitionAssignmentStrategyConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class TestPartitionAssignmentStrategyConfig {
2525
private static final String CFG_MAX_TASKS_VALUE = "20";
2626
private static final String CFG_PARTITIONS_PER_TASK_VALUE = "15";
2727
private static final String CFG_PARTITIONS_FULLNESS_THRESHOLD_PCT_VALUE = "75";
28+
private static final String CFG_TASK_CAPACITY_MBPS_VALUE = "5";
29+
private static final String CFG_TASK_CAPACITY_UTILIZATION_PCT_VALUE = "82";
30+
private static final String CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS_VALUE = "1100";
31+
private static final String CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_VALUE = "1200";
2832
private static final String CFG_ENABLE_ELASTIC_TASK_ASSIGNMENT_VALUE = "true";
2933
private static final String CFG_ZK_ADDRESS_VALUE = "dummyZk";
3034
private static final String CFG_ZK_SESSION_TIMEOUT_VALUE = "1000";
@@ -42,6 +46,13 @@ public void configValuesCorrectlyAssignedTest() {
4246
props.setProperty(PartitionAssignmentStrategyConfig.CFG_PARTITIONS_PER_TASK, CFG_PARTITIONS_PER_TASK_VALUE);
4347
props.setProperty(PartitionAssignmentStrategyConfig.CFG_PARTITION_FULLNESS_THRESHOLD_PCT,
4448
CFG_PARTITIONS_FULLNESS_THRESHOLD_PCT_VALUE);
49+
props.setProperty(PartitionAssignmentStrategyConfig.CFG_TASK_CAPACITY_MBPS, CFG_TASK_CAPACITY_MBPS_VALUE);
50+
props.setProperty(PartitionAssignmentStrategyConfig.CFG_TASK_CAPACITY_UTILIZATION_PCT,
51+
CFG_TASK_CAPACITY_UTILIZATION_PCT_VALUE);
52+
props.setProperty(PartitionAssignmentStrategyConfig.CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS,
53+
CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS_VALUE);
54+
props.setProperty(PartitionAssignmentStrategyConfig.CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS,
55+
CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_VALUE);
4556
props.setProperty(PartitionAssignmentStrategyConfig.CFG_ENABLE_ELASTIC_TASK_ASSIGNMENT,
4657
CFG_ENABLE_ELASTIC_TASK_ASSIGNMENT_VALUE);
4758
props.setProperty(PartitionAssignmentStrategyConfig.CFG_ZK_ADDRESS, CFG_ZK_ADDRESS_VALUE);
@@ -56,6 +67,13 @@ public void configValuesCorrectlyAssignedTest() {
5667
Assert.assertEquals(config.getMaxPartitions(), Optional.of(Integer.parseInt(CFG_MAX_PARTITION_PER_TASK_VALUE)));
5768
Assert.assertEquals(config.getPartitionFullnessThresholdPct(),
5869
Optional.of(Integer.parseInt(CFG_PARTITIONS_FULLNESS_THRESHOLD_PCT_VALUE)));
70+
Assert.assertEquals(config.getTaskCapacityMBps(), Optional.of(Integer.parseInt(CFG_TASK_CAPACITY_MBPS_VALUE)));
71+
Assert.assertEquals(config.getTaskCapacityUtilizationPct(),
72+
Optional.of(Integer.parseInt(CFG_TASK_CAPACITY_UTILIZATION_PCT_VALUE)));
73+
Assert.assertEquals(config.getThroughputInfoFetchTimeoutMs(),
74+
Optional.of(Integer.parseInt(CFG_THROUGHPUT_INFO_FETCH_TIMEOUT_MS_VALUE)));
75+
Assert.assertEquals(config.getThroughputInfoFetchRetryPeriodMs(),
76+
Optional.of(Integer.parseInt(CFG_THROUGHPUT_INFO_FETCH_RETRY_PERIOD_MS_VALUE)));
5977
Assert.assertEquals(config.isElasticTaskAssignmentEnabled(),
6078
Boolean.parseBoolean(CFG_ENABLE_ELASTIC_TASK_ASSIGNMENT_VALUE));
6179
Assert.assertEquals(config.getZkAddress(), CFG_ZK_ADDRESS_VALUE);

0 commit comments

Comments
 (0)