Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions frameworks/Python/granian/app_rsgi_nogil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json

JSON_HEADERS = [('content-type', 'application/json')]
PLAINTEXT_HEADERS = [('content-type', 'text/plain; charset=utf-8')]

# json_dumps = orjson.dumps
json_dumps = json.dumps


async def route_json(scope, proto):
proto.response_str(
200,
JSON_HEADERS,
json_dumps({'message': 'Hello, world!'})
)


async def route_plaintext(scope, proto):
proto.response_bytes(
200,
PLAINTEXT_HEADERS,
b'Hello, world!'
)


async def handle_404(scope, proto):
proto.response_bytes(
404,
PLAINTEXT_HEADERS,
b'Not found'
)


routes = {
'/json': route_json,
'/plaintext': route_plaintext
}


def main(scope, proto):
handler = routes.get(scope.path, handle_404)
return handler(scope, proto)
4 changes: 2 additions & 2 deletions frameworks/Python/granian/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"notes": "",
"versus": "uvicorn"
},
"wrk": {
"nogil": {
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
Expand All @@ -77,7 +77,7 @@
"webserver": "granian",
"os": "Linux",
"database_os": "Linux",
"display_name": "granian [rsgi wrk]",
"display_name": "granian [rsgi nogil]",
"notes": "",
"versus": "uvicorn"
}
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Python/granian/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ platform = "None"
webserver = "granian"
versus = "uvicorn"

[wrk]
[nogil]
urls.plaintext = "/plaintext"
urls.json = "/json"
approach = "Realistic"
Expand Down
16 changes: 16 additions & 0 deletions frameworks/Python/granian/granian-nogil.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ghcr.io/astral-sh/uv:debian-slim

RUN uv python install 3.14t

ENV UV_PYTHON=3.14t
ENV PYTHON_GIL=0

ADD ./ /granian
WORKDIR /granian

RUN uv venv
RUN uv pip install -r requirements-nogil.txt

EXPOSE 8080

CMD uv run python run_nogil.py rsgi st
4 changes: 2 additions & 2 deletions frameworks/Python/granian/granian-rsgi.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.13-slim

ADD ./ /granian

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

EXPOSE 8080

CMD python run.py rsgi mt
CMD python run.py rsgi st
11 changes: 0 additions & 11 deletions frameworks/Python/granian/granian-wrk.dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion frameworks/Python/granian/granian-wsgi.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.13-slim

ADD ./ /granian

Expand Down
4 changes: 2 additions & 2 deletions frameworks/Python/granian/granian.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.13-slim

ADD ./ /granian

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

EXPOSE 8080

CMD python run.py asgi mt
CMD python run.py asgi st
1 change: 1 addition & 0 deletions frameworks/Python/granian/requirements-nogil.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
granian[rloop]>=2.5.0,<2.6.0
4 changes: 2 additions & 2 deletions frameworks/Python/granian/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncpg==0.30.0
granian[uvloop]>=2.4.0,<2.5.0
granian[uvloop]>=2.5.0,<2.6.0
jinja2==3.1.6
orjson==3.10.16
orjson==3.11.3
32 changes: 32 additions & 0 deletions frameworks/Python/granian/run_nogil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import multiprocessing
import sys

from granian import Granian


if __name__ == '__main__':
interface = sys.argv[1]
runtime_mode = sys.argv[2]
workers = multiprocessing.cpu_count()

if interface == "rsgi":
#: leave 25% cpu to the Rust runtime
workers = round(workers * 0.75)

blocking_threads = None
if interface == "wsgi":
#: we don't run any I/O in WSGI benches
blocking_threads = 1

Granian(
f"app_{interface}_nogil:main",
address="0.0.0.0",
port=8080,
workers=workers,
runtime_mode=runtime_mode,
blocking_threads=blocking_threads,
backlog=16384,
interface=interface,
http="1",
websockets=False
).serve()
Loading