Skip to content

Commit 073c348

Browse files
committed
utility function
1 parent d472f71 commit 073c348

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

scaling.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ func scaleRegularThread() {
130130
autoScaledThreads = append(autoScaledThreads, thread)
131131
}
132132

133+
func getWorker(fc *frankenPHPContext) *worker {
134+
// if the request has been stalled long enough, scale
135+
if workersList, ok := workers[fc.scriptFilename]; ok {
136+
// Look for a worker with matching moduleID or a global worker (moduleID == 0)
137+
for _, worker := range workersList {
138+
if worker.moduleID == 0 || worker.moduleID == fc.moduleID {
139+
return worker
140+
}
141+
}
142+
}
143+
return nil
144+
}
145+
133146
func startUpscalingThreads(maxScaledThreads int, scale chan *frankenPHPContext, done chan struct{}) {
134147
for {
135148
scalingMu.Lock()
@@ -160,19 +173,8 @@ func startUpscalingThreads(maxScaledThreads int, scale chan *frankenPHPContext,
160173
}
161174

162175
// if the request has been stalled long enough, scale
163-
if workersList, ok := workers[fc.scriptFilename]; ok {
164-
// Look for a worker with matching moduleID or a global worker (moduleID == 0)
165-
workerFound := false
166-
for _, worker := range workersList {
167-
if worker.moduleID == 0 || worker.moduleID == fc.moduleID {
168-
scaleWorkerThread(worker)
169-
workerFound = true
170-
break
171-
}
172-
}
173-
if !workerFound {
174-
scaleRegularThread()
175-
}
176+
if worker := getWorker(fc); worker != nil {
177+
scaleWorkerThread(worker)
176178
} else {
177179
scaleRegularThread()
178180
}

0 commit comments

Comments
 (0)