Skip to content

Fast client writes will fill up memory #4

@snej

Description

@snej

The client code using libws has no way to tell how fast data is being written to the socket, so it can't tell how fast it can send messages. If it sends messages faster than the socket can write them, the libevent write buffers will start to pile up and increase memory usage. This also increases latency, since the client can end up creating messages that only get written to the socket much later.

(Think of a webcam that wants to send camera frames over the socket as JPEG images. If it starts sending messages at 60FPS, but the network bandwidth isn't enough to support that, then memory will start to fill up with pending frames, and the other side of the connection will see the video feed in slower than real-time. Instead, the webcam should wait until the websocket is ready for more data, and then write the current frame.)

This can be fixed by adding a new callback that tells the client that the socket has room to write. This is equivalent to the write callback provided by libevent; in fact libws's write callback can invoke the new callback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions