Skip to content

Commit fb7c808

Browse files
authored
add timing for Process start, stop, total request time (#91)
1 parent a7e640b commit fb7c808

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

config.example.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
healthCheckTimeout: 90
44

55
# valid log levels: debug, info (default), warn, error
6-
logLevel: info
6+
logLevel: debug
77

88
models:
99
"llama":

proxy/process.go

+13
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func (p *Process) Shutdown() {
303303
// stopCommand will send a SIGTERM to the process and wait for it to exit.
304304
// If it does not exit within 5 seconds, it will send a SIGKILL.
305305
func (p *Process) stopCommand(sigtermTTL time.Duration) {
306+
stopStartTime := time.Now()
307+
defer func() {
308+
p.proxyLogger.Debugf("Process [%s] stopCommand took %v", p.ID, time.Since(stopStartTime))
309+
}()
310+
306311
sigtermTimeout, cancelTimeout := context.WithTimeout(context.Background(), sigtermTTL)
307312
defer cancelTimeout()
308313

@@ -369,6 +374,8 @@ func (p *Process) checkHealthEndpoint(healthURL string) error {
369374
}
370375

371376
func (p *Process) ProxyRequest(w http.ResponseWriter, r *http.Request) {
377+
requestBeginTime := time.Now()
378+
var startDuration time.Duration
372379

373380
// prevent new requests from being made while stopping or irrecoverable
374381
currentState := p.CurrentState()
@@ -385,11 +392,13 @@ func (p *Process) ProxyRequest(w http.ResponseWriter, r *http.Request) {
385392

386393
// start the process on demand
387394
if p.CurrentState() != StateReady {
395+
beginStartTime := time.Now()
388396
if err := p.start(); err != nil {
389397
errstr := fmt.Sprintf("unable to start process: %s", err)
390398
http.Error(w, errstr, http.StatusBadGateway)
391399
return
392400
}
401+
startDuration = time.Since(beginStartTime)
393402
}
394403

395404
proxyTo := p.config.Proxy
@@ -433,4 +442,8 @@ func (p *Process) ProxyRequest(w http.ResponseWriter, r *http.Request) {
433442
return
434443
}
435444
}
445+
446+
totalTime := time.Since(requestBeginTime)
447+
p.proxyLogger.Debugf("Process [%s] request %s - start: %v, total: %v",
448+
p.ID, r.RequestURI, startDuration, totalTime)
436449
}

0 commit comments

Comments
 (0)