diff --git a/README.md b/README.md index 91846ec..97542c8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ * [FAQ](#faq) * [Reference](#reference) - + @@ -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). diff --git a/docs/benchmark.md b/docs/benchmark.md index 17783d8..d59e75b 100644 --- a/docs/benchmark.md +++ b/docs/benchmark.md @@ -16,7 +16,7 @@ * [C libevent version](#c-libevent-version) * [C libuv version](#c-libuv-version) - + @@ -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: @@ -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: @@ -341,6 +411,7 @@ async def main(): async with server: await server.serve_forever() +uvloop.install() asyncio.run(main()) ```