Skip to content

Commit a3984d0

Browse files
feat(ai): Enhance orchestrator selection by incorporating latency (livepeer#3043)
This commit introduces latency consideration into the orchestrator selection process, addressing two key issues. Firstly, it resolves a minor bug where the algorithm consistently selected known orchestrators due to a condition that never evaluated to true (see [this condition](https://github.com/livepeer/go-livepeer/blob/1239b4e56133003fe6a98a863cce6bdd6b5f2532/server/selection.go#L110)). Secondly, this change ensures that, once all orchestrators have been evaluated, the one with the fastest response time for a specific job is chosen. While the current method for calculating latency is somewhat basic, it sets the foundation for more sophisticated enhancements in the future. Co-authored-by: Brad P <0xb79orch@gmail.com>
1 parent 4932a66 commit a3984d0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server/ai_process.go

+19
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func submitTextToImage(ctx context.Context, params aiRequestParams, sess *AISess
9393
}
9494
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)
9595

96+
start := time.Now()
9697
resp, err := client.TextToImageWithResponse(ctx, req, setHeaders)
98+
took := time.Since(start)
9799
if err != nil {
98100
return nil, err
99101
}
@@ -108,6 +110,13 @@ func submitTextToImage(ctx context.Context, params aiRequestParams, sess *AISess
108110
balUpdate.Status = ReceivedChange
109111
}
110112

113+
// TODO: Refine this rough estimate in future iterations
114+
numImages := 1
115+
if req.NumImagesPerPrompt != nil {
116+
numImages = *req.NumImagesPerPrompt
117+
}
118+
sess.LatencyScore = took.Seconds() / float64(outPixels) / float64(numImages)
119+
111120
return resp.JSON200, nil
112121
}
113122

@@ -168,7 +177,9 @@ func submitImageToImage(ctx context.Context, params aiRequestParams, sess *AISes
168177
}
169178
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)
170179

180+
start := time.Now()
171181
resp, err := client.ImageToImageWithBodyWithResponse(ctx, mw.FormDataContentType(), &buf, setHeaders)
182+
took := time.Since(start)
172183
if err != nil {
173184
return nil, err
174185
}
@@ -183,6 +194,9 @@ func submitImageToImage(ctx context.Context, params aiRequestParams, sess *AISes
183194
balUpdate.Status = ReceivedChange
184195
}
185196

197+
// TODO: Refine this rough estimate in future iterations
198+
sess.LatencyScore = took.Seconds() / float64(outPixels)
199+
186200
return resp.JSON200, nil
187201
}
188202

@@ -246,7 +260,9 @@ func submitImageToVideo(ctx context.Context, params aiRequestParams, sess *AISes
246260
}
247261
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)
248262

263+
start := time.Now()
249264
resp, err := client.ImageToVideoWithBody(ctx, mw.FormDataContentType(), &buf, setHeaders)
265+
took := time.Since(start)
250266
if err != nil {
251267
return nil, err
252268
}
@@ -271,6 +287,9 @@ func submitImageToVideo(ctx context.Context, params aiRequestParams, sess *AISes
271287
return nil, err
272288
}
273289

290+
// TODO: Refine this rough estimate in future iterations
291+
sess.LatencyScore = took.Seconds() / float64(outPixels)
292+
274293
return &res, nil
275294
}
276295

0 commit comments

Comments
 (0)