Replies: 1 comment 2 replies
-
We are working on bundling all of Re |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
We have a pretty large CDK app deployed using a CDK pipeline. There are many stacks resulting in a few dozen asset "publish" CodeBuild jobs. Most of these are just "file" jobs but a few are "docker" jobs.
We run this pipeline with some frequency, and the latency overhead added by CDK, especially in these publish jobs, is a meaningful amount on top of the latency of CloudFormation actually deploying stacks. It would be ideal to reduce this added latency.
The typical publish job takes 20-40s to start running on CodeBuild (using on-demand EC2 instances, which is the default), then spends 20-30s in the INSTALL phase running
npm install cdk-assets@2
(the transitive dependency graph of which expands to almost 300 npm packages!), then spends less than a second in the BUILD phase invokingcdk-assets
to upload the assembly to S3. Because we have dozens of such jobs, the overall pipeline ends up getting a (I use this term vaguely) "worst-case" sampling of the variable latencies here.We could eliminate a lot of the startup latency by running the publish jobs on Lambda instead of EC2, but
docker
is not supported in Lambda, so it's not actually an option.We could eliminate the "worst-case" sampling problem by setting
publishAssetsInParallel
to false, which might be a worthwhile tradeoff, if the serialized invocations ofcdk-assets
take less time than the difference between median and "worst-case" CodeBuild EC2 startup +npm install
latency. But in cases where we are modifying docker images such thatdocker build
needs to be invoked, the cost of serializing suchdocker build
s probably is too high for this to be a good strategy.Maybe CodeBuild S3 caching (or local caching, with reserved capacity hosts?) could be used to elide the cost of
npm install cdk-assets@2
? I have not experimented with this.Maybe the newly added CodeBuild docker server feature could help reduce latency of "docker" jobs? But it requires
docker buildx
, which cdk-assets does not use. I've heard that you can kind of hackily convince cdk-assets to invokedocker buildx
with clever abuse of the CDK_DOCKER environment variable, though I've not actually experimented with this myself.Some combination of
publishAssetsInParallel: false
+ caching + a single reserved capacity CodeBuild instance to be used throughout the CDK pipeline might be the right approach to meaningfully and cost effectively reduce latency, but I think it'd be ideal if things were lower latency out of the box, so that all users of CDK pipelines could benefit.A point of confusion for me, which maybe you can help clarify: why are there separate publish jobs in the first place? Why does the single synth job have to upload a single massive zip file as an artifact for all the publish jobs to download and then collectively break apart and push to S3/ECR? Why can't the synth job do all that itself?
Relatedly, why is
cdk-assets
consumed as an unpinned dependency outside of my project (that is, I haveaws-cdk
andaws-cdk-lib
both pinned in my yarn.lock) that has to be installed from npm at the start of every job? Naively, I'd expect the functionality ofcdk-assets
to be baked into the CDK CLI, and for publish jobs to use the version of the CLI that I'm using elsewhere in my project.Sorry for such an expansive post, but this seems to be an expansive problem! I'd love to hear anybody's thoughts on how to tackle this kind of problem, but maybe some "inside baseball" from CDK maintainers would be especially helpful 🌞. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions