question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] about qps

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
lithbitrencommented, Mar 16, 2020

www.v2ex.com/t/653100

fixed it.

from asyncio import ProactorEventLoop, set_event_loop, ProactorEventLoop, get_event_loop
from uvicorn import Config, Server
if __name__ == "__main__":
    set_event_loop(ProactorEventLoop())
    server = Server(config=Config(app=app))
    get_event_loop().run_until_complete(server.serve())
0reactions
github-actions[bot]commented, Apr 24, 2020

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

QPS Interview Questions (2022) - Glassdoor
QPS interview details: 23 interview questions and 23 interview reviews posted anonymously by QPS interview candidates.
Read more >
10 questions about Interviews at QPS Employment Group
35 questions and answers about QPS Employment Group Interviews. What questions did they ask during your interview at QPS Employment Group?
Read more >
Questions to Ask Before Participating in Clinical Research - QPS
Learn these questions to ask before participating in clinical research, and you'll be prepared to get the most out of your participation.
Read more >
Working At QPS - Ask a Question | Comparably
Post questions about QPS' Company Culture, answered by Employees at QPS. See the 3 total questions asked so far.
Read more >
QPS - Cint
Before starting the survey, please answer a few quick profiling questions. You'll be done and on your way to the survey in less...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found