FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add ENF performance tests · Talank/graphql-java_graphql-java@c2d1a3b · GitHub

Commit c2d1a3b

Browse files
committed
add ENF performance tests
1 parent 0478956 commit c2d1a3b

5 files changed

Lines changed: 328 additions & 0 deletions

File tree

‎src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ private void buildEnfsRecursively(@Nullable ExecutableNormalizedField executable
532532
if (fieldAndAstParent.field.getSelectionSet() == null) {
533533
continue;
534534
}
535+
// the AST parent comes from the previous collect from selection set call
536+
// and is the type to which the field belongs (the container type of the field) and output type
537+
// of the field needs to be determined based on the field name
535538
GraphQLFieldDefinition fieldDefinition = Introspection.getFieldDef(graphQLSchema, fieldAndAstParent.astParentType, fieldAndAstParent.field.getName());
536539
GraphQLUnmodifiedType selectionSetType = unwrapAll(fieldDefinition.getType());
537540
this.collectFromSelectionSet(fieldAndAstParent.field.getSelectionSet(),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package performance;
2+
3+
import graphql.execution.CoercedVariables;
4+
import graphql.language.Document;
5+
import graphql.normalized.ExecutableNormalizedOperation;
6+
import graphql.normalized.ExecutableNormalizedOperationFactory;
7+
import graphql.parser.Parser;
8+
import graphql.schema.GraphQLSchema;
9+
import graphql.schema.idl.SchemaGenerator;
10+
import org.openjdk.jmh.annotations.Benchmark;
11+
import org.openjdk.jmh.annotations.BenchmarkMode;
12+
import org.openjdk.jmh.annotations.Fork;
13+
import org.openjdk.jmh.annotations.Measurement;
14+
import org.openjdk.jmh.annotations.Mode;
15+
import org.openjdk.jmh.annotations.OutputTimeUnit;
16+
import org.openjdk.jmh.annotations.Scope;
17+
import org.openjdk.jmh.annotations.Setup;
18+
import org.openjdk.jmh.annotations.State;
19+
import org.openjdk.jmh.annotations.Warmup;
20+
import org.openjdk.jmh.infra.Blackhole;
21+
22+
import java.util.concurrent.TimeUnit;
23+
24+
@State(Scope.Benchmark)
25+
@Warmup(iterations = 2, time = 5)
26+
@Measurement(iterations = 3)
27+
@Fork(3)
28+
public class ENF1Performance {
29+
30+
@State(Scope.Benchmark)
31+
public static class MyState {
32+
33+
GraphQLSchema schema;
34+
Document document;
35+
36+
@Setup
37+
public void setup() {
38+
try {
39+
String schemaString = PerformanceTestingUtils.loadResource("large-schema-1.graphqls");
40+
schema = SchemaGenerator.createdMockedSchema(schemaString);
41+
42+
String query = PerformanceTestingUtils.loadResource("large-schema-1-query.graphql");
43+
document = Parser.parse(query);
44+
} catch (Exception e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}
49+
50+
@Benchmark
51+
@BenchmarkMode(Mode.AverageTime)
52+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
53+
public void benchMarkAvgTime(MyState myState, Blackhole blackhole) {
54+
runImpl(myState, blackhole);
55+
}
56+
57+
@Benchmark
58+
@BenchmarkMode(Mode.Throughput)
59+
@OutputTimeUnit(TimeUnit.SECONDS)
60+
public void benchMarkThroughput(MyState myState, Blackhole blackhole) {
61+
runImpl(myState, blackhole);
62+
}
63+
64+
private void runImpl(MyState myState, Blackhole blackhole) {
65+
ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables());
66+
blackhole.consume(executableNormalizedOperation);
67+
}
68+
69+
70+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package performance;
2+
3+
import graphql.execution.CoercedVariables;
4+
import graphql.language.Document;
5+
import graphql.normalized.ExecutableNormalizedOperation;
6+
import graphql.normalized.ExecutableNormalizedOperationFactory;
7+
import graphql.parser.Parser;
8+
import graphql.schema.GraphQLSchema;
9+
import graphql.schema.idl.SchemaGenerator;
10+
import org.openjdk.jmh.annotations.Benchmark;
11+
import org.openjdk.jmh.annotations.BenchmarkMode;
12+
import org.openjdk.jmh.annotations.Fork;
13+
import org.openjdk.jmh.annotations.Measurement;
14+
import org.openjdk.jmh.annotations.Mode;
15+
import org.openjdk.jmh.annotations.OutputTimeUnit;
16+
import org.openjdk.jmh.annotations.Scope;
17+
import org.openjdk.jmh.annotations.Setup;
18+
import org.openjdk.jmh.annotations.State;
19+
import org.openjdk.jmh.annotations.Warmup;
20+
21+
import java.util.concurrent.TimeUnit;
22+
23+
@State(Scope.Benchmark)
24+
@Warmup(iterations = 2, time = 5)
25+
@Measurement(iterations = 3)
26+
@Fork(3)
27+
public class ENF2Performance {
28+
29+
@State(Scope.Benchmark)
30+
public static class MyState {
31+
32+
GraphQLSchema schema;
33+
Document document;
34+
35+
@Setup
36+
public void setup() {
37+
try {
38+
String schemaString = PerformanceTestingUtils.loadResource("large-schema-2.graphqls");
39+
schema = SchemaGenerator.createdMockedSchema(schemaString);
40+
41+
String query = PerformanceTestingUtils.loadResource("large-schema-2-query.graphql");
42+
document = Parser.parse(query);
43+
} catch (Exception e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
48+
}
49+
50+
@Benchmark
51+
@BenchmarkMode(Mode.AverageTime)
52+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
53+
public ExecutableNormalizedOperation benchMarkAvgTime(MyState myState) {
54+
ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables());
55+
// System.out.println("fields size:" + normalizedQuery.getFieldToNormalizedField().size());
56+
return executableNormalizedOperation;
57+
}
58+
59+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package performance;
2+
3+
import benchmark.BenchmarkUtils;
4+
import graphql.execution.CoercedVariables;
5+
import graphql.language.Document;
6+
import graphql.normalized.ExecutableNormalizedOperation;
7+
import graphql.normalized.ExecutableNormalizedOperationFactory;
8+
import graphql.parser.Parser;
9+
import graphql.schema.GraphQLSchema;
10+
import graphql.schema.idl.SchemaGenerator;
11+
import org.openjdk.jmh.annotations.Benchmark;
12+
import org.openjdk.jmh.annotations.BenchmarkMode;
13+
import org.openjdk.jmh.annotations.Fork;
14+
import org.openjdk.jmh.annotations.Level;
15+
import org.openjdk.jmh.annotations.Measurement;
16+
import org.openjdk.jmh.annotations.Mode;
17+
import org.openjdk.jmh.annotations.OutputTimeUnit;
18+
import org.openjdk.jmh.annotations.Param;
19+
import org.openjdk.jmh.annotations.Scope;
20+
import org.openjdk.jmh.annotations.Setup;
21+
import org.openjdk.jmh.annotations.State;
22+
import org.openjdk.jmh.annotations.Warmup;
23+
import org.openjdk.jmh.runner.Runner;
24+
import org.openjdk.jmh.runner.RunnerException;
25+
import org.openjdk.jmh.runner.options.Options;
26+
import org.openjdk.jmh.runner.options.OptionsBuilder;
27+
28+
import java.util.concurrent.TimeUnit;
29+
30+
import static graphql.normalized.ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation;
31+
32+
@State(Scope.Benchmark)
33+
@Warmup(iterations = 2, time = 5)
34+
@Measurement(iterations = 3, time = 5)
35+
@Fork(2)
36+
public class ENFDeepIntrospectionPerformance {
37+
38+
@Param({"2", "10", "20"})
39+
int howDeep = 2;
40+
41+
String query = "";
42+
43+
GraphQLSchema schema;
44+
Document document;
45+
46+
@Setup(Level.Trial)
47+
public void setUp() {
48+
String schemaString = PerformanceTestingUtils.loadResource("large-schema-2.graphqls");
49+
schema = SchemaGenerator.createdMockedSchema(schemaString);
50+
51+
query = createDeepQuery(howDeep);
52+
document = Parser.parse(query);
53+
}
54+
55+
@Benchmark
56+
@BenchmarkMode(Mode.AverageTime)
57+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
58+
public ExecutableNormalizedOperation benchMarkAvgTime() {
59+
ExecutableNormalizedOperationFactory.Options options = ExecutableNormalizedOperationFactory.Options.defaultOptions();
60+
ExecutableNormalizedOperation executableNormalizedOperation = createExecutableNormalizedOperation(schema,
61+
document,
62+
null,
63+
CoercedVariables.emptyVariables(),
64+
options);
65+
return executableNormalizedOperation;
66+
}
67+
68+
public static void main(String[] args) throws RunnerException {
69+
runAtStartup();
70+
71+
Options opt = new OptionsBuilder()
72+
.include("benchmark.ENFBenchmarkDeepIntrospection")
73+
.build();
74+
75+
new Runner(opt).run();
76+
}
77+
78+
private static void runAtStartup() {
79+
80+
ENFDeepIntrospectionPerformance benchmarkIntrospection = new ENFDeepIntrospectionPerformance();
81+
benchmarkIntrospection.howDeep = 2;
82+
83+
BenchmarkUtils.runInToolingForSomeTimeThenExit(
84+
benchmarkIntrospection::setUp,
85+
() -> {
86+
while (true) {
87+
benchmarkIntrospection.benchMarkAvgTime();
88+
}
89+
},
90+
() -> {
91+
}
92+
);
93+
}
94+
95+
96+
private static String createDeepQuery(int depth) {
97+
String result = "query test {\n" +
98+
" __schema {\n" +
99+
" types {\n" +
100+
" ...F1\n" +
101+
" }\n" +
102+
" }\n" +
103+
"}\n";
104+
105+
for (int i = 1; i < depth; i++) {
106+
result += " fragment F" + i + " on __Type {\n" +
107+
" fields {\n" +
108+
" type {\n" +
109+
" ...F" + (i + 1) + "\n" +
110+
" }\n" +
111+
" }\n" +
112+
"\n" +
113+
" ofType {\n" +
114+
" ...F" + (i + 1) + "\n" +
115+
" }\n" +
116+
" }\n";
117+
}
118+
result += " fragment F" + depth + " on __Type {\n" +
119+
" fields {\n" +
120+
" type {\n" +
121+
"name\n" +
122+
" }\n" +
123+
" }\n" +
124+
"}\n";
125+
return result;
126+
}
127+
128+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package performance;
2+
3+
import graphql.execution.CoercedVariables;
4+
import graphql.language.Document;
5+
import graphql.normalized.ExecutableNormalizedOperation;
6+
import graphql.normalized.ExecutableNormalizedOperationFactory;
7+
import graphql.parser.Parser;
8+
import graphql.schema.GraphQLSchema;
9+
import graphql.schema.idl.SchemaGenerator;
10+
import org.openjdk.jmh.annotations.Benchmark;
11+
import org.openjdk.jmh.annotations.BenchmarkMode;
12+
import org.openjdk.jmh.annotations.Fork;
13+
import org.openjdk.jmh.annotations.Measurement;
14+
import org.openjdk.jmh.annotations.Mode;
15+
import org.openjdk.jmh.annotations.OutputTimeUnit;
16+
import org.openjdk.jmh.annotations.Scope;
17+
import org.openjdk.jmh.annotations.Setup;
18+
import org.openjdk.jmh.annotations.State;
19+
import org.openjdk.jmh.annotations.Warmup;
20+
import org.openjdk.jmh.infra.Blackhole;
21+
22+
import java.util.concurrent.TimeUnit;
23+
24+
@State(Scope.Benchmark)
25+
@Warmup(iterations = 2, time = 5)
26+
@Measurement(iterations = 3)
27+
@Fork(3)
28+
public class ENFExtraLargePerformance {
29+
30+
@State(Scope.Benchmark)
31+
public static class MyState {
32+
33+
GraphQLSchema schema;
34+
Document document;
35+
36+
@Setup
37+
public void setup() {
38+
try {
39+
String schemaString = PerformanceTestingUtils.loadResource("extra-large-schema-1.graphqls");
40+
schema = SchemaGenerator.createdMockedSchema(schemaString);
41+
42+
String query = PerformanceTestingUtils.loadResource("extra-large-schema-1-query.graphql");
43+
document = Parser.parse(query);
44+
} catch (Exception e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}
49+
50+
@Benchmark
51+
@BenchmarkMode(Mode.AverageTime)
52+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
53+
public void benchMarkAvgTime(MyState myState, Blackhole blackhole) {
54+
runImpl(myState, blackhole);
55+
}
56+
57+
@Benchmark
58+
@BenchmarkMode(Mode.Throughput)
59+
@OutputTimeUnit(TimeUnit.SECONDS)
60+
public void benchMarkThroughput(MyState myState, Blackhole blackhole) {
61+
runImpl(myState, blackhole);
62+
}
63+
64+
private void runImpl(MyState myState, Blackhole blackhole) {
65+
ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables());
66+
blackhole.consume(executableNormalizedOperation);
67+
}
68+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL