4949@ Fork (1 )
5050public class ComplexQueryBenchmark {
5151
52- @ Param ({"5" , "10" , "20" })
53- int howManyThreads = 5 ;
54- @ Param ({"10" , "50" , "100" })
55- int howManyQueries = 10 ;
5652 @ Param ({"5" , "20" , "100" })
5753 int howManyItems = 5 ;
58- @ Param ({"1" , "5" , "10" })
59- int howLongToSleep = 1 ;
54+ int howLongToSleep = 5 ;
55+ int howManyQueries = 50 ;
56+ int howManyQueryThreads = 10 ;
57+ int howManyFetcherThreads = 10 ;
6058
61- ExecutorService executorService ;
59+ ExecutorService queryExecutorService ;
60+ ExecutorService fetchersExecutorService ;
6261 GraphQL graphQL ;
6362 volatile boolean shutDown ;
6463
6564 @ Setup (Level .Trial )
6665 public void setUp () {
6766 shutDown = false ;
68- executorService = Executors .newFixedThreadPool (howManyThreads );
67+ queryExecutorService = Executors .newFixedThreadPool (howManyQueryThreads );
68+ fetchersExecutorService = Executors .newFixedThreadPool (howManyFetcherThreads );
6969 graphQL = buildGraphQL ();
7070 }
7171
7272 @ TearDown (Level .Trial )
7373 public void tearDown () {
7474 shutDown = true ;
75- executorService .shutdownNow ();
75+ queryExecutorService .shutdownNow ();
76+ fetchersExecutorService .shutdownNow ();
7677 }
7778
7879
@@ -106,6 +107,7 @@ private static void runAtStartup() {
106107 ComplexQueryBenchmark complexQueryBenchmark = new ComplexQueryBenchmark ();
107108 complexQueryBenchmark .setUp ();
108109 do {
110+ System .out .print ("Running queries....\n " );
109111 complexQueryBenchmark .runManyQueriesToCompletion ();
110112 } while (forever );
111113 complexQueryBenchmark .tearDown ();
@@ -118,7 +120,7 @@ private static void runAtStartup() {
118120 private Void runManyQueriesToCompletion () {
119121 CompletableFuture <?>[] cfs = new CompletableFuture [howManyQueries ];
120122 for (int i = 0 ; i < howManyQueries ; i ++) {
121- cfs [i ] = CompletableFuture .supplyAsync (() -> executeQuery (howManyItems , howLongToSleep ), executorService );
123+ cfs [i ] = CompletableFuture .supplyAsync (() -> executeQuery (howManyItems , howLongToSleep ), queryExecutorService );
122124 }
123125 Void result = CompletableFuture .allOf (cfs ).join ();
124126 return result ;
@@ -166,7 +168,7 @@ private GraphQL buildGraphQL() {
166168
167169 private <T > CompletableFuture <T > supplyAsync (Supplier <T > codeToRun ) {
168170 if (!shutDown ) {
169- return CompletableFuture .supplyAsync (codeToRun );
171+ return CompletableFuture .supplyAsync (codeToRun , fetchersExecutorService );
170172 } else {
171173 // if we have shutdown - get on with it, so we shut down quicker
172174 return CompletableFuture .completedFuture (codeToRun .get ());
0 commit comments