add latency measure from ping in emc and ws_client

This commit is contained in:
Timothy Pogue 2022-11-02 19:30:35 -06:00
parent a0965606a5
commit b749f3edd6
2 changed files with 8 additions and 10 deletions

View File

@ -264,10 +264,10 @@ class ExternalMessageConsumer:
# We haven't received data yet. Check the connection and continue. # We haven't received data yet. Check the connection and continue.
try: try:
# ping # ping
ping = await channel.ping() pong = await channel.ping()
latency = (await asyncio.wait_for(pong, timeout=self.ping_timeout) * 1000)
await asyncio.wait_for(ping, timeout=self.ping_timeout) logger.info(f"Connection to {channel} still alive, latency: {latency}ms")
logger.debug(f"Connection to {channel} still alive...")
continue continue
except (websockets.exceptions.ConnectionClosed): except (websockets.exceptions.ConnectionClosed):
@ -276,7 +276,7 @@ class ExternalMessageConsumer:
await asyncio.sleep(self.sleep_time) await asyncio.sleep(self.sleep_time)
break break
except Exception as e: except Exception as e:
logger.warning(f"Ping error {channel} - retrying in {self.sleep_time}s") logger.warning(f"Ping error {channel} - {e} - retrying in {self.sleep_time}s")
logger.debug(e, exc_info=e) logger.debug(e, exc_info=e)
await asyncio.sleep(self.sleep_time) await asyncio.sleep(self.sleep_time)

View File

@ -240,12 +240,10 @@ async def create_client(
): ):
# Try pinging # Try pinging
try: try:
pong = ws.ping() pong = await ws.ping()
await asyncio.wait_for( latency = (await asyncio.wait_for(pong, timeout=ping_timeout) * 1000)
pong,
timeout=ping_timeout logger.info(f"Connection still alive, latency: {latency}ms")
)
logger.info("Connection still alive...")
continue continue