-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Upgrade JDK toolchain/target version to 17 and add GraalJS #1207
Conversation
…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]>
.../jsonLiquidJSTransformer/src/main/java/org/opensearch/migrations/transform/ScriptRunner.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andre Kurait <[email protected]>
…ontract Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
...tionPlugins/jsonMessageTransformers/jsonLiquidJSTransformer/src/main/resources/liquid.min.js
Outdated
Show resolved
Hide resolved
...Transformer/src/test/java/org/opensearch/migrations/transform/JavascriptTransformerTest.java
Outdated
Show resolved
Hide resolved
...rmers/jsonTypeMappingsSanitizationTransformer/src/main/resources/js/typeMappingsSanitizer.js
Outdated
Show resolved
Hide resolved
...st/java/org/opensearch/migrations/transform/TypeMappingsSanitizationTransformerBulkTest.java
Show resolved
Hide resolved
Signed-off-by: Andre Kurait <[email protected]>
… JsonJSTransformerProvider Signed-off-by: Andre Kurait <[email protected]>
b6285b3
to
b65d7c5
Compare
Signed-off-by: Andre Kurait <[email protected]>
80b975c
to
789e459
Compare
… Graalvm compatibility -s Signed-off-by: Andre Kurait <[email protected]>
789e459
to
738cf2b
Compare
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
9f2f8b6
to
ae06216
Compare
Signed-off-by: Andre Kurait <[email protected]>
681daa0
to
4515ed3
Compare
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
There was a problem hiding this 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.
...st/java/org/opensearch/migrations/transform/TypeMappingsSanitizationTransformerBulkTest.java
Show resolved
Hide resolved
The tools in this directory can only be built if you have Java version 17 | ||
installed. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
" \"type\" : {\n" + | ||
" \"type\" : \"keyword\"\n" + | ||
" },\n" + |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be addressed with https://opensearch.atlassian.net/browse/MIGRATIONS-2267
" }\n" + | ||
" }\n" + | ||
"}"; | ||
var rewriter = new TypeMappingsSanitizationTransformer(null, null); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
...Plugins/jsonMessageTransformers/jsonTypeMappingsSanitizationTransformerProvider/build.gradle
Outdated
Show resolved
Hide resolved
...der/src/test/java/org/opensearch/migrations/replay/TypeMappingsSanitizationProviderTest.java
Outdated
Show resolved
Hide resolved
...der/src/test/java/org/opensearch/migrations/replay/TypeMappingsSanitizationProviderTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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]>
Signed-off-by: Andre Kurait <[email protected]>
Signed-off-by: Andre Kurait <[email protected]>
14e856d
to
5b6fc2a
Compare
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
New javascript based transformation
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.
Description
Issues Resolved
Testing
Check List
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.