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