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

Function scaleWorkerThread

scaling.go:87–114  ·  view source on GitHub ↗

scaleWorkerThread adds a worker PHP thread automatically

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

Source from the content-addressed store, hash-verified

85
86// scaleWorkerThread adds a worker PHP thread automatically
87func scaleWorkerThread(worker *worker, done chan struct{}, mstate *state.ThreadState) {
88 // probe CPU usage before acquiring the lock (avoids holding lock during 120ms sleep)
89 if !cpu.ProbeCPUs(cpuProbeTime, maxCpuUsageForScaling, done) {
90 return
91 }
92
93 scalingMu.Lock()
94 defer scalingMu.Unlock()
95
96 if !mstate.Is(state.Ready) {
97 return
98 }
99
100 thread, err := addWorkerThread(worker)
101 if err != nil {
102 if globalLogger.Enabled(globalCtx, slog.LevelWarn) {
103 globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "could not increase max_threads, consider raising this limit", slog.String("worker", worker.name), slog.Any("error", err))
104 }
105
106 return
107 }
108
109 autoScaledThreads = append(autoScaledThreads, thread)
110
111 if globalLogger.Enabled(globalCtx, slog.LevelInfo) {
112 globalLogger.LogAttrs(globalCtx, slog.LevelInfo, "upscaling worker thread", slog.String("worker", worker.name), slog.Int("thread", thread.threadIndex), slog.Int("num_threads", len(autoScaledThreads)))
113 }
114}
115
116// scaleRegularThread adds a regular PHP thread automatically
117func scaleRegularThread(done chan struct{}, mstate *state.ThreadState) {

Callers 2

startUpscalingThreadsFunction · 0.85

Calls 4

ProbeCPUsFunction · 0.92
addWorkerThreadFunction · 0.85
IsMethod · 0.80
StringMethod · 0.45

Tested by 1