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

Increase heap memory for jsii engine #745

Closed
2 of 6 tasks
bverhoeve opened this issue Aug 27, 2019 · 7 comments
Closed
2 of 6 tasks

Increase heap memory for jsii engine #745

bverhoeve opened this issue Aug 27, 2019 · 7 comments
Labels
closed-for-staleness effort/medium Medium work item – a couple days of effort feature-request A feature should be added or improved. module/runtime Issues affecting the `jsii-runtime` needs-discussion This issue/PR requires more discussion with community. p2

Comments

@bverhoeve
Copy link

bverhoeve commented Aug 27, 2019

🚀 Feature Request

When using JSII for small AWS CDK applications, the JSII kernel will normally not run out of heap memory. However, for larger apps (>800 resources, multiple stacks), depending on the complexity, you can encounter the following error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory.

Is there already a way to increase the Javascript heap memory beyond the default value?

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

General Information

  • JSII Version: v0.15
  • Platform: UNIX
  • I may be able to implement this feature request
  • This feature might incur a breaking change

Description

Add a setting in the cdk.json file which specifies the maximum allowed heap memory that jsii can allocate. Set the maximum heap memory then to this setting.

Proposed Solution

@bverhoeve bverhoeve added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 27, 2019
@RomainMuller
Copy link
Contributor

I don't think we can host this setting in cdk.json (because JSII can be used in contexts other than cdk).

Ability to customize the node runtime is however a very interesting idea and we should dig into this further. We should also consider what other aspects of the node runtime we could/should allow users to control.

@RomainMuller RomainMuller added module/runtime Issues affecting the `jsii-runtime` and removed needs-triage This issue or PR still needs to be triaged. labels Aug 28, 2019
@RomainMuller RomainMuller self-assigned this Aug 28, 2019
@RomainMuller
Copy link
Contributor

Note that in the meantime, you can pass additional arguments to the node process by setting the NODE_OPTIONS environment variable. In particular, controlling the max heap size can be achieved using:

# Sets the maximum heap to 4GiB
NODE_OPTIONS='--max-old-space-size=4096'

@bverhoeve
Copy link
Author

Does jsii always use the system node installation to run? Or does it use another kernel?

If the system node is the case, the NODE_OPTIONS is quite nice already as a workaround :)

@bverhoeve
Copy link
Author

@RomainMuller the NODE_OPTIONS variable works for increasing the max heap size, but unfortunately not the call stack size. This can be changed by using node with the --stack_size option set to a certain value. Unfortunately, the --stack_size option can't be set yet using NODE_OPTIONS.

@RomainMuller
Copy link
Contributor

Ah - an alternate way to solve this until we actually support acting on those settings via configuration is to create a wrapper around node that is ahead of the real node in your $PATH, something along the lines of (warning: I haven't tested it):

#!/bin/bash

/usr/local/bin/node --stack_size=4096 $@

@RomainMuller RomainMuller added the effort/medium Medium work item – a couple days of effort label Jan 24, 2020
@SomayaB SomayaB added needs-discussion This issue/PR requires more discussion with community. and removed status/needs-design labels Feb 25, 2020
@ansgarm
Copy link
Contributor

ansgarm commented Jun 1, 2021

We recently encountered this as well in the CDK for Terraform when generating provider bindings for the AWS Terraform Provider for Go.

Here is a small example which can be used to reproduce the issue or to do some profiling.
For now we went the route of setting NODE_OPTIONS on process.env so it is made available to the child process for jsii-pakmak which is spawned by jsii-srcmak (which we use). While this seems like an okayish fix, I'm still a bit confused why the memory usage is that heavy.

Do you have any pointers where one might start digging, @RomainMuller? We're experiencing this particularly with Go (to this 7 GB extent 🏋️😄)

@github-actions
Copy link
Contributor

This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness effort/medium Medium work item – a couple days of effort feature-request A feature should be added or improved. module/runtime Issues affecting the `jsii-runtime` needs-discussion This issue/PR requires more discussion with community. p2
Projects
None yet
Development

No branches or pull requests

4 participants