Skip to content

Commit

Permalink
add benchmark for uvloop
Browse files Browse the repository at this point in the history
  • Loading branch information
netcan committed Dec 7, 2021
1 parent e3b123d commit 092887d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 9 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* [FAQ](#faq)
* [Reference](#reference)

<!-- Added by: netcan, at: Sat Dec 4 11:01:53 AM HKT 2021 -->
<!-- Added by: netcan, at: Tue Dec 7 07:54:16 PM HKT 2021 -->

<!--te-->

Expand Down Expand Up @@ -155,13 +155,14 @@ Using the Apache Benchmarking tool, 10000000 requests that each size is 106 byte

| framework | RPS [#/sec] (mean) | Language | Pattern |
|----------------|--------------------:| --------: |----------:|
| [python asyncio](docs/benchmark.md#python399-asyncio) | 47393.59 | Python | coroutine |
| [this project](docs/benchmark.md#this-project) | **164457.63** | C++20 | coroutine |
| [asio](docs/benchmark.md#asio1180-in-coroutine-mode) | 159322.66 | C++20 | coroutine |
| [tokio-rs](docs/benchmark.md#tokio-rs-1140) | 156852.70 | Rust1.59.0-nightly | coroutine |
| [epoll](docs/benchmark.md#c-epoll-version) | 153147.79 | C| eventloop |
| [libevent](docs/benchmark.md#c-libevent-21so7) | 136996.46 | C| callback |
| [libuv](docs/benchmark.md#c-libuv1420) | 159937.73 | C| callback |
| [python asyncio](docs/benchmark.md#python399-asyncio) | 47393.59 | Python | coroutine |
| [python asyncio with uvloop](docs/benchmark.md#python399-asyncio) | 100426.97 | Python | coroutine |
| [this project](docs/benchmark.md#this-project) | **164457.63** | C++20 | coroutine |
| [asio](docs/benchmark.md#asio1180-in-coroutine-mode) | 159322.66 | C++20 | coroutine |
| [tokio-rs](docs/benchmark.md#tokio-rs-1140) | 156852.70 | Rust1.59.0-nightly | coroutine |
| [epoll](docs/benchmark.md#c-epoll-version) | 153147.79 | C | eventloop |
| [libevent](docs/benchmark.md#c-libevent-21so7) | 136996.46 | C | callback |
| [libuv](docs/benchmark.md#c-libuv1420) | 159937.73 | C | callback |

The result may be incredible, but it is possible, the magnitude of IO is milliseconds(1e-3 s), while the magnitude of the coroutine is nanoseconds(1e-9 s).

Expand Down
73 changes: 72 additions & 1 deletion docs/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* [C libevent version](#c-libevent-version)
* [C libuv version](#c-libuv-version)

<!-- Added by: netcan, at: Sat Dec 4 10:18:29 AM HKT 2021 -->
<!-- Added by: netcan, at: Tue Dec 7 07:54:39 PM HKT 2021 -->

<!--te-->

Expand Down Expand Up @@ -70,6 +70,47 @@ Percentage of the requests served within a certain time (ms)
100% 2816 (longest request)
```
with uvloop:
```shell
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8888

Document Path: /
Document Length: 0 bytes

Concurrency Level: 1000
Time taken for tests: 99.575 seconds
Complete requests: 10000000
Failed requests: 0
Non-2xx responses: 10000000
Keep-Alive requests: 10000000
Total transferred: 1060000000 bytes
HTML transferred: 0 bytes
Requests per second: 100426.97 [#/sec] (mean)
Time per request: 9.957 [ms] (mean)
Time per request: 0.010 [ms] (mean, across all concurrent requests)
Transfer rate: 10395.76 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 8.3 0 1033
Processing: 2 10 7.0 7 1711
Waiting: 0 10 7.0 7 1711
Total: 2 10 13.6 7 2741

Percentage of the requests served within a certain time (ms)
50% 7
66% 13
75% 13
80% 13
90% 14
95% 14
98% 14
99% 14
100% 2741 (longest request)
```
## This project
```shell
Server Software:
Expand Down Expand Up @@ -318,8 +359,37 @@ Percentage of the requests served within a certain time (ms)
# Test Code
## Python version
asyncio:
```python
import asyncio

async def handle_echo(reader, writer):
while True:
data = await reader.read(200)
if len(data) == 0: break

writer.write(data)
await writer.drain()

writer.close()

async def main():
server = await asyncio.start_server(
handle_echo, '127.0.0.1', 8888)

addrs = ', '.join(str(sock.getsockname()) for sock in server.sockets)
print(f'Serving on {addrs}')

async with server:
await server.serve_forever()

asyncio.run(main())
```
asyncio with uvloop:
```python
import asyncio
import uvloop

async def handle_echo(reader, writer):
while True:
Expand All @@ -341,6 +411,7 @@ async def main():
async with server:
await server.serve_forever()

uvloop.install()
asyncio.run(main())
```
Expand Down

0 comments on commit 092887d

Please sign in to comment.