def on_pong(self, timestamp):
"""
Records the latency of clients (from the server's perspective) via a
log message.
.. note::
This is the ``pong`` specified in the WebSocket protocol itself.
The `pong` method is a Gate One-specific implementation.
"""
self.latency_count += 1
latency = int(time.time() * 1000) - int(timestamp)
if latency < 0:
return # Something went wrong; skip this one
self.timestamps.append(latency)
if len(self.timestamps) > 10:
self.timestamps.pop(0)
self.latency = sum(self.timestamps)/len(self.timestamps)
if self.latency_count > 12: # Only log once a minute
self.latency_count = 0
#self.logger.info(_("WebSocket Latency: {0}ms").format(self.latency))
评论列表
文章目录