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

Replace ByteBuddy with Java Proxy #1904

Merged

Conversation

AyushChaubey
Copy link
Contributor

@AyushChaubey AyushChaubey commented May 6, 2024

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Changes in this PR

Please find the details related to this PR in this discussion

Describe the new behavior from this PR, and why it's needed
ByteBuddy seems to be causing issue when the native image is run. One of the solution to overcome this issue is to use Java Proxy.

Note:
I ran some performance tests from my side on a service. It would be nice if you also have some performance tests that covers this flow.

Instructions on creating a native image:
For a library to support GraalVM, it needs to provide the reachability metadata. GraalVM needs to know about the dynamically-accessed elements(Reflection/Resource loading etc.) at the time of build. This information is provided by the libraries in the form of json files.

There is this repository, where community contributes this metadata information for different libraries. One example is these metadata json files for graphql-java. You will find files like reflect-config.json, resource-config.json and others.

There is a way to generate these metadata files which is using the GraalVM tracing agent. So what we do is, we run the tests in our service that uses DGS using gradle test task and provide the tracing agent parameter with the path where it should generate these metadata json files.

tasks.withType<Test> {
        jvmArgs("-agentlib:native-image-agent=config-output-dir=./src/main/resources/META-INF/native-image")
}

By doing this, those metadata json files are generated at this path src/main/resources/META-INF/native-image. Next when we build the native image, it uses that information and creates a native image that works perfectly.
Luckily, other than DGS micrometer, we didn't face any issue with the native image in terms of the implementation in DGS.

We are using Spring Boot, which works with GraalVM to generate the metadata information but DGS would also need to provide this information to reduce the complete dependency on the tracing agent. I guess we would still need to use the tracing agent to cover all the cases which also means writing tests that cover all the scenarios.

@AyushChaubey AyushChaubey changed the title replace byte buddy with java proxy Replace ByteBuddy with Java Proxy May 6, 2024
@AyushChaubey AyushChaubey marked this pull request as ready for review May 6, 2024 18:59
@paulbakker
Copy link
Collaborator

Sorry for the slow reply @AyushChaubey, I was traveling and completely missed the PR.

This looks great! I've tested it and it seems to work fine. I also pushed some more changes to your branch, because I realized that we don't need a separate handler now for each type of dataloader, since it's using reflection now.

import java.util.concurrent.CompletionStage

internal class BatchLoaderWithContextInterceptor(
private val batchLoader: BatchLoaderWithContext<*, *>,
private val batchLoaderWithContext: Any,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because it's now using reflection the specific interface doesn't actually matter anymore, and we can get away with a single InvocationHandler interceptor that handles all four types of batch loaders.

@@ -1,7 +1,6 @@
dependencies {
api(project(":graphql-dgs"))

implementation("net.bytebuddy:byte-buddy")
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

@paulbakker paulbakker self-requested a review May 17, 2024 20:51
Copy link
Collaborator

@paulbakker paulbakker left a comment

Choose a reason for hiding this comment

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

@AyushChaubey can you double check that you're ok with the changes I made to your branch?

@AyushChaubey
Copy link
Contributor Author

Sorry for the slow reply @AyushChaubey, I was traveling and completely missed the PR.

This looks great! I've tested it and it seems to work fine. I also pushed some more changes to your branch, because I realized that we don't need a separate handler now for each type of dataloader, since it's using reflection now.

No problem @paulbakker. Thanks for looking into the PR. It makes sense, we don't need separate handler for different types of dataloaders. Thanks for pushing the changes.

@AyushChaubey
Copy link
Contributor Author

@AyushChaubey can you double check that you're ok with the changes I made to your branch?

Changes look good @paulbakker. Appreciate your help with this. Thanks 🙇‍♂️.

@paulbakker
Copy link
Collaborator

@AyushChaubey, this is just a heads-up that we got a bit distracted by some urgent issues that needed attention. We were planning to do a bit more testing before releasing this since it's a pretty small but important change.

Will be merged and released soon, sorry for the delay.

@paulbakker paulbakker requested a review from kilink May 24, 2024 00:44
@paulbakker paulbakker merged commit ed9ab48 into Netflix:master May 24, 2024
3 checks passed
@AyushChaubey
Copy link
Contributor Author

@AyushChaubey, this is just a heads-up that we got a bit distracted by some urgent issues that needed attention. We were planning to do a bit more testing before releasing this since it's a pretty small but important change.

Will be merged and released soon, sorry for the delay.

No problem at all @paulbakker. Thanks for the update :). I see the PR is merged. Appreciate your time and effort for taking it through.

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.

None yet

3 participants