-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add benchmark for blocking time reading chunks #11891
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
Open
Dreamsorcerer
wants to merge
5
commits into
master
Choose a base branch
from
s7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07cec64
Add benchmark for blocking time reading chunks
Dreamsorcerer 67e3c30
Merge branch 'master' into s7
Dreamsorcerer 29f0d5a
Update tests/test_benchmarks_web_functional.py
Dreamsorcerer 162f384
Update test_benchmarks_web_functional.py
Dreamsorcerer 985dc9d
Update test_benchmarks_web_functional.py
Dreamsorcerer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from unittest import mock | ||
|
|
||
| from pytest_codspeed import BenchmarkFixture | ||
|
|
||
| from aiohttp import web | ||
| from aiohttp.pytest_plugin import AiohttpClient | ||
|
|
||
|
|
||
| async def test_read_many_chunks( | ||
| aiohttp_client: AiohttpClient, benchmark: BenchmarkFixture | ||
| ) -> None: | ||
| """Benchmark blocking time when receiving many small chunks.""" | ||
|
|
||
| async def sender(): | ||
| for _ in range(200000): | ||
| yield b"x" | ||
|
|
||
| async def handle(request: web.Request) -> web.Response: | ||
| # Wait until buffer is full and reading gets paused. | ||
| while not request.protocol._reading_paused: | ||
| await asyncio.sleep(0.01) | ||
|
|
||
| # We want to measure the initial blocking time in this call. | ||
| # Mocking out the ._wait() call forces the method to return at the first wait, | ||
| # without waiting for more data or processing the rest of the body. | ||
| with mock.patch.object(request.content, "_wait", autospec=True): | ||
| chunk = await benchmark(request.read()) | ||
|
|
||
| return web.Response(text=str(len(chunk))) | ||
|
|
||
| app = web.Application() | ||
| app.router.add_post("/", handle) | ||
| client = await aiohttp_client(app) | ||
|
|
||
| async with client.post("/", chunked=True, data=sender()) as resp: | ||
| assert resp.status == 200 | ||
| assert int(await resp.text()) > 100 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.