[Benchmark] PyPy + Socketify Benchmark Shows 2x–9x Performance Gains vs Uvicorn Single Worker

I recently benchmarked two different Python web stack configurations and found some really large performance differences — in some cases nearly 9× faster.

To isolate runtime and server performance, I used a minimal ASGI framework I maintain called MicroPie. The focus here is on how Socketify + PyPy stacks up against Uvicorn + CPython under realistic workloads.

Configurations tested

CPython 3.12 + Uvicorn (single worker) – Run with: uvicorn a:app

PyPy 3.10 + Socketify (uSockets) – Run with: pypy3 -m socketify a:app

Two Endpoints – I tested a simple hello world response as well a more realistic example:

a. Hello World (« / ») « ` from micropie import App

class Root(App): async def index(self): return « hello world »

app = Root() « `

b. Compute (« /compute?name=Smith ») « `python from micropie import App import asyncio

class Root(App): async def compute(self): name = self.request.query_params.get(« name », « world ») await asyncio.sleep(0.001) # simulate async I/O (e.g., DB) count = sum(i * i for i in range(100)) # basic CPU load return {« message »: f »Hello, {name} », « result »: count}

app = Root() « `

This endpoint simulates a baseline and a realistic microservice which we can benchmark using wrk:

bash wrk -d15s -t4 -c64 ‘http://127.0.0.1:8000/compute?name=Smith’ wrk -d15s -t4 -c64 ‘http://127.0.0.1:8000/’

Results

Server + Runtime Requests/sec Avg Latency Transfer/sec b. Uvicorn + CPython 16,637 3.87 ms 3.06 MB/s b. Socketify + PyPy 35,852 2.62 ms 6.05 MB/s a. Uvicorn + CPython 18,642 3.51 ms 2.88 MB/s a. Socketify + PyPy 170,214 464.09 us 24.51 MB/s PyPy’s JIT helps a lot with repeated loop logic and JSON serialization. Socketify (built on uSockets) outperforms asyncio-based Uvicorn by a wide margin in terms of raw throughput and latency. For I/O-heavy or simple compute-bound microservices, PyPy + Socketify provides a very compelling performance profile.

I was curious if others here have tried running PyPy in production or played with Socketify, hence me sharing this here. Would love to hear your thoughts on other runtime/server combos (e.g., uvloop, Trio, etc.).

submitted by /u/Miserable_Ear3789 to r/Python
[link] [comments]


Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *