[QUESTION] about qps
See original GitHub issueDescription
The simple get ‘hello world’ server crashed when I send more than 510 requests in a second to the fastAPI.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return "Hello World"
How to improve qps for it?
I‘ve checked and can’t find an effective way in questionhttps://github.com/tiangolo/fastapi/issues/603 or any other issues.
My environments: win10 1903 Python 3.7.5 64bit fastapi 0.52.0 uvicorn 0.11.3
used module grequests to send the requests.
import grequests, time, collections
def qps_test(url, N):
start_time = time.time()
res_list = grequests.map([
grequests.get(url)
for _ in range(N)
])
print(f'time: {time.time() - start_time}\nstatue_code:')
print('\n'.join(
f'{k}: {v}'
for k, v in collections.Counter(
res is None and 'LOST' or res.status_code
for res in res_list
).items()
))
if __name__ == '__main__':
qps_test('http://127.0.0.1:8000/', 500)
# qps_test('http://127.0.0.1:8000/', 511) #crashed
uvicorn main:app --reload
run in cmd (follow the docs).
and i also tried uvicorn main:app
, the same.
error message:
Process SpawnProcess-1: Traceback (most recent call last): File "d:\python37\lib\multiprocessing\process.py", line 297, in _bootstrap self.run() File "d:\python37\lib\multiprocessing\process.py", line 99, in run self._target(*self._args, **self._kwargs) File "d:\python37\lib\site-packages\uvicorn\subprocess.py", line 61, in subprocess_started target(sockets=sockets) File "d:\python37\lib\site-packages\uvicorn\main.py", line 382, in run loop.run_until_complete(self.serve(sockets=sockets)) File "d:\python37\lib\asyncio\base_events.py", line 566, in run_until_complete self.run_forever() File "d:\python37\lib\asyncio\base_events.py", line 534, in run_forever self._run_once() File "d:\python37\lib\asyncio\base_events.py", line 1735, in _run_once event_list = self._selector.select(timeout) File "d:\python37\lib\selectors.py", line 323, in select r, w, _ = self._select(self._readers, self._writers, [], timeout) File "d:\python37\lib\selectors.py", line 314, in _select r, w, x = select.select(r, w, w, timeout) ValueError: too many file descriptors in select()
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (9 by maintainers)
Top GitHub Comments
www.v2ex.com/t/653100
fixed it.
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.