Skip to content

Commit d0a653b

Browse files
authored
Merge pull request #606 from ATOMMAX-2001/slimeweb-python
SlimeWeb Python -few improvement changes
2 parents abb3cfd + a65d7e0 commit d0a653b

34 files changed

Lines changed: 217 additions & 215 deletions

frameworks/slimeweb/main.py

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,18 @@ def load_json_processing_file():
2424

2525
@app.route("/baseline11", method=["GET", "POST"])
2626
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
27+
result = 0
28+
for q_val in req.query.values():
29+
try:
30+
result += int(q_val)
31+
except ValueError:
32+
pass
33+
if req.method == "POST":
4234
try:
4335
result += int(req.text)
4436
except ValueError:
4537
pass
46-
return resp.plain(str(result))
38+
return resp.plain(str(result))
4739

4840

4941
@app.route("/pipeline", method="GET")
@@ -66,29 +58,28 @@ def json_test(req, resp):
6658
global JSON_DATASET
6759
count = int(req.params["count"])
6860
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-
)
61+
result = [
62+
{
63+
"id": data["id"],
64+
"name": data["name"],
65+
"category": data["category"],
66+
"price": data["price"],
67+
"quantity": data["quantity"],
68+
"active": data["active"],
69+
"tags": data["tags"],
70+
"rating": {
71+
"score": data["rating"]["score"],
72+
"count": data["rating"]["count"],
73+
},
74+
"total": data["price"] * data["quantity"] * multiplier,
75+
}
76+
for data in JSON_DATASET[:count]
77+
]
78+
8779
return resp.json({"items": result, "count": count})
8880

8981

9082
# Websocket in slime are event driven
91-
# echo back based on the message type
9283
@app.websocket("/ws")
9384
def websocket_test(req, resp):
9485
def echo_me(msg):
@@ -110,27 +101,33 @@ async def async_db_test(req, resp):
110101
limit = int(req.query["limit"])
111102
result = []
112103
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-
)
104+
data_result = await DB_POOL.fetch(QUERY_STMT, min, max, limit)
105+
result = [
106+
{
107+
"id": data["id"],
108+
"name": data["name"],
109+
"category": data["category"],
110+
"price": data["price"],
111+
"quantity": data["quantity"],
112+
"active": data["active"],
113+
"tags": json.loads(data["tags"]),
114+
"rating": {
115+
"score": data["rating_score"],
116+
"count": data["rating_count"],
117+
},
118+
}
119+
for data in data_result
120+
]
131121
return resp.json({"items": result, "count": len(result)})
132122

133123

124+
class NoResetConnection(pg.Connection):
125+
__slots__ = ()
126+
127+
def get_reset_query(self):
128+
return ""
129+
130+
134131
@app.start()
135132
async def init():
136133
global DB_POOL
@@ -139,6 +136,7 @@ async def init():
139136
dsn=os.environ["DATABASE_URL"],
140137
min_size=5,
141138
max_size=int(os.environ.get("DATABASE_MAX_CONN", 256)),
139+
connection_class=NoResetConnection,
142140
)
143141
print("Pool is created successfully")
144142
except Exception as e:

site/data/api-16-1024.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -851,28 +851,28 @@
851851
{
852852
"framework": "SlimeWeb",
853853
"language": "Python",
854-
"rps": 12236,
855-
"avg_latency": "72.57ms",
856-
"p99_latency": "1.38s",
857-
"cpu": "403.8%",
858-
"memory": "154MiB",
854+
"rps": 13047,
855+
"avg_latency": "73.19ms",
856+
"p99_latency": "834.30ms",
857+
"cpu": "371.9%",
858+
"memory": "150MiB",
859859
"connections": 1024,
860860
"threads": 64,
861861
"duration": "5s",
862862
"pipeline": 1,
863-
"bandwidth": "62.97MB/s",
864-
"input_bw": "705.00KB/s",
865-
"reconnects": 36510,
866-
"status_2xx": 183546,
863+
"bandwidth": "67.40MB/s",
864+
"input_bw": "751.73KB/s",
865+
"reconnects": 38816,
866+
"status_2xx": 195716,
867867
"status_3xx": 0,
868868
"status_4xx": 0,
869869
"status_5xx": 0,
870-
"tpl_baseline": 66774,
871-
"tpl_json": 72402,
870+
"tpl_baseline": 70685,
871+
"tpl_json": 76162,
872872
"tpl_db": 0,
873873
"tpl_upload": 0,
874874
"tpl_static": 0,
875-
"tpl_async_db": 44369
875+
"tpl_async_db": 48869
876876
},
877877
{
878878
"framework": "spring-boot",

site/data/api-4-256.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -851,28 +851,28 @@
851851
{
852852
"framework": "SlimeWeb",
853853
"language": "Python",
854-
"rps": 12908,
855-
"avg_latency": "19.37ms",
856-
"p99_latency": "91.00ms",
857-
"cpu": "262.0%",
858-
"memory": "105MiB",
854+
"rps": 14636,
855+
"avg_latency": "16.50ms",
856+
"p99_latency": "75.40ms",
857+
"cpu": "282.5%",
858+
"memory": "102MiB",
859859
"connections": 256,
860860
"threads": 64,
861861
"duration": "5s",
862862
"pipeline": 1,
863-
"bandwidth": "65.54MB/s",
864-
"input_bw": "743.72KB/s",
865-
"reconnects": 38682,
866-
"status_2xx": 193632,
863+
"bandwidth": "74.31MB/s",
864+
"input_bw": "843.29KB/s",
865+
"reconnects": 43842,
866+
"status_2xx": 219549,
867867
"status_3xx": 0,
868868
"status_4xx": 0,
869869
"status_5xx": 0,
870-
"tpl_baseline": 72050,
871-
"tpl_json": 73130,
870+
"tpl_baseline": 81695,
871+
"tpl_json": 82697,
872872
"tpl_db": 0,
873873
"tpl_upload": 0,
874874
"tpl_static": 0,
875-
"tpl_async_db": 48452
875+
"tpl_async_db": 55157
876876
},
877877
{
878878
"framework": "spring-boot",

site/data/async-db-1024.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -673,19 +673,19 @@
673673
{
674674
"framework": "SlimeWeb",
675675
"language": "Python",
676-
"rps": 4147,
677-
"avg_latency": "170.83ms",
678-
"p99_latency": "1.98s",
679-
"cpu": "192.4%",
680-
"memory": "307MiB",
676+
"rps": 4868,
677+
"avg_latency": "199.81ms",
678+
"p99_latency": "493.20ms",
679+
"cpu": "205.0%",
680+
"memory": "312MiB",
681681
"connections": 1024,
682682
"threads": 64,
683683
"duration": "5s",
684684
"pipeline": 1,
685-
"bandwidth": "15.86MB/s",
686-
"input_bw": "283.49KB/s",
687-
"reconnects": 1233,
688-
"status_2xx": 41477,
685+
"bandwidth": "18.68MB/s",
686+
"input_bw": "332.77KB/s",
687+
"reconnects": 1519,
688+
"status_2xx": 48686,
689689
"status_3xx": 0,
690690
"status_4xx": 0,
691691
"status_5xx": 0

site/data/baseline-4096.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,19 @@
948948
{
949949
"framework": "SlimeWeb",
950950
"language": "Python",
951-
"rps": 71705,
952-
"avg_latency": "21.90ms",
953-
"p99_latency": "78.00ms",
954-
"cpu": "1322.5%",
955-
"memory": "150MiB",
951+
"rps": 82494,
952+
"avg_latency": "17.52ms",
953+
"p99_latency": "67.50ms",
954+
"cpu": "1370.1%",
955+
"memory": "125MiB",
956956
"connections": 4096,
957957
"threads": 64,
958958
"duration": "5s",
959959
"pipeline": 1,
960-
"bandwidth": "8.41MB/s",
960+
"bandwidth": "9.75MB/s",
961+
"input_bw": "6.37MB/s",
961962
"reconnects": 0,
962-
"status_2xx": 358528,
963+
"status_2xx": 412474,
963964
"status_3xx": 0,
964965
"status_4xx": 0,
965966
"status_5xx": 0

site/data/baseline-512.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,19 @@
948948
{
949949
"framework": "SlimeWeb",
950950
"language": "Python",
951-
"rps": 69917,
952-
"avg_latency": "6.54ms",
953-
"p99_latency": "17.70ms",
954-
"cpu": "1257.0%",
955-
"memory": "184MiB",
951+
"rps": 85240,
952+
"avg_latency": "5.69ms",
953+
"p99_latency": "16.00ms",
954+
"cpu": "1539.1%",
955+
"memory": "168MiB",
956956
"connections": 512,
957957
"threads": 64,
958958
"duration": "5s",
959959
"pipeline": 1,
960-
"bandwidth": "8.20MB/s",
960+
"bandwidth": "10.08MB/s",
961+
"input_bw": "6.58MB/s",
961962
"reconnects": 0,
962-
"status_2xx": 349588,
963+
"status_2xx": 426200,
963964
"status_3xx": 0,
964965
"status_4xx": 0,
965966
"status_5xx": 0

site/data/baseline-h2c-1024.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@
7878
{
7979
"framework": "wtx",
8080
"language": "Rust",
81-
"rps": 651217,
82-
"avg_latency": "117.30ms",
83-
"p99_latency": "117.30ms",
84-
"cpu": "4364.3%",
85-
"memory": "1.4GiB",
81+
"rps": 663592,
82+
"avg_latency": "127.66ms",
83+
"p99_latency": "127.66ms",
84+
"cpu": "5459.2%",
85+
"memory": "1.3GiB",
8686
"connections": 1024,
8787
"threads": 64,
8888
"duration": "5s",
8989
"pipeline": 1,
90-
"bandwidth": "22.68MB/s",
90+
"bandwidth": "23.07MB/s",
9191
"reconnects": 0,
92-
"status_2xx": 3301674,
92+
"status_2xx": 3357780,
9393
"status_3xx": 0,
9494
"status_4xx": 0,
9595
"status_5xx": 0

site/data/current.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"date": "2026-04-24",
2+
"date": "2026-04-23",
33
"cpu": "AMD Ryzen Threadripper PRO 3995WX 64-Cores",
44
"cores": "64",
55
"threads": "128",
@@ -10,7 +10,7 @@
1010
"docker": "29.3.0",
1111
"docker_runtime": "runc",
1212
"governor": "performance",
13-
"commit": "8d1543bd",
13+
"commit": "275593ae",
1414
"tcp": {
1515
"lo_mtu": "1500",
1616
"congestion": "cubic",

site/data/json-4096.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,19 @@
733733
{
734734
"framework": "SlimeWeb",
735735
"language": "Python",
736-
"rps": 50429,
737-
"avg_latency": "41.15ms",
738-
"p99_latency": "197.80ms",
739-
"cpu": "1985.7%",
740-
"memory": "215MiB",
736+
"rps": 79804,
737+
"avg_latency": "31.69ms",
738+
"p99_latency": "97.50ms",
739+
"cpu": "3496.7%",
740+
"memory": "172MiB",
741741
"connections": 4096,
742742
"threads": 64,
743743
"duration": "5s",
744744
"pipeline": 1,
745-
"bandwidth": "176.21MB/s",
746-
"input_bw": "2.40MB/s",
747-
"reconnects": 8622,
748-
"status_2xx": 252148,
745+
"bandwidth": "279.05MB/s",
746+
"input_bw": "3.81MB/s",
747+
"reconnects": 14611,
748+
"status_2xx": 399021,
749749
"status_3xx": 0,
750750
"status_4xx": 0,
751751
"status_5xx": 0

0 commit comments

Comments
 (0)