scaleWorkerThread adds a worker PHP thread automatically
(worker *worker, done chan struct{}, mstate *state.ThreadState)
| 85 | |
| 86 | // scaleWorkerThread adds a worker PHP thread automatically |
| 87 | func 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 |
| 117 | func scaleRegularThread(done chan struct{}, mstate *state.ThreadState) { |