MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / warmThreads

Function warmThreads

internal/materialize/worker.go:82–101  ·  view source on GitHub ↗

warmThreads brings the worker's thread set to steady state BEFORE it reads the readiness probe, i.e. before the supervisor measures the baseline the memory cap is relative to (supervisor.go armCap). Every P runs an allocating goroutine at once, so the runtime starts an M for each, and a GC starts it

()

Source from the content-addressed store, hash-verified

80// otherwise come out of that job's budget: on a cgo build each reserves an
81// 8 MiB stack, and CI measured the growth this closes.
82func warmThreads() {
83 n := runtime.GOMAXPROCS(0)
84 var wg sync.WaitGroup
85 start := make(chan struct{})
86 for range n {
87 wg.Add(1)
88 go func() {
89 defer wg.Done()
90 <-start
91 var keep [][]byte
92 for range 32 {
93 keep = append(keep, make([]byte, 64<<10))
94 }
95 runtime.KeepAlive(keep)
96 }()
97 }
98 close(start)
99 wg.Wait()
100 runtime.GC()
101}
102
103// serveWorker is RunWorker's loop over an already-loaded Runner. Split out so
104// the tests of the loop share one loaded bundle instead of paying the load

Callers 2

runHelperFunction · 0.85
RunWorkerFunction · 0.85

Calls 5

appendFunction · 0.85
DoneMethod · 0.80
AddMethod · 0.65
makeFunction · 0.50
closeFunction · 0.50

Tested by 1

runHelperFunction · 0.68