Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #7797/27c308b1 backport][3.9] Fix increase in latency with small messages from websocket compression changes #7799

Conversation

patchback[bot]
Copy link
Contributor

@patchback patchback bot commented Nov 7, 2023

This is a backport of PR #7797 as merged into master (27c308b).

What do these changes do?

Changes the threshold that is required to compress in the executor for websocket messages to 5KiB

#7223 changed the websocket implementation to compress messages > 1KiB in the executor. The threshold was a bit low which caused an increase in latency compressing messages as the overhead to use the executor can exceed the cost to compress tiny messages. When testing 3.9.0 with Home Assistant, we saw a 3 order of magnitude increase in executor usage which resulted in an overall increase in cpu time since all the tiny messages were being compressed in the executor.

I could not find the motivation for choosing 1KiB in the original PR

Are there changes in behavior for the user?

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

…n changes (#7797)

<!-- Thank you for your contribution! -->

## What do these changes do?

Changes the threshold that is required to compress in the executor for
websocket messages to 5KiB

#7223 changed the websocket
implementation to compress messages > 1KiB in the executor. The
threshold was a bit low which caused an increase in latency compressing
messages as the overhead to use the executor can exceed the cost to
compress tiny messages. When testing 3.9.0 with Home Assistant, we saw a
3 order of magnitude increase in executor usage which resulted in an
overall increase in cpu time since all the tiny messages were being
compressed in the executor.

I could not find the motivation for choosing 1KiB in the original PR

## Are there changes in behavior for the user?

<!-- Outline any notable behaviour for the end users. -->

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

## Checklist

- [x] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names.
- [ ] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating
the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
* `.misc`: A ticket has been closed, but it is not of interest to users.
* Make sure to use full sentences with correct case and punctuation, for
example: "Fix issue with non-ascii contents in doctest text files."

(cherry picked from commit 27c308b)
Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #7799 (2012bee) into 3.9 (8f27edf) will increase coverage by 0.00%.
Report is 4 commits behind head on 3.9.
The diff coverage is 75.00%.

@@           Coverage Diff           @@
##              3.9    #7799   +/-   ##
=======================================
  Coverage   97.36%   97.36%           
=======================================
  Files         107      107           
  Lines       32317    32318    +1     
  Branches     3824     3824           
=======================================
+ Hits        31466    31467    +1     
  Misses        648      648           
  Partials      203      203           
Flag Coverage Δ
CI-GHA 97.27% <75.00%> (+<0.01%) ⬆️
OS-Linux 96.97% <75.00%> (+<0.01%) ⬆️
OS-Windows 94.50% <100.00%> (+<0.01%) ⬆️
OS-macOS 96.63% <75.00%> (+<0.01%) ⬆️
Py-3.10.11 94.41% <100.00%> (+<0.01%) ⬆️
Py-3.10.13 96.79% <75.00%> (+<0.01%) ⬆️
Py-3.11.6 96.47% <75.00%> (+<0.01%) ⬆️
Py-3.8.10 94.39% <100.00%> (+<0.01%) ⬆️
Py-3.8.18 96.73% <75.00%> (+<0.01%) ⬆️
Py-3.9.13 94.40% <100.00%> (+<0.01%) ⬆️
Py-3.9.18 96.78% <75.00%> (+<0.01%) ⬆️
Py-pypy7.3.11 96.17% <75.00%> (+<0.01%) ⬆️
VM-macos 96.63% <75.00%> (+<0.01%) ⬆️
VM-ubuntu 96.97% <75.00%> (+<0.01%) ⬆️
VM-windows 94.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
aiohttp/http_websocket.py 99.22% <100.00%> (+<0.01%) ⬆️
aiohttp/client.py 94.91% <50.00%> (ø)

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@Dreamsorcerer Dreamsorcerer merged commit 476c4f2 into 3.9 Nov 7, 2023
21 of 27 checks passed
@Dreamsorcerer Dreamsorcerer deleted the patchback/backports/3.9/27c308b177a8421e2ce093505e71d74a2082f374/pr-7797 branch November 7, 2023 17:58
xiangxli pushed a commit to xiangxli/aiohttp that referenced this pull request Dec 4, 2023
…h small messages from websocket compression changes (aio-libs#7799)

**This is a backport of PR aio-libs#7797 as merged into master
(27c308b).**

<!-- Thank you for your contribution! -->

Changes the threshold that is required to compress in the executor for
websocket messages to 5KiB

aio-libs#7223 changed the websocket
implementation to compress messages > 1KiB in the executor. The
threshold was a bit low which caused an increase in latency compressing
messages as the overhead to use the executor can exceed the cost to
compress tiny messages. When testing 3.9.0 with Home Assistant, we saw a
3 order of magnitude increase in executor usage which resulted in an
overall increase in cpu time since all the tiny messages were being
compressed in the executor.

I could not find the motivation for choosing 1KiB in the original PR

<!-- Outline any notable behaviour for the end users. -->

<!-- Are there any issues opened that will be resolved by merging this
change? -->

- [x] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names.
- [ ] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating
the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
* `.misc`: A ticket has been closed, but it is not of interest to users.
* Make sure to use full sentences with correct case and punctuation, for
example: "Fix issue with non-ascii contents in doctest text files."

Co-authored-by: J. Nick Koston <nick@koston.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants