Skip to content

Commit

Permalink
refactor(ai): improve selection algorithm retry durtaion
Browse files Browse the repository at this point in the history
This commit replaces the simple timebased for loop in the selection
algorithm retry logic with a context.
  • Loading branch information
rickstaa committed Apr 24, 2024
1 parent 5a08c6d commit 87d8213
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/ai_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/livepeer/lpms/stream"
)

const maxProcessingRetryDuration = 500 * time.Millisecond
const processingRetryTimeout = 2 * time.Second
const defaultTextToImageModelID = "stabilityai/sdxl-turbo"
const defaultImageToImageModelID = "stabilityai/sdxl-turbo"
const defaultImageToVideoModelID = "stabilityai/stable-video-diffusion-img2vid-xt"
Expand Down Expand Up @@ -312,9 +312,11 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface

var resp *worker.ImageResponse

cctx, cancel := context.WithTimeout(context.Background(), processingRetryTimeout)
defer cancel()

tries := 0
retryDuration := time.Now().Add(maxProcessingRetryDuration)
for time.Now().Before(retryDuration) {
for {
tries++

sess, err := params.sessManager.Select(ctx, cap, modelID)
Expand All @@ -336,6 +338,10 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface
clog.Infof(ctx, "Error submitting request cap=%v modelID=%v try=%v orch=%v err=%v", cap, modelID, tries, sess.Transcoder(), err)

params.sessManager.Remove(ctx, sess)

if cctx.Err() == context.DeadlineExceeded {
break
}
}

if resp == nil {
Expand Down

0 comments on commit 87d8213

Please sign in to comment.