-
Notifications
You must be signed in to change notification settings - Fork 358
Add per-phase graph concurrency limits #9752
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
Open
Rick Winter (RickWinter)
wants to merge
3
commits into
Azure:main
Choose a base branch
from
RickWinter:rickwinter-per-phase-concurrency-limits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "log" | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| const ( | ||
| concurrencyMaxEnvVar = "AZD_CONCURRENCY_MAX" | ||
| packageConcurrencyEnvVar = "AZD_PACKAGE_CONCURRENCY" | ||
| provisionConcurrencyEnvVar = "AZD_PROVISION_CONCURRENCY" | ||
| deployConcurrencyEnvVar = "AZD_DEPLOY_CONCURRENCY" | ||
| upConcurrencyEnvVar = "AZD_UP_CONCURRENCY" | ||
|
|
||
| packageConcurrencyGroup = "package" | ||
| provisionConcurrencyGroup = "provision" | ||
| deployConcurrencyGroup = "deploy" | ||
|
|
||
| maxConfiguredConcurrency = 64 | ||
| ) | ||
|
|
||
| type environmentLookup func(string) (string, bool) | ||
|
|
||
| type concurrencySetting struct { | ||
| value int | ||
| set bool | ||
| } | ||
|
|
||
| type graphConcurrencyOptions struct { | ||
| max int | ||
| groups map[string]int | ||
| } | ||
|
|
||
| func resolveConcurrencySetting(lookup environmentLookup, envName string) concurrencySetting { | ||
| envValue, ok := lookup(envName) | ||
| if !ok { | ||
| return concurrencySetting{} | ||
| } | ||
|
|
||
| setting := concurrencySetting{set: true} | ||
| value, err := strconv.Atoi(envValue) | ||
| if err != nil { | ||
| log.Printf("warning: ignoring invalid %s=%q: %v", envName, envValue, err) | ||
| return setting | ||
| } | ||
| if value <= 0 { | ||
| log.Printf( | ||
| "warning: ignoring invalid %s=%q: value must be greater than zero; "+ | ||
| "lower-precedence concurrency settings will not apply", | ||
| envName, | ||
| envValue, | ||
| ) | ||
| return setting | ||
| } | ||
|
|
||
| setting.value = min(value, maxConfiguredConcurrency) | ||
| if setting.value < value { | ||
| label := strings.ToLower(strings.ReplaceAll(strings.TrimPrefix(envName, "AZD_"), "_", " ")) | ||
| log.Printf("clamping %s from %d to %d", label, value, setting.value) | ||
| } | ||
| return setting | ||
| } | ||
|
|
||
| func firstConcurrency(settings ...concurrencySetting) int { | ||
| for _, setting := range settings { | ||
| if setting.set { | ||
| return setting.value | ||
| } | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| func resolveUpGraphConcurrency(lookup environmentLookup) graphConcurrencyOptions { | ||
| maxSetting := resolveConcurrencySetting(lookup, concurrencyMaxEnvVar) | ||
| upSetting := resolveConcurrencySetting(lookup, upConcurrencyEnvVar) | ||
| packageSetting := resolveConcurrencySetting(lookup, packageConcurrencyEnvVar) | ||
| provisionSetting := resolveConcurrencySetting(lookup, provisionConcurrencyEnvVar) | ||
| deploySetting := resolveConcurrencySetting(lookup, deployConcurrencyEnvVar) | ||
|
|
||
| // AZD_DEPLOY_CONCURRENCY remains the last hard-ceiling fallback so users who | ||
| // tuned `azd deploy` parallelism before `azd up` gained its own variable do | ||
| // not silently get the unbounded scheduler default for the whole graph. | ||
| return graphConcurrencyOptions{ | ||
| max: firstConcurrency(maxSetting, upSetting, deploySetting), | ||
| groups: map[string]int{ | ||
| packageConcurrencyGroup: firstConcurrency(packageSetting, upSetting), | ||
| provisionConcurrencyGroup: firstConcurrency(provisionSetting, upSetting), | ||
| deployConcurrencyGroup: firstConcurrency(deploySetting, upSetting), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func resolveDeployGraphConcurrency(lookup environmentLookup) graphConcurrencyOptions { | ||
| maxSetting := resolveConcurrencySetting(lookup, concurrencyMaxEnvVar) | ||
| packageSetting := resolveConcurrencySetting(lookup, packageConcurrencyEnvVar) | ||
| deploySetting := resolveConcurrencySetting(lookup, deployConcurrencyEnvVar) | ||
|
|
||
| return graphConcurrencyOptions{ | ||
| max: firstConcurrency(maxSetting, deploySetting), | ||
| groups: map[string]int{ | ||
| packageConcurrencyGroup: firstConcurrency(packageSetting, deploySetting), | ||
| deployConcurrencyGroup: deploySetting.value, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func resolveProvisionGraphConcurrency(lookup environmentLookup) graphConcurrencyOptions { | ||
| maxSetting := resolveConcurrencySetting(lookup, concurrencyMaxEnvVar) | ||
| provisionSetting := resolveConcurrencySetting(lookup, provisionConcurrencyEnvVar) | ||
|
|
||
| return graphConcurrencyOptions{ | ||
| max: firstConcurrency(maxSetting, provisionSetting), | ||
| groups: map[string]int{ | ||
| provisionConcurrencyGroup: provisionSetting.value, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "log" | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/environment" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestResolveConcurrencySettingWarnsForNonPositiveValues(t *testing.T) { | ||
| var output bytes.Buffer | ||
| originalWriter := log.Writer() | ||
| log.SetOutput(&output) | ||
| t.Cleanup(func() { | ||
| log.SetOutput(originalWriter) | ||
| }) | ||
|
|
||
| for _, value := range []string{"0", "-1"} { | ||
| output.Reset() | ||
| setting := resolveConcurrencySetting(lookupEnvironment(map[string]string{ | ||
| packageConcurrencyEnvVar: value, | ||
| }), packageConcurrencyEnvVar) | ||
|
|
||
| assert.True(t, setting.set) | ||
| assert.Zero(t, setting.value) | ||
| assert.Contains(t, output.String(), "value must be greater than zero") | ||
| assert.Contains(t, output.String(), "lower-precedence concurrency settings will not apply") | ||
| } | ||
| } | ||
|
|
||
| func TestUpGraphRunOptionsUsesActiveEnvironment(t *testing.T) { | ||
| t.Setenv(packageConcurrencyEnvVar, "1") | ||
| t.Setenv(upConcurrencyEnvVar, "2") | ||
| env := environment.NewWithValues("test", map[string]string{ | ||
| packageConcurrencyEnvVar: "3", | ||
| upConcurrencyEnvVar: "4", | ||
| }) | ||
|
|
||
| opts := (&UpGraphAction{env: env}).runOptions() | ||
|
|
||
| assert.Equal(t, 4, opts.MaxConcurrency) | ||
| assert.Equal(t, 3, opts.GroupConcurrency[packageConcurrencyGroup]) | ||
| assert.Equal(t, 4, opts.GroupConcurrency[provisionConcurrencyGroup]) | ||
| assert.Equal(t, 4, opts.GroupConcurrency[deployConcurrencyGroup]) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.