cli: allow to parallelize asset build #32789
Labels
effort/small
Small work item – less than a day of effort
feature-request
A feature should be added or improved.
p2
package/tools
Related to AWS CDK Tools or CLI
Describe the feature
Currently in
cdk deploy
, assets are built serially one by one, making it slow when there are many container image assets.The current behavior assumes that asset build is CPU-bound and will not get benefit from parallelism:
aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts
Lines 559 to 563 in bbdd42c
However, in our use cases, our assets are not fully cpu-bound and will actually get faster when parallelized. That is why I want to configure the concurrency parameter by CLI arguments.
Use Case
When a CDK app contains many docker images whose build process are not fully CPU-bound, we can make cdk deploy faster by parallelizing the asset build processes.
You can see the outcome by the following extreme example:
And this CDK code:
When you run cdk deploy, you can see the five images are built serially, requiring more than 50 seconds to finish deployment.
Currently you can configure the parallelism parameter by directly editing
node_modules/aws-cdk/lib/index.js
, search for{"stack":concurrency,"asset-build":1
and replace it with{"stack":concurrency,"asset-build":5
.After updateing the parameter, run cdk deploy again (make sure to change
DUMMY_ARG
to invalidate caches), and all the images are built concurrently. It now takes about 10 seconds.Proposed Solution
Expose CLI argument like
asset-build-concurrency
. Default is 1, and set the value here.aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts
Lines 559 to 563 in bbdd42c
Other Information
No response
Acknowledgements
CDK version used
2.174.1
Environment details (OS name and version, etc.)
macOS
The text was updated successfully, but these errors were encountered: