Skip to content

Commit a7ef695

Browse files
authored
Various updates (#24)
1 parent b280ed4 commit a7ef695

17 files changed

+764
-99
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
hooks:
1717
- id: ruff
1818
args: ["--fix"]
19-
exclude: "frameworks*"
19+
exclude: "test_data"
2020
- repo: https://github.com/psf/black
2121
rev: 23.7.0
2222
hooks:

Diff for: README.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
> [**_Starlite has been renamed to Litestar_**](https://litestar.dev/about/organization.html#litestar-and-starlite)
2424
2525
This is an API performance test comparing:
26+
2627
1. [Litestar](https://github.com/litestar-org/litestar)
2728
2. [Starlite v1.5x](https://github.com/litestar-org/litestar/tree/v1.51)
2829
3. [Starlette](https://github.com/encode/starlette)
@@ -32,15 +33,6 @@ This is an API performance test comparing:
3233

3334
Using the [bombardier](https://github.com/codesenberg/bombardier) HTTP benchmarking tool.
3435

35-
## Last Run Results
36-
37-
![Plain Text Results](result.png)
38-
39-
You can view the last run results under the `/results` folder - it contains json files with the output.
40-
The plotting is done using pandas - script is under `/analysis`.
41-
42-
Note: PRs improving the analysis script are welcome.
43-
4436
## Test Setup
4537

4638
Setup is identical for all frameworks.
@@ -153,7 +145,7 @@ You can run a single test by specifying its full name and category:
153145
#### Test Settings
154146

155147
| | |
156-
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
148+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
157149
| -r, --rebuild | rebuild docker images |
158150
| -L, --latency | run latency tests |
159151
| -R, --rps | run RPS tests |

Diff for: asgi_bench/build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def build_docker_images(framework_specs: list[FrameworkSpec], rebuild: bool = Fa
3737
client = docker.from_env()
3838

3939
with console.status("[yellow]Building runner image"):
40-
client.images.build(path=".", dockerfile="DockerfileBench", tag="starlite-api-bench:runner")
40+
client.images.build(path=".", dockerfile="DockerfileBench", tag="litestar-bench:runner")
4141
console.print("[green] Runner image built successfully")
4242

4343
for framework in framework_specs:
@@ -68,5 +68,5 @@ def remove_docker_images(client: docker.DockerClient | None = None, force: bool
6868
client = docker.from_env()
6969
with console.status("[yellow]Removing all images"):
7070
for image in client.images.list():
71-
if any(tag.startswith("starlite-api-bench:") for tag in image.tags):
71+
if any(tag.startswith("litestar-bench:") for tag in image.tags):
7272
image.remove(force=force)

Diff for: asgi_bench/runner.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _run_image(self, image: str) -> Container:
139139

140140
def _run_bench_in_container(self, *args: str) -> str:
141141
container = self.docker_client.containers.run(
142-
"starlite-api-bench:runner", "./bombardier " + " ".join(args), network_mode="host", detach=True
142+
"litestar-bench:runner", "./bombardier " + " ".join(args), network_mode="host", detach=True
143143
)
144144
container.wait()
145145
return container.logs().decode()
@@ -162,7 +162,7 @@ def _validate_bench_endpoint(self, test_spec: TestSpec) -> bool:
162162
def _stop_all_containers(self) -> None:
163163
with self.console.status("[yellow]Stopping running containers"):
164164
for container in self.docker_client.containers.list(ignore_removed=True):
165-
if any(tag.startswith("starlite-api-bench:") for tag in container.image.tags):
165+
if any(tag.startswith("litestar-bench:") for tag in container.image.tags):
166166
container.kill()
167167

168168
def run_benchmark(self, test_spec: TestSpec) -> dict[str, Any]:
@@ -204,10 +204,7 @@ def provide_service(self, spec: FrameworkSpec) -> Generator[bool, None, None]:
204204
try:
205205
container.kill()
206206
except APIError as error:
207-
if (
208-
error.status_code != 409
209-
or "not running" not in error.explanation
210-
):
207+
if not (error.status_code == 409 and "not running" in error.explanation):
211208
# the container stopped for reasons
212209
raise error
213210
yield False

Diff for: asgi_bench/spec.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ def supports_framework(self, framework: str, mode: EndpointMode) -> bool:
3737
class TestCategory:
3838
name: EndpointCategory
3939
endpoints: list[Endpoint]
40-
frameworks: tuple[Framework, ...] = ("starlite", "starlette", "fastapi", "sanic", "blacksheep", "quart")
40+
frameworks: tuple[Framework, ...] = (
41+
"litestar",
42+
"starlite",
43+
"starlette",
44+
"fastapi",
45+
"sanic",
46+
"blacksheep",
47+
"quart",
48+
)
4149

4250

4351
TEST_CATEGORIES: list[TestCategory] = [
@@ -91,7 +99,7 @@ class TestCategory:
9199
),
92100
TestCategory(
93101
name="dependency-injection",
94-
frameworks=("starlite", "fastapi", "sanic", "blacksheep"),
102+
frameworks=("litestar", "fastapi", "sanic", "blacksheep"),
95103
endpoints=[
96104
Endpoint(path="dependencies-sync", name="dependencies sync"),
97105
Endpoint(path="dependencies-async", name="dependencies async", exclude=["sanic", "blacksheep"]),
@@ -100,7 +108,7 @@ class TestCategory:
100108
),
101109
TestCategory(
102110
name="serialization",
103-
frameworks=("starlite", "fastapi"),
111+
frameworks=("litestar", "fastapi"),
104112
endpoints=[
105113
Endpoint(path="serialize-pydantic-50", name="serialize pydantic, 50 objects"),
106114
Endpoint(path="serialize-pydantic-100", name="serialize pydantic, 100 objects"),
@@ -254,7 +262,7 @@ def make_spec(
254262

255263

256264
FRAMEWORK_REPOS: dict[Framework, str] = {
257-
"starlite": "https://github.com/starlite-api/starlite.git",
265+
"litestar": "https://github.com/litestar-org/litestar.git",
258266
"starlette": "https://github.com/encode/starlette.git",
259267
"fastapi": "https://github.com/tiangolo/fastapi.git",
260268
"sanic": "https://github.com/sanic-org/sanic.git",

Diff for: asgi_bench/types.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818
BenchmarkMode = Literal["rps", "latency"]
1919
VersionPrefix = Literal["pip", "git", "docker", "file"]
20-
Framework = Literal["starlite", "starlette", "fastapi", "sanic", "blacksheep", "quart", "litestar"]
20+
Framework = Literal["litestar", "starlite", "starlette", "fastapi", "sanic", "blacksheep", "quart"]
2121

2222

2323
@dataclass
@@ -85,7 +85,7 @@ def is_pip_target(self) -> bool:
8585
@property
8686
def image_tag(self) -> str:
8787
versioned_name = self.version_name.replace(":", "_").replace("/", "_").replace(".git", "")
88-
return f"starlite-api-bench:{versioned_name}"
88+
return f"litestar-bench:{versioned_name}"
8989

9090
@property
9191
def build_stage_image(self) -> str | None:
@@ -116,7 +116,9 @@ def pip_package(self) -> str:
116116
from .spec import FRAMEWORK_REPOS
117117

118118
return f"git+{FRAMEWORK_REPOS[self.name]}@{version}"
119-
return version if prefix == "file" else f"{self.name}=={self.version}"
119+
if prefix == "file":
120+
return version
121+
return f"{self.name}=={self.version}"
120122

121123
@property
122124
def extra_requirements(self) -> list[str]:

Diff for: frameworks/__init__.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
from . import blacksheep_app, fastapi_app, sanic_app, starlette_app, starlite_app, quart_app
1+
from . import (
2+
blacksheep_app,
3+
fastapi_app,
4+
litestar_app,
5+
quart_app,
6+
sanic_app,
7+
starlette_app,
8+
starlite_app,
9+
)
210

3-
__all__ = ["blacksheep_app", "fastapi_app", "sanic_app", "starlite_app", "starlette_app", "quart_app"]
11+
__all__ = [
12+
"blacksheep_app",
13+
"fastapi_app",
14+
"litestar_app",
15+
"quart_app",
16+
"sanic_app",
17+
"starlette_app",
18+
"starlite_app",
19+
]

Diff for: frameworks/blacksheep_app.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ async def async_dependencies_sync(
375375

376376
@app.router.post("/async-post-json")
377377
async def async_post_json(request: Request) -> Response:
378-
data = await request.json()
378+
await request.json()
379379
return no_content()
380380

381381

@@ -410,11 +410,11 @@ def sync_post_form_urlencoded(request: Request, data: FromForm) -> Response:
410410

411411
@app.router.post("/sync-post-file")
412412
def sync_post_file(request: Request, data: FromFiles) -> Response:
413-
content = data.value[0].data
413+
data.value[0].data
414414
return no_content()
415415

416416

417417
@app.router.post("/async-post-file")
418418
async def async_post_file(request: Request, data: FromFiles) -> Response:
419-
content = data.value[0].data
419+
data.value[0].data
420420
return no_content()

Diff for: frameworks/fastapi_app.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ def sync_dependency_one() -> str:
307307

308308

309309
def sync_dependency_two(
310-
injected_sync_one: str = Depends(sync_dependency_one), # noqa: B008
310+
injected_sync_one: str = Depends(sync_dependency_one),
311311
) -> list[str]:
312312
time.sleep(0.00000001)
313313
return [injected_sync_one, "sync_dependency_two"]
314314

315315

316316
def sync_dependency_three(
317-
injected_sync_two: list[str] = Depends(sync_dependency_two), # noqa: B008
317+
injected_sync_two: list[str] = Depends(sync_dependency_two),
318318
) -> list[str]:
319319
time.sleep(0.00000001)
320320
return [*injected_sync_two, "sync_dependency_three"]
@@ -326,84 +326,84 @@ async def async_dependency_one() -> str:
326326

327327

328328
async def async_dependency_two(
329-
injected_async_one: str = Depends(async_dependency_one), # noqa: B008
329+
injected_async_one: str = Depends(async_dependency_one),
330330
) -> list[str]:
331331
await anyio.sleep(0.00000001)
332332
return [injected_async_one, "async_dependency_two"]
333333

334334

335335
async def async_dependency_three(
336-
injected_async_two: list[str] = Depends(async_dependency_two), # noqa: B008
336+
injected_async_two: list[str] = Depends(async_dependency_two),
337337
) -> list[str]:
338338
await anyio.sleep(0.00000001)
339339
return [*injected_async_two, "async_dependency_three"]
340340

341341

342342
async def dependencies_mixed(
343-
injected_sync_three: list[str] = Depends(sync_dependency_three), # noqa: B008
344-
injected_async_three: list[str] = Depends(async_dependency_three), # noqa: B008
343+
injected_sync_three: list[str] = Depends(sync_dependency_three),
344+
injected_async_three: list[str] = Depends(async_dependency_three),
345345
) -> tuple[list[str], list[str]]:
346346
return injected_sync_three, injected_async_three
347347

348348

349349
@app.get("/sync-dependencies-sync")
350350
def sync_dependencies_sync(
351-
injected_sync_one: str = Depends(sync_dependency_one), # noqa: B008
352-
injected_sync_two: list[str] = Depends(sync_dependency_two), # noqa: B008
353-
injected_sync_three: list[str] = Depends(sync_dependency_three), # noqa: B008
351+
injected_sync_one: str = Depends(sync_dependency_one),
352+
injected_sync_two: list[str] = Depends(sync_dependency_two),
353+
injected_sync_three: list[str] = Depends(sync_dependency_three),
354354
) -> list[str]:
355355
return injected_sync_three
356356

357357

358358
@app.get("/sync-dependencies-async")
359359
def sync_dependencies_async(
360-
injected_async_one: str = Depends(async_dependency_one), # noqa: B008
361-
injected_async_two: list[str] = Depends(async_dependency_two), # noqa: B008
362-
injected_async_three: list[str] = Depends(async_dependency_three), # noqa: B008
360+
injected_async_one: str = Depends(async_dependency_one),
361+
injected_async_two: list[str] = Depends(async_dependency_two),
362+
injected_async_three: list[str] = Depends(async_dependency_three),
363363
) -> list[str]:
364364
return injected_async_three
365365

366366

367367
@app.get("/sync-dependencies-mixed")
368368
def sync_dependencies_mixed(
369-
injected_sync_one: str = Depends(sync_dependency_one), # noqa: B008
370-
injected_sync_two: list[str] = Depends(sync_dependency_two), # noqa: B008
371-
injected_sync_three: list[str] = Depends(sync_dependency_three), # noqa: B008
372-
injected_async_one: str = Depends(async_dependency_one), # noqa: B008
373-
injected_async_two: list[str] = Depends(async_dependency_two), # noqa: B008
374-
injected_async_three: list[str] = Depends(async_dependency_three), # noqa: B008
375-
injected_mixed: tuple[list[str], list[str]] = Depends(dependencies_mixed), # noqa: B008
369+
injected_sync_one: str = Depends(sync_dependency_one),
370+
injected_sync_two: list[str] = Depends(sync_dependency_two),
371+
injected_sync_three: list[str] = Depends(sync_dependency_three),
372+
injected_async_one: str = Depends(async_dependency_one),
373+
injected_async_two: list[str] = Depends(async_dependency_two),
374+
injected_async_three: list[str] = Depends(async_dependency_three),
375+
injected_mixed: tuple[list[str], list[str]] = Depends(dependencies_mixed),
376376
) -> tuple[list[str], list[str]]:
377377
return injected_mixed
378378

379379

380380
@app.get("/async-dependencies-sync")
381381
async def async_dependencies_sync(
382-
injected_sync_one: str = Depends(sync_dependency_one), # noqa: B008
383-
injected_sync_two: list[str] = Depends(sync_dependency_two), # noqa: B008
384-
injected_sync_three: list[str] = Depends(sync_dependency_three), # noqa: B008
382+
injected_sync_one: str = Depends(sync_dependency_one),
383+
injected_sync_two: list[str] = Depends(sync_dependency_two),
384+
injected_sync_three: list[str] = Depends(sync_dependency_three),
385385
) -> list[str]:
386386
return injected_sync_three
387387

388388

389389
@app.get("/async-dependencies-async")
390390
async def async_dependencies_async(
391-
injected_async_one: str = Depends(async_dependency_one), # noqa: B008
392-
injected_async_two: list[str] = Depends(async_dependency_two), # noqa: B008
393-
injected_async_three: list[str] = Depends(async_dependency_three), # noqa: B008
391+
injected_async_one: str = Depends(async_dependency_one),
392+
injected_async_two: list[str] = Depends(async_dependency_two),
393+
injected_async_three: list[str] = Depends(async_dependency_three),
394394
) -> list[str]:
395395
return injected_async_three
396396

397397

398398
@app.get("/async-dependencies-mixed")
399399
async def async_dependencies_mixed(
400-
injected_sync_one: str = Depends(sync_dependency_one), # noqa: B008
401-
injected_sync_two: list[str] = Depends(sync_dependency_two), # noqa: B008
402-
injected_sync_three: list[str] = Depends(sync_dependency_three), # noqa: B008
403-
injected_async_one: str = Depends(async_dependency_one), # noqa: B008
404-
injected_async_two: list[str] = Depends(async_dependency_two), # noqa: B008
405-
injected_async_three: list[str] = Depends(async_dependency_three), # noqa: B008
406-
injected_mixed: tuple[list[str], list[str]] = Depends(dependencies_mixed), # noqa: B008
400+
injected_sync_one: str = Depends(sync_dependency_one),
401+
injected_sync_two: list[str] = Depends(sync_dependency_two),
402+
injected_sync_three: list[str] = Depends(sync_dependency_three),
403+
injected_async_one: str = Depends(async_dependency_one),
404+
injected_async_two: list[str] = Depends(async_dependency_two),
405+
injected_async_three: list[str] = Depends(async_dependency_three),
406+
injected_mixed: tuple[list[str], list[str]] = Depends(dependencies_mixed),
407407
) -> tuple[list[str], list[str]]:
408408
return injected_mixed
409409

@@ -492,25 +492,25 @@ async def async_post_json(data: list) -> None:
492492

493493
@app.post("/async-post-multipart-form", status_code=HTTP_204_NO_CONTENT)
494494
async def async_post_multipart_form(request: Request) -> None:
495-
data = await request.form()
495+
await request.form()
496496

497497

498498
# form urlencoded
499499

500500

501501
@app.post("/async-post-form-urlencoded", status_code=HTTP_204_NO_CONTENT)
502502
async def async_post_form_urlencoded(request: Request) -> None:
503-
data = await request.form()
503+
await request.form()
504504

505505

506506
# upload files
507507

508508

509509
@app.post("/sync-post-file", status_code=HTTP_204_NO_CONTENT)
510510
def sync_post_file(test_file: UploadFile) -> None:
511-
content = test_file.file.read()
511+
test_file.file.read()
512512

513513

514514
@app.post("/async-post-file", status_code=HTTP_204_NO_CONTENT)
515515
async def async_post_file(test_file: UploadFile) -> None:
516-
content = await test_file.read()
516+
await test_file.read()

0 commit comments

Comments
 (0)