MCPcopy Index your code
hub / github.com/php/frankenphp / scaleRegularThread

Function scaleRegularThread

scaling.go:117–144  ·  view source on GitHub ↗

scaleRegularThread adds a regular PHP thread automatically

(done chan struct{}, mstate *state.ThreadState)

Source from the content-addressed store, hash-verified

115
116// scaleRegularThread adds a regular PHP thread automatically
117func scaleRegularThread(done chan struct{}, mstate *state.ThreadState) {
118 // probe CPU usage before acquiring the lock (avoids holding lock during 120ms sleep)
119 if !cpu.ProbeCPUs(cpuProbeTime, maxCpuUsageForScaling, done) {
120 return
121 }
122
123 scalingMu.Lock()
124 defer scalingMu.Unlock()
125
126 if !mstate.Is(state.Ready) {
127 return
128 }
129
130 thread, err := addRegularThread()
131 if err != nil {
132 if globalLogger.Enabled(globalCtx, slog.LevelWarn) {
133 globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "could not increase max_threads, consider raising this limit", slog.Any("error", err))
134 }
135
136 return
137 }
138
139 autoScaledThreads = append(autoScaledThreads, thread)
140
141 if globalLogger.Enabled(globalCtx, slog.LevelInfo) {
142 globalLogger.LogAttrs(globalCtx, slog.LevelInfo, "upscaling regular thread", slog.Int("thread", thread.threadIndex), slog.Int("num_threads", len(autoScaledThreads)))
143 }
144}
145
146func startUpscalingThreads(maxScaledThreads int, scale chan *frankenPHPContext, done chan struct{}, mstate *state.ThreadState) {
147 for {

Calls 3

ProbeCPUsFunction · 0.92
addRegularThreadFunction · 0.85
IsMethod · 0.80