mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 02:36:53 +00:00
Add a configurable pause between persisted nodes
This commit is contained in:
1 parent
dc8e03bd40
commit
e7df1aeb5b
3 files changed
+18
-5
No files matched your search
+10
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -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");
|
||||
|
||||
+2
-2
@@ -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))));
|
||||
|
||||
Reference in new issue
Block a user