Skip to content

Commit b9a3ff5

Browse files
authored
feat: add litestar benchmark target (#23)
1 parent a7ef695 commit b9a3ff5

File tree

10 files changed

+110
-14
lines changed

10 files changed

+110
-14
lines changed

.github/CODEOWNERS

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Code owner settings for `api-performance-tests`
2+
# @maintainers should be assigned to all reviews.
3+
# Most specific assignment takes precedence though, so if you add a more specific thing than the `*` glob, you must also add @maintainers
4+
# For more info about code owners see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-example
5+
6+
# Global Assignment
7+
* @litestar-org/maintainers @litestar-org/members

.github/dependabot.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/workflows/ci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
validate:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.11"
15+
- name: Install Pre-Commit
16+
run: python -m pip install pre-commit && pre-commit install
17+
- name: Load cached Pre-Commit Dependencies
18+
id: cached-pre-commit-dependencies
19+
uses: actions/cache@v3
20+
with:
21+
path: ~/.cache/pre-commit/
22+
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
23+
- name: Execute Pre-Commit
24+
run: pre-commit run --show-diff-on-failure --color=always --all-files
25+
test:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: true
29+
matrix:
30+
python-version: ["3.11"]
31+
steps:
32+
- name: Check out repository
33+
uses: actions/checkout@v3
34+
- name: Set up python ${{ matrix.python-version }}
35+
uses: actions/setup-python@v4
36+
with:
37+
python-version: ${{ matrix.python-version }}
38+
- name: Install Poetry
39+
uses: snok/install-poetry@v1
40+
with:
41+
virtualenvs-create: true
42+
virtualenvs-in-project: true
43+
installer-parallel: true
44+
- name: Load cached venv
45+
id: cached-poetry-dependencies
46+
uses: actions/cache@v3
47+
with:
48+
path: .venv
49+
key: v1-venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
50+
- name: Install dependencies
51+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
52+
run: poetry install --no-interaction
53+
- name: Set pythonpath
54+
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
55+
- name: Test with Coverage
56+
if: matrix.python-version == '3.11'
57+
run: poetry run pytest --cov=. --cov-report=xml
58+
- uses: actions/upload-artifact@v3
59+
if: matrix.python-version == '3.11'
60+
with:
61+
name: coverage-xml
62+
path: coverage.xml

Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: install
2+
install: ## Install all dependencies
3+
poetry install --extras test --with lint
4+
pre-commit install
5+
6+
.PHONY: sourcery
7+
sourcery: ## Run sourcery
8+
poetry run sourcery review --fix .
9+
10+
.PHONY: tests
11+
test: ## Run tests
12+
pytest tests
13+
14+
.PHONY: clean
15+
clean: ## Remove all generated files
16+
rm -rf .mypy_cache
17+
find . -type d -name ".pytest_cache" -exec rm -rf {} +
18+
rm -rf .ruff_cache
19+
rm -rf results
20+
21+
.PHONY: lint
22+
lint: ## Run linters
23+
poetry run pre-commit run --all-files

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Serializing a dictionary into JSON
6767

6868
##### Serialization
6969

70-
(only supported by `Litestar` and `FastAPI`)
70+
(only supported by `Litestar`, `Starlite`, and `FastAPI`)
7171

7272
- Serializing 50 dataclass objects each referencing 2 more dataclass objects
7373
- Serializing 100 dataclass objects each referencing 5 more dataclass objects
@@ -97,8 +97,8 @@ All responses return "No Content"
9797
(not supported by `Starlette`)
9898

9999
- Resolving 3 nested synchronous dependencies
100-
- Resolving 3 nested asynchronous dependencies (only supported by `Litestar` and `FastAPI`)
101-
- Resolving 3 nested synchronous, and 3 nested asynchronous dependencies (only supported by `Litestar` and `FastAPI`)
100+
- Resolving 3 nested asynchronous dependencies (only supported by `Litestar`, `Starlite`, and `FastAPI`)
101+
- Resolving 3 nested synchronous, and 3 nested asynchronous dependencies (only supported by `Litestar`, `Starlite`, and `FastAPI`)
102102

103103
#### Modifying responses
104104

@@ -127,11 +127,11 @@ After the run, the results will be stored in `results/run_<run_mumber>.json`
127127

128128
To select a framework, simply pass its name to the `run command`:
129129

130-
`bench run --rps litestar starlette fastapi`
130+
`bench run --rps litestar starlite starlette fastapi`
131131

132132
##### Selecting a framework version
133133

134-
- A version available on PyPi: `bench run --rps litestar@v1.40.0`
134+
- A version available on PyPi: `bench run --rps litestar@v2.0.0`
135135
- A version from git: `bench run --rps litestar@git+branch_or_tag_name`
136136
- A version from a specific git repository: `bench run --rps litestar@git+https://github.com/litestar-org/litestar.git@branch_or_tag_name`
137137
- A local file: `bench run --rps litestar@file+/path/to/litestar`

asgi_bench/cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from asgi_bench.types import BenchmarkMode, EndpointCategory, EndpointMode
88

99

10-
@click.group()
10+
@click.group(help="ASGI benchmarking tool", context_settings={"help_option_names": ["-h", "--help"]})
1111
def cli() -> None:
1212
pass
1313

1414

15-
@cli.command()
15+
@cli.command(help="run benchmarks")
1616
@click.argument("frameworks", nargs=-1)
1717
@click.option("--rebuild", is_flag=True, show_default=True, help="rebuild images")
1818
@click.option("-w", "--warmup", default=5, show_default=True)
@@ -86,7 +86,7 @@ def run(
8686
runner.run()
8787

8888

89-
@cli.command("results")
89+
@cli.command("results", help="generate result tables and plots")
9090
@click.option("-r", "--run", "run_name", type=int, help="run to analyze (defaults to latest run)")
9191
@click.option(
9292
"-f",

asgi_bench/runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def provide_service(self, spec: FrameworkSpec) -> Generator[bool, None, None]:
204204
try:
205205
container.kill()
206206
except APIError as error:
207-
if not (error.status_code == 409 and "not running" in error.explanation):
207+
if error.status_code != 409 or "not running" not in error.explanation:
208208
# the container stopped for reasons
209209
raise error
210210
yield False

asgi_bench/spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def make_spec(
201201
rate_limit: int | None = None,
202202
benchmark_modes: tuple[BenchmarkMode, ...] | BenchmarkMode,
203203
test_name: str | None = None,
204-
) -> list[FrameworkSpec]:
204+
) -> list[FrameworkSpec]: # sourcery skip: low-code-quality
205205
if isinstance(endpoint_modes, str):
206206
endpoint_modes = (endpoint_modes,)
207207
if isinstance(categories, str):

asgi_bench/types.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def pip_package(self) -> str:
116116
from .spec import FRAMEWORK_REPOS
117117

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

123121
@property
124122
def extra_requirements(self) -> list[str]:

tests/test_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_spec_targets(
3737
version_name: str,
3838
):
3939
spec = FrameworkSpec(name="litestar", version=version, path=Path(), tests=[])
40-
if pip_package:
40+
if pip_package: # sourcery skip: no-conditionals-in-tests
4141
assert spec.pip_package == pip_package
4242
assert spec.typed_version == (type_, clean_version)
4343
assert spec.image_tag == f"litestar-bench:{image_tag}"

0 commit comments

Comments
 (0)