Skip to content

Commit 1e75842

Browse files
committed
more cleanup
1 parent b636718 commit 1e75842

9 files changed

Lines changed: 16 additions & 29 deletions

File tree

caddy/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (admin *FrankenPHPAdmin) restartWorkers(w http.ResponseWriter, r *http.Requ
4444
return nil
4545
}
4646

47-
func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, r *http.Request) error {
47+
func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, _ *http.Request) error {
4848
debugState := frankenphp.DebugState()
4949
prettyJson, err := json.MarshalIndent(debugState, "", " ")
5050
if err != nil {

cgi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func packCgiVariable(key *C.zend_string, value string) C.ht_key_value_pair {
168168
return C.ht_key_value_pair{key, toUnsafeChar(value), C.size_t(len(value))}
169169
}
170170

171-
func addHeadersToServer(thread *phpThread, fc *frankenPHPContext, trackVarsArray *C.zval) {
171+
func addHeadersToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
172172
for field, val := range fc.request.Header {
173173
if k := mainThread.commonHeaders[field]; k != nil {
174174
v := strings.Join(val, ", ")
@@ -197,7 +197,7 @@ func go_register_variables(threadIndex C.uintptr_t, trackVarsArray *C.zval) {
197197
fc := thread.getRequestContext()
198198

199199
addKnownVariablesToServer(thread, fc, trackVarsArray)
200-
addHeadersToServer(thread, fc, trackVarsArray)
200+
addHeadersToServer(fc, trackVarsArray)
201201

202202
// The Prepared Environment is registered last and can overwrite any previous values
203203
addPreparedEnvToServer(fc, trackVarsArray)

internal/watcher/watcher.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func listenForFileEvents(triggerWatcher chan string, stopWatcher chan struct{})
187187
for {
188188
select {
189189
case <-stopWatcher:
190-
break
191190
case lastChangedFile = <-triggerWatcher:
192191
timer.Reset(debounceDuration)
193192
case <-timer.C:

metrics.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const (
1212
StopReasonCrash = iota
1313
StopReasonRestart
14-
StopReasonShutdown
14+
//StopReasonShutdown
1515
)
1616

1717
type StopReason int
@@ -74,9 +74,9 @@ func (n nullMetrics) StartWorkerRequest(string) {
7474
func (n nullMetrics) Shutdown() {
7575
}
7676

77-
func (n nullMetrics) QueuedWorkerRequest(name string) {}
77+
func (n nullMetrics) QueuedWorkerRequest(string) {}
7878

79-
func (n nullMetrics) DequeuedWorkerRequest(name string) {}
79+
func (n nullMetrics) DequeuedWorkerRequest(string) {}
8080

8181
func (n nullMetrics) QueuedRequest() {}
8282
func (n nullMetrics) DequeuedRequest() {}
@@ -127,9 +127,10 @@ func (m *PrometheusMetrics) StopWorker(name string, reason StopReason) {
127127
m.totalWorkers.WithLabelValues(name).Dec()
128128
m.readyWorkers.WithLabelValues(name).Dec()
129129

130-
if reason == StopReasonCrash {
130+
switch reason {
131+
case StopReasonCrash:
131132
m.workerCrashes.WithLabelValues(name).Inc()
132-
} else if reason == StopReasonRestart {
133+
case StopReasonRestart:
133134
m.workerRestarts.WithLabelValues(name).Inc()
134135
}
135136
}

phpmainthread.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,6 @@ func getInactivePHPThread() *phpThread {
144144
return nil
145145
}
146146

147-
func getPHPThreadAtState(state stateID) *phpThread {
148-
for _, thread := range phpThreads {
149-
if thread.state.is(state) {
150-
return thread
151-
}
152-
}
153-
return nil
154-
}
155-
156147
//export go_frankenphp_main_thread_is_ready
157148
func go_frankenphp_main_thread_is_ready() {
158149
mainThread.setAutomaticMaxThreads()

phpmainthread_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func allPossibleTransitions(worker1Path string, worker2Path string) []func(*phpT
220220

221221
func TestCorrectThreadCalculation(t *testing.T) {
222222
maxProcs := runtime.GOMAXPROCS(0) * 2
223-
oneWorkerThread := []workerOpt{workerOpt{num: 1}}
223+
oneWorkerThread := []workerOpt{{num: 1}}
224224

225225
// default values
226226
testThreadCalculation(t, maxProcs, maxProcs, &opt{})

scaling.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const (
2020
cpuProbeTime = 120 * time.Millisecond
2121
// do not scale over this amount of CPU usage
2222
maxCpuUsageForScaling = 0.8
23-
// upscale stalled threads every x milliseconds
24-
upscaleCheckTime = 100 * time.Millisecond
2523
// downscale idle threads every x seconds
2624
downScaleCheckTime = 5 * time.Second
2725
// max amount of threads stopped in one iteration of downScaleCheckTime
@@ -31,13 +29,11 @@ const (
3129
)
3230

3331
var (
32+
ErrMaxThreadsReached = errors.New("max amount of overall threads reached")
33+
3434
scaleChan chan *frankenPHPContext
3535
autoScaledThreads = []*phpThread{}
3636
scalingMu = new(sync.RWMutex)
37-
38-
MaxThreadsReachedError = errors.New("max amount of overall threads reached")
39-
CannotRemoveLastThreadError = errors.New("cannot remove last thread")
40-
WorkerNotFoundError = errors.New("worker not found for given filename")
4137
)
4238

4339
func initAutoScaling(mainThread *phpMainThread) {
@@ -67,7 +63,7 @@ func drainAutoScaling() {
6763
func addRegularThread() (*phpThread, error) {
6864
thread := getInactivePHPThread()
6965
if thread == nil {
70-
return nil, MaxThreadsReachedError
66+
return nil, ErrMaxThreadsReached
7167
}
7268
convertToRegularThread(thread)
7369
thread.state.waitFor(stateReady, stateShuttingDown, stateReserved)
@@ -77,7 +73,7 @@ func addRegularThread() (*phpThread, error) {
7773
func addWorkerThread(worker *worker) (*phpThread, error) {
7874
thread := getInactivePHPThread()
7975
if thread == nil {
80-
return nil, MaxThreadsReachedError
76+
return nil, ErrMaxThreadsReached
8177
}
8278
convertToWorkerThread(thread, worker)
8379
thread.state.waitFor(stateReady, stateShuttingDown, stateReserved)

threadinactive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (handler *inactiveThread) beforeScriptExecution() string {
3333
panic("unexpected state: " + thread.state.name())
3434
}
3535

36-
func (handler *inactiveThread) afterScriptExecution(exitStatus int) {
36+
func (handler *inactiveThread) afterScriptExecution(int) {
3737
panic("inactive threads should not execute scripts")
3838
}
3939

threadregular.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (handler *regularThread) beforeScriptExecution() string {
4747
}
4848

4949
// return true if the worker should continue to run
50-
func (handler *regularThread) afterScriptExecution(exitStatus int) {
50+
func (handler *regularThread) afterScriptExecution(int) {
5151
handler.afterRequest()
5252
}
5353

0 commit comments

Comments
 (0)