Commit b082b62
committed
app: Bound memory under sustained session churn
Add three mechanisms that cap memory growth on app-access agents
handling high session volumes with stalled upload streams.
Reverse proxy buffer pool: add a `sync.Pool`-backed
`httputil.BufferPool` to the reverse proxy `Forwarder`. Without a
pool, every proxied request allocates a fresh 32 KiB buffer for
`io.Copy` that becomes garbage immediately after the request
completes. Under high concurrency this creates GC pressure.
Session writer buffer cap: add a `MaxBufferSize` config field
(default 4096) to `SessionWriter`. When the internal
`[]PreparedSessionEvent` buffer reaches capacity, `processEvents`
stops reading from `eventsCh`, creating backpressure through the
unbuffered channel back to `RecordEvent` callers. Extract a
`handleStreamDone()` helper to deduplicate stream recovery logic
between the backpressure and main select blocks. Fix a pre-existing
off-by-one in `updateStatus` where `lastIndex > 0` prevented
trimming when only one event (index 0) was confirmed.
Session chunk semaphore: add a `chunkSem` buffered channel to
`ConnectionsHandler` that limits the number of concurrently active
session chunks per agent to `MaxActiveSessionChunks` (default 256).
A slot is acquired in `newSessionChunk` before opening the recording
stream and released in `close()` after the stream shuts down. Use a
`success` flag to release the slot on error paths. Log a warning
when a chunk is rejected so the rejection is observable without
correlating with generic request failure logs. Set
`ReloadOnErr: true` on the `FnCache` so that `LimitExceeded` errors
from a full semaphore are not cached for the full TTL.1 parent a1c54f4 commit b082b62
File tree
4 files changed
+163
-13
lines changed- lib
- events
- httplib/reverseproxy
- srv/app
4 files changed
+163
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
| |||
128 | 142 | | |
129 | 143 | | |
130 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
131 | 148 | | |
132 | 149 | | |
133 | 150 | | |
| |||
174 | 191 | | |
175 | 192 | | |
176 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
177 | 198 | | |
178 | 199 | | |
179 | 200 | | |
| |||
428 | 449 | | |
429 | 450 | | |
430 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
431 | 475 | | |
432 | 476 | | |
433 | 477 | | |
| |||
454 | 498 | | |
455 | 499 | | |
456 | 500 | | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
| 501 | + | |
465 | 502 | | |
466 | 503 | | |
467 | 504 | | |
| |||
471 | 508 | | |
472 | 509 | | |
473 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
474 | 526 | | |
475 | 527 | | |
476 | 528 | | |
| |||
612 | 664 | | |
613 | 665 | | |
614 | 666 | | |
615 | | - | |
| 667 | + | |
616 | 668 | | |
617 | 669 | | |
618 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
619 | 676 | | |
620 | 677 | | |
621 | 678 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
36 | 58 | | |
37 | 59 | | |
38 | 60 | | |
| |||
77 | 99 | | |
78 | 100 | | |
79 | 101 | | |
| 102 | + | |
80 | 103 | | |
81 | 104 | | |
82 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
134 | 143 | | |
135 | 144 | | |
136 | 145 | | |
| |||
211 | 220 | | |
212 | 221 | | |
213 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
214 | 226 | | |
215 | 227 | | |
216 | 228 | | |
| |||
244 | 256 | | |
245 | 257 | | |
246 | 258 | | |
| 259 | + | |
| 260 | + | |
247 | 261 | | |
248 | 262 | | |
249 | 263 | | |
| |||
252 | 266 | | |
253 | 267 | | |
254 | 268 | | |
| 269 | + | |
255 | 270 | | |
256 | 271 | | |
257 | 272 | | |
| |||
265 | 280 | | |
266 | 281 | | |
267 | 282 | | |
| 283 | + | |
268 | 284 | | |
269 | 285 | | |
270 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
48 | 62 | | |
49 | 63 | | |
50 | 64 | | |
| |||
81 | 95 | | |
82 | 96 | | |
83 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
84 | 106 | | |
85 | 107 | | |
86 | 108 | | |
| |||
92 | 114 | | |
93 | 115 | | |
94 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
95 | 141 | | |
96 | 142 | | |
97 | 143 | | |
98 | 144 | | |
99 | 145 | | |
| 146 | + | |
100 | 147 | | |
101 | 148 | | |
102 | 149 | | |
| |||
137 | 184 | | |
138 | 185 | | |
139 | 186 | | |
| 187 | + | |
140 | 188 | | |
141 | 189 | | |
142 | 190 | | |
| |||
197 | 245 | | |
198 | 246 | | |
199 | 247 | | |
200 | | - | |
201 | | - | |
202 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
203 | 251 | | |
204 | 252 | | |
205 | 253 | | |
| |||
251 | 299 | | |
252 | 300 | | |
253 | 301 | | |
254 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
255 | 309 | | |
256 | 310 | | |
257 | 311 | | |
| |||
0 commit comments