Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): template bulk runner count for parallel apply #6510

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,15 @@ func (a *API) Serve(ctx context.Context) error {
a.cleanWorkflowRunSecrets(ctx)
})
}
chanWorkflowTemplateBulkOperation := make(chan WorkflowTemplateBulkOperation)
if a.Config.Workflow.TemplateBulkRunnerCount == 0 {
a.Config.Workflow.TemplateBulkRunnerCount = 10
}
chanWorkflowTemplateBulkOperation := make(chan WorkflowTemplateBulkOperation, a.Config.Workflow.TemplateBulkRunnerCount*10)
defer close(chanWorkflowTemplateBulkOperation)
a.GoRoutines.RunWithRestart(ctx, "api.WorkflowTemplateBulk", func(ctx context.Context) {
a.WorkflowTemplateBulk(ctx, 100*time.Millisecond, chanWorkflowTemplateBulkOperation)
})
a.WorkflowTemplateBulkOperation(ctx, a.Config.Workflow.MaxRuns, chanWorkflowTemplateBulkOperation)
a.WorkflowTemplateBulkOperation(ctx, chanWorkflowTemplateBulkOperation)

log.Info(ctx, "Bootstrapping database...")
defaultValues := sdk.DefaultValues{
Expand Down
17 changes: 10 additions & 7 deletions engine/api/workflow_template_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (api *API) workflowTemplateBulk(ctx context.Context, bulkID int64, chanOper
}

if b.Parallel {
for len(operationTodo) > 0 {
for i := 0; i < int(api.Config.Workflow.TemplateBulkRunnerCount) && len(operationTodo) > 0; i++ {
chanOperation <- operationTodo.Pop()
}
} else {
Expand All @@ -137,7 +137,13 @@ func (api *API) workflowTemplateBulk(ctx context.Context, bulkID int64, chanOper
return nil
}
if (res.Status == sdk.OperationStatusDone || res.Status == sdk.OperationStatusError) && len(operationTodo) > 0 {
chanOperation <- operationTodo.Pop()
if b.Parallel {
for i := 0; i < int(api.Config.Workflow.TemplateBulkRunnerCount) && len(operationTodo) > 0; i++ {
chanOperation <- operationTodo.Pop()
}
} else {
chanOperation <- operationTodo.Pop()
}
}
case <-ctx.Done():
b.Status = sdk.OperationStatusPending
Expand All @@ -146,11 +152,8 @@ func (api *API) workflowTemplateBulk(ctx context.Context, bulkID int64, chanOper
}
}

func (api *API) WorkflowTemplateBulkOperation(ctx context.Context, routineCount int64, chanOperation chan WorkflowTemplateBulkOperation) {
if routineCount == 0 {
routineCount = 10
}
for i := int64(0); i < routineCount; i++ {
func (api *API) WorkflowTemplateBulkOperation(ctx context.Context, chanOperation chan WorkflowTemplateBulkOperation) {
for i := int64(0); i < api.Config.Workflow.TemplateBulkRunnerCount; i++ {
api.GoRoutines.RunWithRestart(ctx, fmt.Sprintf("api.WorkflowTemplateBulkOperation-%d", i), func(ctx context.Context) {
for {
select {
Expand Down