Skip to content

Commit 43edfc1

Browse files
authored
[Python] Update Granian to 2.5, remove "wrk" variant, add "nogil" variant (TechEmpower#10177)
1 parent 67852f7 commit 43edfc1

File tree

11 files changed

+101
-21
lines changed

11 files changed

+101
-21
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
3+
JSON_HEADERS = [('content-type', 'application/json')]
4+
PLAINTEXT_HEADERS = [('content-type', 'text/plain; charset=utf-8')]
5+
6+
# json_dumps = orjson.dumps
7+
json_dumps = json.dumps
8+
9+
10+
async def route_json(scope, proto):
11+
proto.response_str(
12+
200,
13+
JSON_HEADERS,
14+
json_dumps({'message': 'Hello, world!'})
15+
)
16+
17+
18+
async def route_plaintext(scope, proto):
19+
proto.response_bytes(
20+
200,
21+
PLAINTEXT_HEADERS,
22+
b'Hello, world!'
23+
)
24+
25+
26+
async def handle_404(scope, proto):
27+
proto.response_bytes(
28+
404,
29+
PLAINTEXT_HEADERS,
30+
b'Not found'
31+
)
32+
33+
34+
routes = {
35+
'/json': route_json,
36+
'/plaintext': route_plaintext
37+
}
38+
39+
40+
def main(scope, proto):
41+
handler = routes.get(scope.path, handle_404)
42+
return handler(scope, proto)

frameworks/Python/granian/benchmark_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"notes": "",
6464
"versus": "uvicorn"
6565
},
66-
"wrk": {
66+
"nogil": {
6767
"json_url": "/json",
6868
"plaintext_url": "/plaintext",
6969
"port": 8080,
@@ -77,7 +77,7 @@
7777
"webserver": "granian",
7878
"os": "Linux",
7979
"database_os": "Linux",
80-
"display_name": "granian [rsgi wrk]",
80+
"display_name": "granian [rsgi nogil]",
8181
"notes": "",
8282
"versus": "uvicorn"
8383
}

frameworks/Python/granian/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ platform = "None"
4848
webserver = "granian"
4949
versus = "uvicorn"
5050

51-
[wrk]
51+
[nogil]
5252
urls.plaintext = "/plaintext"
5353
urls.json = "/json"
5454
approach = "Realistic"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ghcr.io/astral-sh/uv:debian-slim
2+
3+
RUN uv python install 3.14t
4+
5+
ENV UV_PYTHON=3.14t
6+
ENV PYTHON_GIL=0
7+
8+
ADD ./ /granian
9+
WORKDIR /granian
10+
11+
RUN uv venv
12+
RUN uv pip install -r requirements-nogil.txt
13+
14+
EXPOSE 8080
15+
16+
CMD uv run python run_nogil.py rsgi st
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.10-slim
1+
FROM python:3.13-slim
22

33
ADD ./ /granian
44

@@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt
88

99
EXPOSE 8080
1010

11-
CMD python run.py rsgi mt
11+
CMD python run.py rsgi st

frameworks/Python/granian/granian-wrk.dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

frameworks/Python/granian/granian-wsgi.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.10-slim
1+
FROM python:3.13-slim
22

33
ADD ./ /granian
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.10-slim
1+
FROM python:3.13-slim
22

33
ADD ./ /granian
44

@@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt
88

99
EXPOSE 8080
1010

11-
CMD python run.py asgi mt
11+
CMD python run.py asgi st
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
granian[rloop]>=2.5.0,<2.6.0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
asyncpg==0.30.0
2-
granian[uvloop]>=2.4.0,<2.5.0
2+
granian[uvloop]>=2.5.0,<2.6.0
33
jinja2==3.1.6
4-
orjson==3.10.16
4+
orjson==3.11.3

0 commit comments

Comments
 (0)