Skip to content

model-serving: build the plugin chain once instead of per role replica #1834

Description

@Abhayanthk

What would you like to be added:

Build the ModelServing plugin chain once and reuse it for every pod created in the same pass, as the TODO in CreatePodsByRole suggests:

func (c *ModelServingController) CreatePodsByRole(ctx context.Context, role workloadv1alpha1.Role, ms *workloadv1alpha1.ModelServing, roleIndex int, servingGroupOrdinal int, revision string, roleTemplateHash string) error {
servingGroupName := utils.GenerateServingGroupName(ms.Name, servingGroupOrdinal)
// TODO(hzxuzhonghu): build the plugin chain only once per ModelServing
// This is not critical now, so we leave it for future optimization.
chain, err := c.buildPluginChain(ms)
if err != nil {
return fmt.Errorf("build plugin chain: %w", err)
}

Today CreatePodsByRole calls buildPluginChain on every call. Its callers invoke it inside loops, once per role replica:

Proposed change: build the chain once in each caller and pass it into CreatePodsByRole as a parameter. Behaviour stays the same, and unit tests would check that the chain is built once per pass and still applied to entry and worker pods.

Why is this needed:

When spec.plugins is set, plugins.NewChain runs every plugin factory again for each role replica, so a ServingGroup with N role replicas builds the same chain N times in one reconcile. When no plugins are configured, buildPluginChain returns early, so the cost only applies to ModelServings that use plugins.

@hzxuzhonghu, is this still wanted? If so, I'd like to work on it. One question first: is a chain safe to reuse across pods within one reconcile, or do some plugins keep per-pod state?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions