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 #9935/0c312496 backport][3.11] Add benchmark for routing sub_applications #9937

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/test_benchmarks_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,37 @@ async def run_url_dispatcher_benchmark() -> None:
@benchmark
def _run() -> None:
loop.run_until_complete(run_url_dispatcher_benchmark())


def test_resolve_prefix_resources_many_prefix_many_plain(
loop: asyncio.AbstractEventLoop,
benchmark: BenchmarkFixture,
) -> None:
"""Resolve prefix resource (sub_app) whene 250 PlainResources registered and there are 250 subapps that shares the same sub_app path prefix."""

async def handler(request: web.Request) -> NoReturn:
assert False

app = web.Application()
for count in range(250):
app.router.add_get(f"/api/server/other/{count}/update", handler)
for count in range(250):
subapp = web.Application()
# sub_apps exists for handling deep enough nested route trees
subapp.router.add_get("/deep/enough/sub/path", handler)
app.add_subapp(f"/api/path/to/plugin/{count}", subapp)
app.freeze()
router = app.router

requests = [
_mock_request(method="GET", path="/api/path/to/plugin/249/deep/enough/sub/path")
for customer in range(250)
]

async def run_url_dispatcher_benchmark() -> None:
for request in requests:
await router.resolve(request)

@benchmark
def _run() -> None:
loop.run_until_complete(run_url_dispatcher_benchmark())
Loading