mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 00:43:06 +00:00
adding a dynamic sleep interval in the connectivity loop (#3031)
This commit is contained in:
parent
b120da2a18
commit
2a596f4c77
@ -965,7 +965,21 @@ proc relayConnectivityLoop*(pm: PeerManager) {.async.} =
|
|||||||
await pm.manageRelayPeers()
|
await pm.manageRelayPeers()
|
||||||
else:
|
else:
|
||||||
await pm.connectToRelayPeers()
|
await pm.connectToRelayPeers()
|
||||||
await sleepAsync(ConnectivityLoopInterval)
|
let
|
||||||
|
(inRelayPeers, outRelayPeers) = pm.connectedPeers(WakuRelayCodec)
|
||||||
|
excessInConns = max(inRelayPeers.len - pm.inRelayPeersTarget, 0)
|
||||||
|
|
||||||
|
# One minus the percentage of excess connections relative to the target, limited to 100%
|
||||||
|
# We calculate one minus this percentage because we want the factor to be inversely proportional to the number of excess peers
|
||||||
|
inFactor = 1 - min(excessInConns / pm.inRelayPeersTarget, 1)
|
||||||
|
# Percentage of out relay peers relative to the target
|
||||||
|
outFactor = min(outRelayPeers.len / pm.outRelayPeersTarget, 1)
|
||||||
|
factor = min(outFactor, inFactor)
|
||||||
|
dynamicSleepInterval =
|
||||||
|
chronos.seconds(int(float(ConnectivityLoopInterval.seconds()) * factor))
|
||||||
|
|
||||||
|
# Shorten the connectivity loop interval dynamically based on percentage of peers to fill or connections to prune
|
||||||
|
await sleepAsync(dynamicSleepInterval)
|
||||||
|
|
||||||
proc logAndMetrics(pm: PeerManager) {.async.} =
|
proc logAndMetrics(pm: PeerManager) {.async.} =
|
||||||
heartbeat "Scheduling log and metrics run", LogAndMetricsInterval:
|
heartbeat "Scheduling log and metrics run", LogAndMetricsInterval:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user