20 lines
616 B
Python
20 lines
616 B
Python
"""
|
||||
|
|
原生 FastAPI 对照服务(无 Zenoh / 无网关中间件 / 无 worker)
|
|||
|
|
|
|||
|
|
用于与 chongming 网关的 /api/v1/demo/hello 做性能对照:
|
|||
|
|
同样的 GET 返回一个 JSON(字段形状与 demo/hello 一致),排除业务与 RPC 链路,
|
|||
|
|
仅度量纯 FastAPI+Uvicorn 框架本身的吞吐与延迟。
|
|||
|
|
|
|||
|
|
启动:
|
|||
|
|
uv run uvicorn native_fastapi:app --host 0.0.0.0 --port 8001 --no-access-log
|
|||
|
|
"""
|
|||
|
|
import time
|
|||
|
|
|
|||
|
|
from fastapi import FastAPI
|
|||
|
|
|
|||
|
|
app = FastAPI()
|
|||
|
|
|
|||
|
|
|
|||
|
|
@app.get("/hello")
|
|||
|
|
async def hello(name: str = "bench"):
|
|||
|
|
return {"greeting": f"Hello, {name}!", "worker_id": "native", "timestamp": time.time()}
|