i have a question.when i test the process code , the service "/v1/test/" is very low. which can not suport high Concurrent access.
#!/usr/bin/env python
-- coding: utf-8 --
import asyncio import uvicorn from fastapi import FastAPI import databases from databases import Database from asyncio import gather from pydantic import BaseModel from databases.core import Connection
app = FastAPI()
mysql_url = 'mysql://username:password@ip:port/db' database = Database(mysql_url)
@app.on_event('startup') async def init_scheduler(): await database.connect()
@app.on_event("shutdown") async def down(): await database.disconnect()
class TestResult(BaseModel): code: str value_1: str value_2: str
class TestItem(BaseModel): code: str
@app.post("/v1/test/", response_model=TestResult)
async def test(item: TestItem):
code = item.code
# v1, v2 = 0, 0
sql = f"select Close,ChangePercActual from search_realtime where SecuCode = {code}"
res = await gather(database.fetch_one(query=sql))
# print(res)
v1, v2 = float(res[0][0]), float(res[0][1])
res = {"code": str(code), "value_1": str(v1), "value_2": str(v2)}
return res
if name == "main": uvicorn.run("server:app", host="127.0.0.1", port=8083, workers=2)