Skip to content

Commit 3e65cf6

Browse files
committed
TCP server document update
1 parent 86ffbe7 commit 3e65cf6

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

β€ŽREADME.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
A tiny python asyncio just for learning πŸ™‹β€β™‚οΈ, document below is my personal notes during the learning, may change
44
frequently.
55

6+
## TCP Echo Servers
7+
8+
I implement a series of TCP echo server for the test of tiny-asyncio client including multi threading, IO multiplexing
9+
and so on. Details can be found [here](https://github.com/HFrost0/tiny-asyncio/tree/master/echo).
10+
611
## Event Loop
712

813
Event loop is just a `while True` loop, the basic functionality of event loop is to keep find out which functions can

β€Žecho/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,41 @@ response.
2626

2727
### 6. threadpool
2828

29-
Main thread for listening new connection, and a threadpool will be used to execute the response callbacks.
29+
Main thread for listening new connection, and a threadpool will be used to execute the response callbacks.
30+
31+
## Performances
32+
33+
Setup: all the results are obtained on macOS 12.4 M1 8 core chip laptop. selector_process server will have 4 worker
34+
processes, and threadpool server will have a default `ThreadPoolExecutor` without worker number arg.
35+
36+
### 1k
37+
38+
1000 client connect and then each one send 100 times.
39+
40+
| | select | selectors | selectors_process | thread | threadpool |
41+
|---------|--------|-----------|-------------------|---------|------------|
42+
| connect | 0.2328 | 0.0427 | 0.0487 | 0.2784 | 0.0424 |
43+
| echo | 1.2135 | 1.2332 | 1.3918 | 24.4581 | 1.5212 |
44+
45+
### 10k
46+
47+
10,000 client connect and then each one send 100 times
48+
49+
| | select | selectors | selectors_process | thread | threadpool |
50+
|---------|--------|-----------|-------------------|--------|------------|
51+
| connect | ❌ | 0.4142 | 0.4698 | ❌ | 0.4155 |
52+
| echo | ❌ | 16.2907 | 19.7788 | ❌ | 16.1532 |
53+
54+
* select server failed because of the limit of maximum 1024 fd number of `select`.
55+
* thread server failed because of too many thread created.
56+
57+
### 10k + cpu
58+
59+
10,000 client connect and then each one send 1 times, but server side is slow down by the cpu bound
60+
task `sum(range(100000))`.
61+
62+
| | select | selectors | selectors_process | thread | threadpool |
63+
|---------|--------|-----------|-------------------|--------|------------|
64+
| connect | ❌ | 0.7029 | 0.5843 | ❌ | 0.5510 |
65+
| echo | ❌ | 9.2716 | 2.9143 | ❌ | 9.9059 |
66+

0 commit comments

Comments
Β (0)