websockets icon indicating copy to clipboard operation
websockets copied to clipboard

Provide metrics

Open aaugustin opened this issue 3 years ago • 2 comments

I'm thinking of something along the lines of:

websocket.get_metrics()

{
    "lifetime": 23.780,
    "latency": 0.423,
    "frames": {
        "rcvd": {
            "text": 93,
            "pong": 17,
        },
        "rcvd": {
            "text": 1,
            "ping": 17,
        },
    },
}

I'm not sure what would be must useful to track.

Idea sparked in #919.

aaugustin avatar May 15 '21 07:05 aaugustin

maybe avg_{rcvd,txd}_{compressed,uncompressed}_frame_size ? latency would be the ping/pong one i imagine, so maybe an tuple of min/avg/max/mdev ?

adriansev avatar May 18 '21 05:05 adriansev

Nice suggestions!

aaugustin avatar May 18 '21 10:05 aaugustin

Latency is now available via a dedicated API. See #1195.

One year later, I'm not sure about implementing the rest:

  • Buffer sizes: I don't know how to get the TCP buffers at the OS level, which are the largest buffers in the system for the most common WebSocket use cases (small messages).
  • Compression: it's not just about the size, it's also about CPU usage, so benchmarks compression is best done offline with scripts similar to experimentation/compression/broadcast.py
  • Messages sent or received: this is easy to implement outside of websockets — just count what you send or receive; I don't really want to add overhead for everyone when it isn't a common feature request.

aaugustin avatar Oct 09 '22 13:10 aaugustin

Also I looked for prior art in other WebSocket frameworks and couldn't find anything resembling this. Typical metrics are things like "number of connections to the server".

aaugustin avatar Oct 09 '22 13:10 aaugustin