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

Upgrade JDK toolchain/target version to 17 and add GraalJS #1207

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

gregschohn
Copy link
Collaborator

@gregschohn gregschohn commented Dec 20, 2024

Upgrade JDK toolchain and target version for most packages to 17 to get GraalJS+LiquidJS working via a transformer. After noticing extremely dissappointing results for liquid templated transforms (see below), I reworked the type mappings sanitization transform in pure javascript code. The results for recording 10K bulk request transformations went from

Old jinja transform

[INFO ] 2024-12-22 02:37:04,761762 [main] TypeMappingsSanitizationTransformerBulkTest - Total time=PT14.153184457S over 10000 runs

New javascript based transformation

[INFO ] 2024-12-22 02:42:58,180275 [main] TypeMappingsSanitizationTransformerBulkTest - Total time=PT0.904187796S over 10000 runs

That's a 14x improvement over the jinja code. Considering that we noticed that RFS performance went down by 20x, that would imply that 95% of the time was spent on transforms. Making that 14x faster could imply a ~10x performance increase (or only 2x worse than what it was without transformations). Notice that there's a lot less serialization back and forth with the javascript transform than with the template approach, but the code's also pretty sub-optimal, possibly like what I would expect to come in from a contributor - at least if they didn't have much experience with javascript.

There are two commits in this PR. The first one implements the TypeMappinsSanitization as an incomplete liquid transform. I stopped developing that because a rough test showed a huge performance difference between Liquid.js and a raw javascript call. The results on my mac were about 300x slower to use the templating solution than to just run JSON.stringify() (likely much worse than jinjava).

Below are some logs showing those differences for the liquid transforms.

/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI ...
org.opensearch.migrations.transform.LiquidJsTransformerTest
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[INFO ] 2024-12-20 04:11:56,654825 [main] LiquidJsTransformerTest - Run 0: PT4.052694709S
[INFO ] 2024-12-20 04:11:59,694596 [main] LiquidJsTransformerTest - Run 1: PT3.039395S
[INFO ] 2024-12-20 04:12:02,747087 [main] LiquidJsTransformerTest - Run 2: PT3.052563917S
[INFO ] 2024-12-20 04:12:05,823644 [main] LiquidJsTransformerTest - Run 3: PT3.076653792S
[INFO ] 2024-12-20 04:12:08,833241 [main] LiquidJsTransformerTest - Run 4: PT3.009687375S
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[INFO ] 2024-12-20 04:12:08,906295 [main] LiquidJsTransformerTest - Run 0: PT0.021998S
[INFO ] 2024-12-20 04:12:08,916581 [main] LiquidJsTransformerTest - Run 1: PT0.010198S
[INFO ] 2024-12-20 04:12:08,927812 [main] LiquidJsTransformerTest - Run 2: PT0.011137708S
[INFO ] 2024-12-20 04:12:08,938391 [main] LiquidJsTransformerTest - Run 3: PT0.010506958S
[INFO ] 2024-12-20 04:12:08,948759 [main] LiquidJsTransformerTest - Run 4: PT0.010288125S
[INFO ] 2024-12-20 04:12:08,959167 [main] LiquidJsTransformerTest - Run 5: PT0.010324625S

Description

Issues Resolved

Testing

Check List

  • New functionality includes testing
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…et GraalJS+LiquidJS working via a transformer.

There's a rough test in place that shows the relative performance between Liquid.js and a raw javascript call.  The results on my mac were about 300x slower to use the templating solution than to just run JSON.stringify().

/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI ...
org.opensearch.migrations.transform.LiquidJsTransformerTest
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[INFO ] 2024-12-20 04:11:56,654825 [main] LiquidJsTransformerTest - Run 0: PT4.052694709S
[INFO ] 2024-12-20 04:11:59,694596 [main] LiquidJsTransformerTest - Run 1: PT3.039395S
[INFO ] 2024-12-20 04:12:02,747087 [main] LiquidJsTransformerTest - Run 2: PT3.052563917S
[INFO ] 2024-12-20 04:12:05,823644 [main] LiquidJsTransformerTest - Run 3: PT3.076653792S
[INFO ] 2024-12-20 04:12:08,833241 [main] LiquidJsTransformerTest - Run 4: PT3.009687375S
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: Libgraal compilation is not available on this JVM. Alternatively, the org.graalvm.compiler:compiler module can be put on the --upgrade-module-path.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
[INFO ] 2024-12-20 04:12:08,906295 [main] LiquidJsTransformerTest - Run 0: PT0.021998S
[INFO ] 2024-12-20 04:12:08,916581 [main] LiquidJsTransformerTest - Run 1: PT0.010198S
[INFO ] 2024-12-20 04:12:08,927812 [main] LiquidJsTransformerTest - Run 2: PT0.011137708S
[INFO ] 2024-12-20 04:12:08,938391 [main] LiquidJsTransformerTest - Run 3: PT0.010506958S
[INFO ] 2024-12-20 04:12:08,948759 [main] LiquidJsTransformerTest - Run 4: PT0.010288125S
[INFO ] 2024-12-20 04:12:08,959167 [main] LiquidJsTransformerTest - Run 5: PT0.010324625S

Signed-off-by: Greg Schohn <[email protected]>
…transform invocation scripts and rewrite the type mappings sanitization transformer to be pure javascript as opposed to liquid (or jinja).

I've tweaked a bulk request test time the accumulated time for 10K warm runs and the average time to transform is around 0.2ms (without '-ea'), which is a major improvement over liquid/jinja scripts.

Signed-off-by: Greg Schohn <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
@AndreKurait AndreKurait force-pushed the liquidJsTransforms branch 2 times, most recently from 80b975c to 789e459 Compare January 10, 2025 05:20
… Graalvm compatibility

-s
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
Copy link
Collaborator Author

@gregschohn gregschohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work moving this along Andre. Thanks! I'll keep an eye out for future changes.

Comment on lines 94 to 95
The tools in this directory can only be built if you have Java version 17
installed.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true, right? Gradle download 17 if it wasn't present - so you really just need whatever the minimum version of java is to run ../../gradlew

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified this is the case and updated. We need Java 8-17 (until bumping gradle up to 8.4 when we'll gain 21 support)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed more verification and found that spotless fails for Java 17 language usage when the host is Java 11. Junit and build downloads and runs as expected when the host is java 8 or 11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed spotless temporarily, will address root cause with https://opensearch.atlassian.net/browse/MIGRATIONS-2344

build.gradle Outdated Show resolved Hide resolved
build.gradle Show resolved Hide resolved
Comment on lines -73 to -75
" \"type\" : {\n" +
" \"type\" : \"keyword\"\n" +
" },\n" +
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this no longer expected? Shouldn't we be adding this (or have an option to)? I've seen this conversion in a number of examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't fully implemented. I'd want this as a feature that would also update the documents as well that could be disabled. This can be an extension in the future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" }\n" +
" }\n" +
"}";
var rewriter = new TypeMappingsSanitizationTransformer(null, null);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what source version do we default to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing defined. This would be expected to work if you were migrating from 2.x -> 2.x

Copy link
Member

@AndreKurait AndreKurait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait to merge this until we get license approval for GraalJS UPL License

…tings, and proper thread safe support for IJsonTransformers

Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
@AndreKurait AndreKurait dismissed their stale review January 15, 2025 21:18

License approval granted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants