Skip to content

Commit b869f9f

Browse files
committed
Work around bug in AWS API Gateway.
Fix #1065.
1 parent 27e861f commit b869f9f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

docs/project/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Improvements
3838
the :attr:`~legacy.protocol.WebSocketCommonProtocol.path` attribute of
3939
the first argument.
4040

41+
* Worked around a `bug in AWS API Gateway`_ that websockets 10.0 triggers.
42+
43+
.. _bug in AWS API Gateway: https://github.com/aaugustin/websockets/issues/1065
44+
4145
* Mirrored the entire :class:`~asyncio.Server` API
4246
in :class:`~server.WebSocketServer`.
4347

docs/topics/compression.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ usage for both sides.
7777

7878
* **Window Bits** controls the size of the compression context. It must be
7979
an integer between 9 (lowest memory usage) and 15 (best compression).
80-
websockets defaults to 12. Setting it to 8 is possible but rejected by some
81-
versions of zlib.
80+
websockets defaults to 12 for servers and 15 for clients. Setting it to 8
81+
is possible but rejected by some versions of zlib.
8282

8383
:mod:`zlib` offers additional parameters for tuning compression. They control
8484
the trade-off between compression rate and CPU and memory usage for the
@@ -101,10 +101,20 @@ Unless mentioned otherwise, websockets uses the defaults of
101101
Tuning compression
102102
------------------
103103

104-
By default, websockets enables compression with conservative settings that
105-
optimize memory usage at the cost of a slightly worse compression rate: Window
106-
Bits = 12 and Memory Level = 5. This strikes a good balance for small messages
107-
that are typical of WebSocket servers.
104+
By default, for servers, websockets enables compression with conservative
105+
settings that optimize memory usage at the cost of a slightly worse
106+
compression rate: Window Bits = 12 and Memory Level = 5. This strikes a good
107+
balance for small messages that are typical of WebSocket servers.
108+
109+
For clients, websockets enables compression but leaves settings up to the
110+
server. This is for a bad reason: providing compression settings triggers a
111+
`bug in AWS API Gateway`_ and, since there's no realistic way to file a bug
112+
against AWS, affected users end up filing bugs against websockets. Optimizing
113+
memory usage is less critical for clients because it's uncommon to open
114+
thousands of client connections in a program. This makes it acceptable not to
115+
perform the same optimization as for servers.
116+
117+
.. _bug in AWS API Gateway: https://github.com/aaugustin/websockets/issues/1065
108118

109119
Here's how various compression settings affect memory usage of a single
110120
connection on a 64-bit system, as well a benchmark of compressed size and

src/websockets/extensions/permessage_deflate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ def enable_client_permessage_deflate(
448448
):
449449
extensions = list(extensions) + [
450450
ClientPerMessageDeflateFactory(
451-
server_max_window_bits=12,
452-
client_max_window_bits=12,
453451
compress_settings={"memLevel": 5},
454452
)
455453
]

0 commit comments

Comments
 (0)