- Use sync.Pool for relay buffers instead of stack-allocated arrays. A [16379]byte on the goroutine stack forces Go to grow it to 32KB (next power of two). Pooled buffers keep goroutine stacks small. - Same fix for doppelganger write buffer ([16384]byte in conn.start). - Replace idle goroutines with context.AfterFunc in proxy.ServeConn and relay.Relay. These goroutines existed only to wait on ctx.Done() and close connections. AfterFunc achieves the same without allocating a goroutine until the context is actually cancelled. Net effect: at 3000 concurrent connections on a 1-vCPU/961MB VPS, the unmodified binary drops 246 connections and falls to 10 MB/s. With these changes: zero failures, 63 MB/s, 31% lower RSS. Closes #412tags/v2.2.5^2^2
|
||
| 9 | 9 |
|
| 10 | 10 |
|
| 11 | 11 |
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 12 | 19 |
|
| 13 | 20 |
|
| 14 | 21 |
|
|
||
| 46 | 53 |
|
| 47 | 54 |
|
| 48 | 55 |
|
| 49 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 50 | 59 |
|
| 51 | 60 |
|
| 52 | 61 |
|
|
||
| 68 | 77 |
|
| 69 | 78 |
|
| 70 | 79 |
|
| 71 |
|
|
| 80 |
|
|
| 72 | 81 |
|
| 73 | 82 |
|
| 74 | 83 |
|
|
||
| 4 | 4 |
|
| 5 | 5 |
|
| 6 | 6 |
|
| 7 |
|
|
| 7 | 8 |
|
| 8 | 9 |
|
| 9 | 10 |
|
| 10 | 11 |
|
| 11 | 12 |
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 12 | 20 |
|
| 13 | 21 |
|
| 14 | 22 |
|
|
||
| 16 | 24 |
|
| 17 | 25 |
|
| 18 | 26 |
|
| 19 |
|
|
| 20 |
|
|
| 27 |
|
|
| 21 | 28 |
|
| 22 | 29 |
|
| 23 |
|
|
| 30 |
|
|
| 31 |
|
|
| 24 | 32 |
|
| 25 | 33 |
|
| 26 | 34 |
|
|
||
| 36 | 44 |
|
| 37 | 45 |
|
| 38 | 46 |
|
| 39 |
|
|
| 47 |
|
|
| 48 |
|
|
| 40 | 49 |
|
| 41 | 50 |
|
| 42 | 51 |
|
| 43 | 52 |
|
| 44 |
|
|
| 53 |
|
|
| 45 | 54 |
|
| 46 | 55 |
|
| 47 | 56 |
|
|
||
| 65 | 65 |
|
| 66 | 66 |
|
| 67 | 67 |
|
| 68 |
|
|
| 69 |
|
|
| 68 |
|
|
| 70 | 69 |
|
| 71 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 | 72 |
|
| 73 | 73 |
|
| 74 | 74 |
|