Skip to content

adding Profiler #3976

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

adding Profiler #3976

wants to merge 30 commits into from

Conversation

andimarek
Copy link
Member

While we recently added a Java agent to profile a GraphQL Java application the following things became clear:

Java agents are not the future of the JVM: soon a dynamic loading will be forbidden. See https://openjdk.org/jeps/451
We added the ability to track the engine running state
We added the ability to chain DataLoaders, which as a side effect allow for tracking which dataloaders are used by which field / DataFetcher
Together this means Java agents are not really future proof + they are not needed anymore, as we have all the abilities now inside GraphQL Java directly itself.

The goal is to remove the Java agent eventually and offer a better alternative in form of this PRs: a built-in Profiler in GraphQL Java.

A Profiler is enabled per execution (request) and will collect with very minimal overhead all relevant informations to understand the performance and execution. The result will be made available via GraphQLContext.

Copy link
Contributor

github-actions bot commented May 19, 2025

Test Results

  324 files    324 suites   4m 16s ⏱️
5 004 tests 4 989 ✅ 15 💤 0 ❌
5 093 runs  5 078 ✅ 15 💤 0 ❌

Results for commit 572090e.

♻️ This comment has been updated with latest results.


}


Choose a reason for hiding this comment

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

extra line - intentional?

andimarek added 8 commits July 1, 2025 06:52
# Conflicts:
#	src/main/java/graphql/execution/instrumentation/dataloader/PerLevelDataLoaderDispatchStrategy.java
#	src/main/java/graphql/schema/DataFetchingEnvironmentImpl.java
# Conflicts:
#	src/main/java/graphql/EngineRunningState.java
#	src/main/java/graphql/ExecutionInput.java
#	src/main/java/graphql/GraphQL.java
#	src/main/java/graphql/execution/ExecutionContext.java
#	src/test/groovy/graphql/execution/AsyncExecutionStrategyTest.groovy
#	src/test/groovy/graphql/execution/AsyncSerialExecutionStrategyTest.groovy
#	src/test/groovy/graphql/execution/ExecutionStrategyTest.groovy
#	src/test/groovy/graphql/execution/instrumentation/fieldvalidation/FieldValidationTest.groovy
public Builder profileExecution(boolean profileExecution) {
this.profileExecution = profileExecution;
return this;
}
Copy link
Member

Choose a reason for hiding this comment

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

For another PR, not this one

Can you add the toggle to GraphQLUnusualConfiguration instead?

Copy link
Member

Choose a reason for hiding this comment

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

To be discussed!


@Override
public void chainedStrategyDispatching(int level) {
profilerResult.chainedStrategyDispatching(level);
Copy link
Member

Choose a reason for hiding this comment

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

To make it more obvious to a user, can comment on this method (or interface method) to indicate that this refers to the option DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING

I think to us, we know what Chained DataLoaders are but this is not a well known phrase

I'll also make a note to mention in the documentation, this is a way to measure the impact of Chained DataLoaders


@Internal
@NullMarked
public interface Profiler {
Copy link
Member

Choose a reason for hiding this comment

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

Add a quick JavaDoc explaining what this does

A Profiler monitors important execution timings and counters. Enable this via ExecutionInput/new Unusual Configuration method

Of course 1 sentence isn't enough, let's add a documentation link here when it's written

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an internal class btw

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;

Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but in the future, with more Profiler features you might want to introduce options to toggle sets of tracking on and off

e.g. toggle DataLoader related tracking on and off


}

default <V> void manualDispatch(String dataLoaderName, int level, int count) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice

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.

3 participants