Skip to content

Commit 50d485b

Browse files
committed
thread work
1 parent 1e1ad52 commit 50d485b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

content/blog/threads.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ date = 2021-02-05T00:00:00+10:00
1010

1111
We follow a fundamental rule in GraphQL Java regarding Threads: GraphQL Java never creates
1212
Threads or interacts with Thread pools. We do this because we want to give the user the full control
13-
and whatever GraphQL Java would do it would not be correct in general.
13+
and whatever GraphQL Java would do, it would not be correct for every use case.
1414

15-
Additionally to being strictly unopinionated regarding Threads GraphQL Java is also fully reactive,
15+
Additionally to being strictly unopinionated regarding Threads, GraphQL Java is also fully reactive,
1616
implemented via `CompletableFuture` (`CF`).
1717
These two constrain together mean we rely on the `CF` returned by the user.
1818
Specifically we piggyback on the `CF` returned by the `DataFetcher`
@@ -34,7 +34,7 @@ as it is by far the most important).
3434

3535
# Blocking DataFetcher
3636

37-
Lets assume your accessing a DB in blocking way in your `DataFetcher`:
37+
Lets assume you are accessing a DB in a blocking way in your `DataFetcher`:
3838

3939
{{< highlight Java "linenos=table" >}}
4040
String get(DataFetchingEnvironment env) {
@@ -61,7 +61,7 @@ If the `DataFetcher` for these `dbData` fields don't return a `CF`,
6161
but block the Thread until the data is read, GraphQL Java will not work with maximum efficiency.
6262

6363
GraphQL Java can invoke the `DataFetcher` for all three fields in parallel. But if your `DataFetcher` for
64-
`dbData1` is blocking GraphQL Java will also be blocked and only invoke the next `DataFetcher` once `dbData1`
64+
`dbData1` is blocking, GraphQL Java will also be blocked and only invoke the next `DataFetcher` once `dbData<n>`
6565
is finished.
6666
The recommend solution to this problem is offloading your blocking code onto a separate Thread pool
6767
as shown here:
@@ -119,12 +119,12 @@ Because the code is non blocking there is no need to offload anything on a dedic
119119
GraphQL Java.
120120

121121
You still might want to consider using a dedicated GraphQL Java pool as you otherwise would use
122-
threads which are dedicated to IO. How much this is really relevant depends highly on your use case.
122+
Threads which are dedicated to IO. How much this is really relevant depends highly on your use case.
123123

124-
For example `Async Http Client` (`AHC`) uses by default 2 * #cores (this value comes actually from Netty) threads. If you
125-
don't use a dedicated Thread Pool for GraphQL Java work you might encounter situations under load where all `AHC`
126-
threads are either busy or blocked by GraphQL Java code and as a result your system is not as performant as it
127-
could be.
124+
For example `Async Http Client` (`AHC`) uses by default 2 * #cores (this value comes actually from Netty) Threads. If you
125+
don't use a dedicated Thread Pool for GraphQL Java you might encounter situations under load where all `AHC`
126+
Threads are either busy or blocked by GraphQL Java code and as a result your system is not as performant as it
127+
could be. Normally only load tests in production like environments can show the relevance of different Thread pools.
128128

129129

130130
# Feedback or questions

0 commit comments

Comments
 (0)