Skip to content

Commit

Permalink
fix: multiplicative backoff for shutdown (#3547)
Browse files Browse the repository at this point in the history
* multiplicative backoff for shutdown

Rather than always retry every two seconds, back off the shutdown attempt rate? 

Signed-off-by: Dave <dave@gray101.com>

* Update loader.go

Signed-off-by: Dave <dave@gray101.com>

* add clamp of 2 minutes

Signed-off-by: Dave Lee <dave@gray101.com>

---------

Signed-off-by: Dave <dave@gray101.com>
Signed-off-by: Dave Lee <dave@gray101.com>
  • Loading branch information
dave-gray101 authored Sep 16, 2024
1 parent e22e514 commit ae86724
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/model/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ var knownModelsNameSuffixToSkip []string = []string{
".tar.gz",
}

const retryTimeout = time.Duration(2 * time.Minute)

func (ml *ModelLoader) ListFilesInModelPath() ([]string, error) {
files, err := os.ReadDir(ml.ModelPath)
if err != nil {
Expand Down Expand Up @@ -151,9 +153,15 @@ func (ml *ModelLoader) ShutdownModel(modelName string) error {
return fmt.Errorf("model %s not found", modelName)
}

retries := 1
for ml.models[modelName].GRPC(false, ml.wd).IsBusy() {
log.Debug().Msgf("%s busy. Waiting.", modelName)
time.Sleep(2 * time.Second)
dur := time.Duration(retries*2) * time.Second
if dur > retryTimeout {
dur = retryTimeout
}
time.Sleep(dur)
retries++
}

return ml.deleteProcess(modelName)
Expand Down

0 comments on commit ae86724

Please sign in to comment.