Commit ede4b05
committed
feat: bound the KCL native (off-heap) memory growth in-process
function-kcl recompiles the whole KCL module on every reconcile. The native
KCL runtime (loaded via dlopen/cgo) accumulates off-heap memory per compile
that Go's GC, GOGC and GOMEMLIMIT cannot bound, so long-lived pods climb to
their memory limit and get OOMKilled mid-render, dropping reconciles
(connection reset / DeadlineExceeded). A true compile cache
(BuildProgram/ExecArtifact) is not reachable through the native C-ABI this
function uses, so this bounds the growth at a process boundary instead, with
two complementary, opt-in mechanisms (both nil-safe and default-off):
* recycle.go — a watchdog samples process RSS (incl. native off-heap memory)
plus optional reconcile-count / lifetime limits; on threshold it stops
accepting new reconciles, drains in-flight ones, and exits 0 so the
orchestrator restarts the pod cleanly between renders instead of OOMKilling
it during one. Defaults to 85% of the detected cgroup limit.
* rendercache.go — memoises the KCL pipeline output keyed on the exact
serialized input. A composition function is deterministic over its input, so
byte-identical reconciles return the cached output without invoking the KCL
runtime, skipping the recompile and a leak increment. Opt-in via
FUNCTION_KCL_RENDER_CACHE_SIZE; bounded LRU with optional TTL.
grpc is promoted to a direct dependency for codes/status.
Signed-off-by: Callum MacDonald <callum@stakater.com>1 parent 69432e9 commit ede4b05
7 files changed
Lines changed: 923 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
49 | 61 | | |
50 | 62 | | |
51 | 63 | | |
| |||
189 | 201 | | |
190 | 202 | | |
191 | 203 | | |
192 | | - | |
193 | 204 | | |
194 | 205 | | |
195 | 206 | | |
| |||
200 | 211 | | |
201 | 212 | | |
202 | 213 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
210 | 233 | | |
211 | | - | |
212 | | - | |
| 234 | + | |
| 235 | + | |
213 | 236 | | |
214 | 237 | | |
215 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
247 | | - | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
40 | 51 | | |
41 | 52 | | |
42 | 53 | | |
| |||
0 commit comments