Add a configurable pause between persisted nodes

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-03-16 09:35:19 -04:00
1 parent dc8e03bd40
commit e7df1aeb5b
3 files changed
+18 -5

No files matched your search

@@ -23,16 +23,21 @@ public class DynamicMessagePersisterConfiguration {
@JsonProperty
private Duration nodeClaimTtl = Duration.ofHours(1);
@JsonProperty
private Duration sleepBetweenNodes = Duration.ofSeconds(5);
public DynamicMessagePersisterConfiguration() {}
@VisibleForTesting
public DynamicMessagePersisterConfiguration(final boolean persistenceEnabled,
final double trimOversizedQueueExtraRoomRatio,
final Duration nodeClaimTtl) {
final Duration nodeClaimTtl,
final Duration sleepBetweenNodes) {
this.persistenceEnabled = persistenceEnabled;
this.trimOversizedQueueExtraRoomRatio = trimOversizedQueueExtraRoomRatio;
this.nodeClaimTtl = nodeClaimTtl;
this.sleepBetweenNodes = sleepBetweenNodes;
}
public boolean isPersistenceEnabled() {
@@ -46,4 +51,8 @@ public class DynamicMessagePersisterConfiguration {
public Duration getNodeClaimTtl() {
return nodeClaimTtl;
}
public Duration getSleepBetweenNodes() {
return sleepBetweenNodes;
}
}
@@ -153,8 +153,12 @@ public class MessagePersister implements Managed {
logger.warn("Failed to persist queues", t);
Util.sleep(EXCEPTION_PAUSE_MILLIS);
}
} else {
Util.sleep(1000);
}
try {
// Persisters work through nodes quickly, and running in a hot loop taxes Redis nodes unnecessarily
Thread.sleep(dynamicConfigurationManager.getConfiguration().getMessagePersisterConfiguration().getSleepBetweenNodes());
} catch (final InterruptedException _) {
}
}
}, "MessagePersister");
@@ -124,7 +124,7 @@ class MessagePersisterTest {
dynamicConfiguration = mock(DynamicConfiguration.class);
when(dynamicConfiguration.getMessagePersisterConfiguration())
.thenReturn(new DynamicMessagePersisterConfiguration(true, EXTRA_ROOM_RATIO, Duration.ofHours(1)));
.thenReturn(new DynamicMessagePersisterConfiguration(true, EXTRA_ROOM_RATIO, Duration.ofHours(1), Duration.ZERO));
when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration);
sharedExecutorService = Executors.newSingleThreadExecutor();
@@ -286,7 +286,7 @@ class MessagePersisterTest {
CLOCK.instant().minus(PERSIST_DELAY.plusSeconds(1)));
when(dynamicConfiguration.getMessagePersisterConfiguration())
.thenReturn(new DynamicMessagePersisterConfiguration(false, EXTRA_ROOM_RATIO, Duration.ofHours(1)));
.thenReturn(new DynamicMessagePersisterConfiguration(false, EXTRA_ROOM_RATIO, Duration.ofHours(1), Duration.ZERO));
assertEquals(0, messagePersister.persistNode(
getNodeWithKey(MessagesCache.getMessageQueueKey(DESTINATION_ACCOUNT_UUID, DESTINATION_DEVICE_ID))));