Skip to content

Commit 979ea8e

Browse files
authored
Merge pull request #575 from ATOMMAX-2001/slimeweb-python
New: Slimeweb -python
2 parents 03a4ff4 + 8bd3dfa commit 979ea8e

41 files changed

Lines changed: 616 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frameworks/slimeweb/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.13-slim
2+
3+
WORKDIR /app
4+
5+
RUN pip install --no-cache-dir uv slimeweb
6+
7+
RUN slime new arena
8+
9+
WORKDIR /app/arena
10+
11+
RUN slime add asyncpg
12+
13+
COPY main.py /app/arena/main.py
14+
15+
EXPOSE 8080
16+
17+
CMD ["slime","run","main.py"]

frameworks/slimeweb/main.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import json
2+
import os
3+
4+
import asyncpg as pg
5+
from slimeweb import Slime, SlimeCompression
6+
7+
app = Slime(__file__)
8+
9+
10+
def load_json_processing_file():
11+
with open("/data/dataset.json", "r") as file:
12+
return json.load(file)
13+
14+
15+
JSON_DATASET = load_json_processing_file()
16+
QUERY_STMT = """
17+
SELECT id, name, category, price, quantity, active, tags, rating_score, rating_count
18+
FROM items
19+
WHERE price BETWEEN $1 AND $2
20+
LIMIT $3
21+
"""
22+
DB_POOL = None
23+
24+
25+
@app.route("/baseline11", method=["GET", "POST"])
26+
def baseline_test(req, resp):
27+
if req.method == "GET":
28+
result = 0
29+
for q_val in req.query.values():
30+
try:
31+
result += int(q_val)
32+
except ValueError:
33+
pass
34+
return resp.plain(str(result))
35+
else:
36+
result = 0
37+
for q_val in req.query.values():
38+
try:
39+
result += int(q_val)
40+
except ValueError:
41+
pass
42+
try:
43+
result += int(req.text)
44+
except ValueError:
45+
pass
46+
return resp.plain(str(result))
47+
48+
49+
@app.route("/pipeline", method="GET")
50+
def pipeline_test(req, resp):
51+
return resp.plain("ok")
52+
53+
54+
# body_size by default it will read 10MB
55+
# setting read_size as 25MB
56+
@app.route("/upload", method="POST", body_size=1024 * 1024 * 25)
57+
def upload_test(req, resp):
58+
result = len(req.body)
59+
return resp.plain(str(result))
60+
61+
62+
@app.route(
63+
"/json/{count}", method="GET", compression=SlimeCompression.All, comp_level=1
64+
)
65+
def json_test(req, resp):
66+
global JSON_DATASET
67+
count = int(req.params["count"])
68+
multiplier = int(req.query["m"])
69+
result = []
70+
for data in JSON_DATASET[:count]:
71+
result.append(
72+
{
73+
"id": data["id"],
74+
"name": data["name"],
75+
"category": data["category"],
76+
"price": data["price"],
77+
"quantity": data["quantity"],
78+
"active": data["active"],
79+
"tags": data["tags"],
80+
"rating": {
81+
"score": data["rating"]["score"],
82+
"count": data["rating"]["count"],
83+
},
84+
"total": data["price"] * data["quantity"] * multiplier,
85+
}
86+
)
87+
return resp.json({"items": result, "count": count})
88+
89+
90+
# Websocket in slime are event driven
91+
# echo back based on the message type
92+
@app.websocket("/ws")
93+
def websocket_test(req, resp):
94+
def echo_me(msg):
95+
if isinstance(msg, str):
96+
return resp.send_text(msg)
97+
else:
98+
return resp.send_bytes(msg)
99+
100+
resp.on_message(echo_me)
101+
102+
103+
@app.route("/async-db", method="GET")
104+
async def async_db_test(req, resp):
105+
global QUERY_STMT, DB_POOL
106+
if DB_POOL is None:
107+
return resp.json({"items": [], "count": 0})
108+
min = int(req.query["min"])
109+
max = int(req.query["max"])
110+
limit = int(req.query["limit"])
111+
result = []
112+
data_result = None
113+
async with DB_POOL.acquire() as conn:
114+
data_result = await conn.fetch(QUERY_STMT, min, max, limit)
115+
for data in data_result:
116+
result.append(
117+
{
118+
"id": data["id"],
119+
"name": data["name"],
120+
"category": data["category"],
121+
"price": data["price"],
122+
"quantity": data["quantity"],
123+
"active": data["active"],
124+
"tags": json.loads(data["tags"]),
125+
"rating": {
126+
"score": data["rating_score"],
127+
"count": data["rating_count"],
128+
},
129+
}
130+
)
131+
return resp.json({"items": result, "count": len(result)})
132+
133+
134+
@app.start()
135+
async def init():
136+
global DB_POOL
137+
try:
138+
DB_POOL = await pg.create_pool(
139+
dsn=os.environ["DATABASE_URL"],
140+
min_size=5,
141+
max_size=int(os.environ.get("DATABASE_MAX_CONN", 256)),
142+
)
143+
print("Pool is created successfully")
144+
except Exception as e:
145+
print("Failed to create pool", e)
146+
DB_POOL = None
147+
148+
149+
if __name__ == "__main__":
150+
app.serve(host="0.0.0.0", port=8080, static_path="/data/static")

frameworks/slimeweb/meta.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"display_name": "SlimeWeb",
3+
"language": "Python",
4+
"type": "tuned",
5+
"engine": "hyper",
6+
"description": "SlimeWeb is a fast lightweight framework for python powered by rust",
7+
"repo": "https://github.com/ATOMMAX-2001/Slime/",
8+
"enabled": true,
9+
"tests": [
10+
"baseline",
11+
"pipelined",
12+
"limited-conn",
13+
"json",
14+
"json-comp",
15+
"upload",
16+
"echo-ws",
17+
"api-4",
18+
"api-16",
19+
"static",
20+
"async-db"
21+
],
22+
"maintainers": ["ATOMMAX-2001"]
23+
}

site/data/api-16-1024.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,32 @@
718718
"tpl_static": 0,
719719
"tpl_async_db": 163326
720720
},
721+
{
722+
"framework": "SlimeWeb",
723+
"language": "Python",
724+
"rps": 12236,
725+
"avg_latency": "72.57ms",
726+
"p99_latency": "1.38s",
727+
"cpu": "403.8%",
728+
"memory": "154MiB",
729+
"connections": 1024,
730+
"threads": 64,
731+
"duration": "5s",
732+
"pipeline": 1,
733+
"bandwidth": "62.97MB/s",
734+
"input_bw": "705.00KB/s",
735+
"reconnects": 36510,
736+
"status_2xx": 183546,
737+
"status_3xx": 0,
738+
"status_4xx": 0,
739+
"status_5xx": 0,
740+
"tpl_baseline": 66774,
741+
"tpl_json": 72402,
742+
"tpl_db": 0,
743+
"tpl_upload": 0,
744+
"tpl_static": 0,
745+
"tpl_async_db": 44369
746+
},
721747
{
722748
"framework": "spring-boot",
723749
"language": "Java",

site/data/api-4-256.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,32 @@
718718
"tpl_static": 0,
719719
"tpl_async_db": 65218
720720
},
721+
{
722+
"framework": "SlimeWeb",
723+
"language": "Python",
724+
"rps": 12908,
725+
"avg_latency": "19.37ms",
726+
"p99_latency": "91.00ms",
727+
"cpu": "262.0%",
728+
"memory": "105MiB",
729+
"connections": 256,
730+
"threads": 64,
731+
"duration": "5s",
732+
"pipeline": 1,
733+
"bandwidth": "65.54MB/s",
734+
"input_bw": "743.72KB/s",
735+
"reconnects": 38682,
736+
"status_2xx": 193632,
737+
"status_3xx": 0,
738+
"status_4xx": 0,
739+
"status_5xx": 0,
740+
"tpl_baseline": 72050,
741+
"tpl_json": 73130,
742+
"tpl_db": 0,
743+
"tpl_upload": 0,
744+
"tpl_static": 0,
745+
"tpl_async_db": 48452
746+
},
721747
{
722748
"framework": "spring-boot",
723749
"language": "Java",

site/data/async-db-1024.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,26 @@
570570
"status_4xx": 0,
571571
"status_5xx": 0
572572
},
573+
{
574+
"framework": "SlimeWeb",
575+
"language": "Python",
576+
"rps": 4147,
577+
"avg_latency": "170.83ms",
578+
"p99_latency": "1.98s",
579+
"cpu": "192.4%",
580+
"memory": "307MiB",
581+
"connections": 1024,
582+
"threads": 64,
583+
"duration": "5s",
584+
"pipeline": 1,
585+
"bandwidth": "15.86MB/s",
586+
"input_bw": "283.49KB/s",
587+
"reconnects": 1233,
588+
"status_2xx": 41477,
589+
"status_3xx": 0,
590+
"status_4xx": 0,
591+
"status_5xx": 0
592+
},
573593
{
574594
"framework": "spring-boot",
575595
"language": "Java",

site/data/baseline-4096.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,25 @@
805805
"status_4xx": 0,
806806
"status_5xx": 0
807807
},
808+
{
809+
"framework": "SlimeWeb",
810+
"language": "Python",
811+
"rps": 71705,
812+
"avg_latency": "21.90ms",
813+
"p99_latency": "78.00ms",
814+
"cpu": "1322.5%",
815+
"memory": "150MiB",
816+
"connections": 4096,
817+
"threads": 64,
818+
"duration": "5s",
819+
"pipeline": 1,
820+
"bandwidth": "8.41MB/s",
821+
"reconnects": 0,
822+
"status_2xx": 358528,
823+
"status_3xx": 0,
824+
"status_4xx": 0,
825+
"status_5xx": 0
826+
},
808827
{
809828
"framework": "spring-boot",
810829
"language": "Java",

site/data/baseline-512.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,25 @@
805805
"status_4xx": 0,
806806
"status_5xx": 0
807807
},
808+
{
809+
"framework": "SlimeWeb",
810+
"language": "Python",
811+
"rps": 69917,
812+
"avg_latency": "6.54ms",
813+
"p99_latency": "17.70ms",
814+
"cpu": "1257.0%",
815+
"memory": "184MiB",
816+
"connections": 512,
817+
"threads": 64,
818+
"duration": "5s",
819+
"pipeline": 1,
820+
"bandwidth": "8.20MB/s",
821+
"reconnects": 0,
822+
"status_2xx": 349588,
823+
"status_3xx": 0,
824+
"status_4xx": 0,
825+
"status_5xx": 0
826+
},
808827
{
809828
"framework": "spring-boot",
810829
"language": "Java",

site/data/current.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"docker": "29.3.0",
1111
"docker_runtime": "runc",
1212
"governor": "performance",
13-
"commit": "e9453b3f",
13+
"commit": "f4baef2e",
1414
"tcp": {
1515
"lo_mtu": "1500",
1616
"congestion": "cubic",

site/data/frameworks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@
397397
"type": "tuned",
398398
"engine": "sisk"
399399
},
400+
"SlimeWeb": {
401+
"dir": "slimeweb",
402+
"description": "SlimeWeb is a fast lightweight framework for python powered by rust",
403+
"repo": "https://github.com/ATOMMAX-2001/Slime/",
404+
"type": "tuned",
405+
"engine": "hyper"
406+
},
400407
"spring-boot": {
401408
"dir": "spring-boot",
402409
"description": "Spring Boot with embedded Tomcat on JDK 25 with virtual threads.",

0 commit comments

Comments
 (0)