interface: add warmup budget to PaddedRSTransport
Adds a 1024 (unpadded) byte budget to the PaddedRSTransport below which messages are instantly flushed down the socket before the transport will beginn waiting for the buffer to reach MIN_PACKET_SIZE (1024). This allows to get the first couple of messages sent quickly when starting the wallet to improve UX.
This commit is contained in:
@@ -328,6 +328,9 @@ class PaddedRSTransport(RSTransport):
|
||||
|
||||
MIN_PACKET_SIZE = 1024
|
||||
WAIT_FOR_BUFFER_GROWTH_SECONDS = 1.0
|
||||
# (unpadded) amount of bytes sent instantly before beginning with polling.
|
||||
# This makes the initial handshake where a few small messages are exchanged faster.
|
||||
WARMUP_BUDGET_SIZE = 1024
|
||||
|
||||
session: Optional['RPCSession']
|
||||
|
||||
@@ -361,6 +364,7 @@ class PaddedRSTransport(RSTransport):
|
||||
self._force_send
|
||||
or len(buf) >= self.MIN_PACKET_SIZE
|
||||
or self._last_send + self.WAIT_FOR_BUFFER_GROWTH_SECONDS < time.monotonic()
|
||||
or self.session.send_size < self.WARMUP_BUDGET_SIZE
|
||||
):
|
||||
return
|
||||
assert buf[-2:] in (b"}\n", b"]\n"), f"unexpected json-rpc terminator: {buf[-2:]=!r}"
|
||||
@@ -950,6 +954,7 @@ class Interface(Logger):
|
||||
proxy=self.proxy,
|
||||
transport=PaddedRSTransport,
|
||||
) as session:
|
||||
start = time.perf_counter()
|
||||
self.session = session # type: NotificationSession
|
||||
self.session.set_default_timeout(self.network.get_network_timeout_seconds(NetworkTimeout.Generic))
|
||||
try:
|
||||
@@ -972,7 +977,7 @@ class Interface(Logger):
|
||||
raise GracefulDisconnect(e)
|
||||
if server_genesis_hash != constants.net.GENESIS:
|
||||
raise GracefulDisconnect(f'server on different chain: {server_genesis_hash=}. ours: {constants.net.GENESIS}')
|
||||
self.logger.info(f"connection established. version: {ver}")
|
||||
self.logger.info(f"connection established. version: {ver}, handshake duration: {(time.perf_counter() - start) * 1000:.2f} ms")
|
||||
|
||||
try:
|
||||
async with self.taskgroup as group:
|
||||
|
||||
Reference in New Issue
Block a user