Skip to content

Websocket compression for send_bytes on by default #2856

Closed
@frederikaalund

Description

Long story short

I recently upgraded from Aiohttp 2.2.5 to 3.0.6. After that, I got a lot of dropped websocket connections. Through investigation, I found that 2.3.0 introduced the compression=True parameter for websockets. It turns out, that this change caused the dropped connections. Simply setting compression=False (and thereby returning to the pre-2.3.0 behaviour) solved the issue.

I can understand that having compression on by default makes a lot of sense for text messages (e.g., send_str or send_json messages). We can naturally assume statistical redundancy for text messages.
However, I find it strange to find compression on by default for binary messages (e.g., send_bytes messages). I don't think we can assume anything about binary messages. Said messages may very well be near-random (and therefore compress very poorly).

In my application, I send a lot of binary data over a websocket (roughly 500 KBps) that doesn't compress very well at all. The (needless) compression caused the python process take up all CPU resources and, ultimately, drop the connection due to timeout.

Expected behaviour

I expected send_bytes to have compression off by default.

Actual behaviour

Since 2.3.0, WebSocketResponse has compression on by default. Since 3.0.0, it is possible to disable compression on a per-method basis (send_bytes(..., compression=False)). However, compression is on by default, which I think is very questionable.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions