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

feat(kernel): experimental runtime package cache #3724

Merged
merged 12 commits into from
Aug 30, 2022
Merged

Conversation

RomainMuller
Copy link
Contributor

Adds an experimental (hence opt-in) feature that caches the contents of
loaded libraries in a directory that persists between executions, in
order to spare the time it takes to extract the tarballs.

When this feature is enabled, packages present in the cache will be used
as-is (i.e: they are not checked for tampering) instead of being
extracted from the tarball. The cache is keyed on:

  • The hash of the tarball
  • The name of the library
  • The version of the library

Objects in the cache will expire if they are not used for 30 days, and
are subsequently removed from disk (this avoids a cache growing
extremely large over time).

In order to enable the feature, the following environment variables are
used:

  • JSII_RUNTIME_PACKAGE_CACHE must be set to enabled in order for the
    package cache to be active at all;
  • JSII_RUNTIME_PACKAGE_CACHE_ROOT can be used to change which
    directory is used as a cache root. It defaults to:
    • On MacOS: $HOME/Library/Caches/com.amazonaws.jsii
    • On Linux: $HOME/.cache/aws/jsii/package-cache
    • On Windows: %LOCALAPPDATA%\AWS\jsii\package-cache
    • On other platforms: $TMP/aws-jsii-package-cache
  • JSII_RUNTIME_PACKAGE_CACHE_TTL can be used to change the default
    time entries will remain in cache before expiring if they are not
    used. This defaults to 30 days, and the value is expressed in days.
    Set to 0 to immediately expire all the cache's content.

When troubleshooting load performance, it is possible to obtain timing
data for some critical parts of the library load process within the jsii
kernel by setting JSII_DEBUG_TIMING environment variable.

Related to #3389


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Adds an experimental (hence opt-in) feature that caches the contents of
loaded libraries in a directory that persists between executions, in
order to spare the time it takes to extract the tarballs.

When this feature is enabled, packages present in the cache will be used
as-is (i.e: they are not checked for tampering) instead of being
extracted from the tarball. The cache is keyed on:
- The hash of the tarball
- The name of the library
- The version of the library

Objects in the cache will expire if they are not used for 30 days, and
are subsequently removed from disk (this avoids a cache growing
extremely large over time).

In order to enable the feature, the following environment variables are
used:
- `JSII_RUNTIME_PACKAGE_CACHE` must be set to `enabled` in order for the
  package cache to be active at all;
- `JSII_RUNTIME_PACKAGE_CACHE_ROOT` can be used to change which
  directory is used as a cache root. It defaults to:
  * On MacOS: `$HOME/Library/Caches/com.amazonaws.jsii`
  * On Linux: `$HOME/.cache/aws/jsii/package-cache`
  * On Windows: `%LOCALAPPDATA%\AWS\jsii\package-cache`
  * On other platforms: `$TMP/aws-jsii-package-cache`
- `JSII_RUNTIME_PACKAGE_CACHE_TTL` can be used to change the default
  time entries will remain in cache before expiring if they are not
  used. This defaults to 30 days, and the value is expressed in days.
  Set to `0` to immediately expire all the cache's content.

When troubleshooting load performance, it is possible to obtain timing
data for some critical parts of the library load process within the jsii
kernel by setting `JSII_DEBUG_TIMING` environment variable.

Related to #3389
@RomainMuller RomainMuller requested a review from a team August 26, 2022 16:03
@RomainMuller RomainMuller self-assigned this Aug 26, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 26, 2022
@Naumel
Copy link

Naumel commented Aug 30, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

update

✅ Branch has been successfully updated

RomainMuller and others added 3 commits August 30, 2022 12:49
A missing condition in the code generator could have resulted
in attempting to read a property on undefined, resulting in
a crash.
A missing condition in the code generator could have resulted
in attempting to read a property on undefined, resulting in
a crash.
@RomainMuller
Copy link
Contributor Author

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

update

❌ Base branch update has failed

merge conflict between base and head
err-code: 4CC50

@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Aug 30, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

Merging (with squash)...

@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

Merging (with squash)...

@mergify mergify bot merged commit 4c2dcd5 into main Aug 30, 2022
@mergify mergify bot deleted the rmuller/runtime-timing branch August 30, 2022 15:11
@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2022

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Aug 30, 2022
RomainMuller added a commit that referenced this pull request Sep 26, 2022
Windows does not allow renaming files that are currently open, or
directories that contain open files. When antivirus software is used,
files are open for analysis by the A/V software, making it impossible to
rename files too quickly after they've been created.

This was already reported in #992 and addressed, however the issue was
re-introduced in #3724, in which tarballs were extracted into temporary
directories that were then renamed.

Changed the code back to a form taht extracts files directly into their
final place instead of staging via a temporary space, and added comments
warning maintainers about the specific issue being solved here, so that
hopefully the problem does not get re-introduced again in the future.

Fixes #3751
mergify bot pushed a commit that referenced this pull request Sep 26, 2022
Windows does not allow renaming files that are currently open, or directories that contain open files. When antivirus software is used, files are open for analysis by the A/V software, making it impossible to rename files too quickly after they've been created.

This was already reported in #992 and addressed, however the issue was re-introduced in #3724, in which tarballs were extracted into temporary directories that were then renamed.

Changed the code back to a form taht extracts files directly into their final place instead of staging via a temporary space, and added comments warning maintainers about the specific issue being solved here, so that hopefully the problem does not get re-introduced again in the future.

Fixes #3751



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants