mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix round robin load balancing
This commit is contained in:
@ -90,6 +90,7 @@ class CircuitV2Transport(ITransport):
|
||||
discovery_interval=config.discovery_interval,
|
||||
max_relays=config.max_relays,
|
||||
)
|
||||
self.relay_counter = 0 # for round robin load balancing
|
||||
|
||||
async def dial(
|
||||
self,
|
||||
@ -231,13 +232,13 @@ class CircuitV2Transport(ITransport):
|
||||
other_relays.append(relay_id)
|
||||
|
||||
# Return first available relay with reservation, or fallback to others
|
||||
self.relay_counter += 1
|
||||
if relays_with_reservations:
|
||||
return relays_with_reservations[
|
||||
attempts % len(relays_with_reservations)
|
||||
(self.relay_counter-1) % len(relays_with_reservations)
|
||||
]
|
||||
elif other_relays:
|
||||
return other_relays[attempts % len(other_relays)]
|
||||
|
||||
return other_relays[(self.relay_counter-1) % len(other_relays)]
|
||||
await trio.sleep(1)
|
||||
attempts += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user