forked from LBRYCommunity/lbry-sdk
track connection latency
This commit is contained in:
parent
72690b5cff
commit
0e48772c84
1 changed files with 4 additions and 0 deletions
|
@ -25,6 +25,7 @@ class ClientSession(BaseClientSession):
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.max_seconds_idle = timeout * 2
|
self.max_seconds_idle = timeout * 2
|
||||||
self.response_time: Optional[float] = None
|
self.response_time: Optional[float] = None
|
||||||
|
self.connection_latency: Optional[float] = None
|
||||||
self._response_samples = 0
|
self._response_samples = 0
|
||||||
self.pending_amount = 0
|
self.pending_amount = 0
|
||||||
self._on_connect_cb = on_connect_callback or (lambda: None)
|
self._on_connect_cb = on_connect_callback or (lambda: None)
|
||||||
|
@ -91,7 +92,9 @@ class ClientSession(BaseClientSession):
|
||||||
|
|
||||||
async def create_connection(self, timeout=6):
|
async def create_connection(self, timeout=6):
|
||||||
connector = Connector(lambda: self, *self.server)
|
connector = Connector(lambda: self, *self.server)
|
||||||
|
start = perf_counter()
|
||||||
await asyncio.wait_for(connector.create_connection(), timeout=timeout)
|
await asyncio.wait_for(connector.create_connection(), timeout=timeout)
|
||||||
|
self.connection_latency = perf_counter() - start
|
||||||
|
|
||||||
async def handle_request(self, request):
|
async def handle_request(self, request):
|
||||||
controller = self.network.subscription_controllers[request.method]
|
controller = self.network.subscription_controllers[request.method]
|
||||||
|
@ -101,6 +104,7 @@ class ClientSession(BaseClientSession):
|
||||||
log.debug("Connection lost: %s:%d", *self.server)
|
log.debug("Connection lost: %s:%d", *self.server)
|
||||||
super().connection_lost(exc)
|
super().connection_lost(exc)
|
||||||
self.response_time = None
|
self.response_time = None
|
||||||
|
self.connection_latency = None
|
||||||
self._response_samples = 0
|
self._response_samples = 0
|
||||||
self._on_disconnect_controller.add(True)
|
self._on_disconnect_controller.add(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue