why is time rising for more than one request to asyncio server in python?

前端 未结 1 1022
半阙折子戏
半阙折子戏 2020-12-11 20:59

I wrote a pythonic server with socket. that should receives requests at the same time(parallel) and respond them parallel. When i send more than one request to it, the time

1条回答
  •  醉梦人生
    2020-12-11 21:46

    What is request

    Single request (roughly saying) consists of the following steps:

    1. write data to network
    2. waste time waiting for answer
    3. read answer from network

    №1/№3 processed by your CPU very fast. Step №2 - is a bytes journey from your PC to some server (in another city, for example) and back by wires: it usually takes much more time.

    How asynchronous requests work

    Asynchronous requests are not really "parallel" in terms of processing: it's still your single CPU core that can process one thing at a time. But running multiple async requests allows you to use step №2 of some request to do steps №1/№3 of other request instead of just wasting huge amount of time. That's a reason why multiple async requests usually would finish earlier then same amount of sync ones.

    Running async code without network delay

    But when you run things locally, step №2 doesn't take much time: your PC and server are the same thing and bytes don't go to network journey. There is just no time that can be used in step №2 to start new request. Only your single CPU core works processing one thing at a time.

    You should test requests against server that answers with some delay to see results you expect.

    0 讨论(0)
提交回复
热议问题