Skip to content

Commit 921f2b5

Browse files
Optimizations & Update Benchmark Results (#832)
* Bail out of lock earlier * Avoid calling `get_events` for unfinished work tasks. Use `cached_property` for `HttpParser` optimization * Add `type: ignore[no-any-return]`, odd scenario * We dont have to rebuild response packet repeatedly within `WebServerPlugin` * Parse line and header in one invocation * Minor optimizations and update benchmark to use `oha` instead of `hey` * Remove `flask` from benchmark, only benchmark `asgi` or `async` based libraries. Use `uvicorn` and 10 workers for `blacksheep`. Use `oha` instead of `hey` * Add benchmark for `starlette` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add missing dep * pre-commit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9782f6c commit 921f2b5

28 files changed

+326
-524
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ lib-profile:
138138
-o profile.svg \
139139
-t -F -s -- \
140140
python -m proxy \
141+
--hostname 127.0.0.1 \
141142
--num-acceptors 1 \
142143
--num-workers 1 \
143144
--disable-http-proxy \

README.md

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -128,63 +128,51 @@
128128
```console
129129
# On Macbook Pro 2019 / 2.4 GHz 8-Core Intel Core i9 / 32 GB RAM
130130
❯ ./helper/benchmark.sh
131-
CONCURRENCY: 100 workers, TOTAL REQUESTS: 100000 req, QPS: 8000 req/sec, TIMEOUT: 1 sec
131+
CONCURRENCY: 100 workers, TOTAL REQUESTS: 100000 req
132132

133133
Summary:
134-
Total: 3.1217 secs
135-
Slowest: 0.0499 secs
136-
Fastest: 0.0004 secs
137-
Average: 0.0030 secs
138-
Requests/sec: 32033.7261
134+
Success rate: 1.0000
135+
Total: 2.5489 secs
136+
Slowest: 0.0443 secs
137+
Fastest: 0.0006 secs
138+
Average: 0.0025 secs
139+
Requests/sec: 39232.6572
139140

140-
Total data: 1900000 bytes
141-
Size/request: 19 bytes
141+
Total data: 1.81 MiB
142+
Size/request: 19 B
143+
Size/sec: 727.95 KiB
142144

143145
Response time histogram:
144-
0.000 [1] |
145-
0.005 [92268] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
146-
0.010 [7264] |■■■
147-
0.015 [318] |
148-
0.020 [102] |
149-
0.025 [32] |
150-
0.030 [6] |
151-
0.035 [4] |
152-
0.040 [1] |
153-
0.045 [2] |
154-
0.050 [2] |
155-
146+
0.001 [5006] |■■■■■
147+
0.001 [19740] |■■■■■■■■■■■■■■■■■■■■■
148+
0.002 [29701] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
149+
0.002 [21278] |■■■■■■■■■■■■■■■■■■■■■■
150+
0.003 [15376] |■■■■■■■■■■■■■■■■
151+
0.004 [6644] |■■■■■■■
152+
0.004 [1609] |■
153+
0.005 [434] |
154+
0.006 [83] |
155+
0.006 [29] |
156+
0.007 [100] |
156157

157158
Latency distribution:
158-
10% in 0.0017 secs
159-
25% in 0.0020 secs
160-
50% in 0.0025 secs
161-
75% in 0.0036 secs
162-
90% in 0.0050 secs
163-
95% in 0.0060 secs
164-
99% in 0.0087 secs
159+
10% in 0.0014 secs
160+
25% in 0.0018 secs
161+
50% in 0.0023 secs
162+
75% in 0.0030 secs
163+
90% in 0.0036 secs
164+
95% in 0.0040 secs
165+
99% in 0.0047 secs
165166

166167
Details (average, fastest, slowest):
167-
DNS+dialup: 0.0000 secs, 0.0004 secs, 0.0499 secs
168-
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs
169-
req write: 0.0000 secs, 0.0000 secs, 0.0020 secs
170-
resp wait: 0.0030 secs, 0.0004 secs, 0.0462 secs
171-
resp read: 0.0000 secs, 0.0000 secs, 0.0027 secs
168+
DNS+dialup: 0.0025 secs, 0.0015 secs, 0.0030 secs
169+
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0001 secs
172170

173171
Status code distribution:
174-
[200] 100000 responses
172+
[200] 100000 responses
175173
```
176174

177-
- `1 Million` requests benchmark comparison @ `8000 QPS`
178-
179-
| Server | Throughput (request/sec) |
180-
| ------ | ------------ |
181-
| `proxy.py` | 30,351 |
182-
| `blacksheep` | 7,358 |
183-
| `aiohttp` | 6,615 |
184-
| `tornado` | 3,301 |
185-
| `Flask` | 830 |
186-
187-
See [Benchmark](https://github.com/abhinavsingh/proxy.py/tree/develop/benchmark#readme) for more details and how to run them locally.
175+
- See [Benchmark](https://github.com/abhinavsingh/proxy.py/tree/develop/benchmark#readme) for more details and how to run them locally.
188176

189177
- Lightweight
190178
- Uses `~5-20 MB` RAM

0 commit comments

Comments
 (0)