Skip to content

Commit 6d02f27

Browse files
authored
feat: Make worker loop sleep duration configurable (#20007)
Signed-off-by: Petar Tonev <[email protected]>
1 parent c19882f commit 6d02f27

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

hedera-node/hedera-app/src/main/java/com/hedera/node/app/blocks/impl/streaming/BlockNodeConnectionManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ public class BlockNodeConnectionManager {
7272
*/
7373
public static final Duration INITIAL_RETRY_DELAY = Duration.ofSeconds(1);
7474
/**
75-
* The amount of time the worker thread will sleep when there is no work available to process.
75+
* The multiplier used for exponential backoff when retrying connections.
7676
*/
77-
private static final int PROCESSOR_LOOP_DELAY_MS = 10;
78-
7977
private static final long RETRY_BACKOFF_MULTIPLIER = 2;
8078
/**
8179
* The maximum delay used for reties.
@@ -220,6 +218,18 @@ private int blockItemBatchSize() {
220218
.blockItemBatchSize();
221219
}
222220

221+
/**
222+
* The amount of time the worker thread will sleep when there is no work available to process.
223+
*
224+
* @return the sleep duration of the worker loop
225+
*/
226+
private Duration workerLoopSleepDuration() {
227+
return configProvider
228+
.getConfiguration()
229+
.getConfigData(BlockStreamConfig.class)
230+
.workerLoopSleepDuration();
231+
}
232+
223233
/**
224234
* Extracts block node configurations from the specified configuration file.
225235
*
@@ -549,8 +559,7 @@ private void blockStreamWorkerLoop() {
549559

550560
// Sleep for a short duration to avoid busy waiting
551561
if (shouldSleep) {
552-
// TODO: make sleep duration configurable
553-
Thread.sleep(PROCESSOR_LOOP_DELAY_MS);
562+
Thread.sleep(workerLoopSleepDuration());
554563
}
555564
} catch (final InterruptedException e) {
556565
logger.error("Block stream worker interrupted", e);

hedera-node/hedera-config/src/main/java/com/hedera/node/config/data/BlockStreamConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public record BlockStreamConfig(
3333
@ConfigProperty(defaultValue = "2s") @Min(0) @NetworkProperty Duration blockPeriod,
3434
@ConfigProperty(defaultValue = "256") @Min(0) @NetworkProperty int blockItemBatchSize,
3535
@ConfigProperty(defaultValue = "5m") @Min(0) @NetworkProperty Duration blockBufferTtl,
36-
@ConfigProperty(defaultValue = "1s") @Min(0) @NetworkProperty Duration blockBufferPruneInterval) {
36+
@ConfigProperty(defaultValue = "1s") @Min(0) @NetworkProperty Duration blockBufferPruneInterval,
37+
@ConfigProperty(defaultValue = "10ms") @Min(1) @NodeProperty Duration workerLoopSleepDuration) {
3738

3839
/**
3940
* Whether to stream to block nodes.

0 commit comments

Comments
 (0)