https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
l

Lenny

05/21/2020, 9:28 PM
i just converted a graphql-java service to kotlin, then rewrote it to use graphql-kotlin. i ran load tests before and after. the final version has a significant performance regression … average latency rose from 200-ish ms to over 1000ms. this is using 3.0.0-rc5. i’ll dig in more but if anyone has guidance on where to look i could use the help!
s

Shane Myrick

05/21/2020, 9:33 PM
What operations are you running to test performance? Query, Mutation, Subscription? Are you using coroutines or any async wrapper?
l

Lenny

05/21/2020, 9:37 PM
queries only, and i’m not really using coroutines yet but i am using dataloader
d

Dariusz Kuc

05/21/2020, 10:01 PM
well there is a big difference in behavior whether you use regular blocking query vs coroutine based one
checking if we have it documented
TLDR if you don’t use any of the async models, by default you will be blocking the threads
are you using
graphql-kotlin-spring-server
?
l

Lenny

05/21/2020, 10:13 PM
i’m not, we have our own java framework 😞
i think this codepath is using completable futures, but maybe i’m blocking things elsewhere … i’m experimenting with a couple of things
this is the resolver i’m using:
Copy code
class Query {
  fun plan(id: ID, env: DataFetchingEnvironment): CompletableFuture<Plan?> {
    return env.getDataLoader<String, Plan>("plan").load(id.value)
  }
}
and i’m calling it multiple times in the same operation, like
Copy code
{
  a: plan(id: 1) {id}
  b: plan(id: 2) {id}
  c: plan(id: 3) {id}
}
d

Dariusz Kuc

05/21/2020, 10:20 PM
what execution strategy are you using?
i.e. completable future will eventually run on some thread
you might need to create custom strategy with thread pools (or custom data fetcher that does it)
l

Lenny

05/21/2020, 10:21 PM
Copy code
.executeAsync()
if that’s what you mean
l

Lenny

05/21/2020, 10:23 PM
hm interesting … i haven’t needed that api when i was using graphql-java directly
i can give it a shot
d

Dariusz Kuc

05/21/2020, 10:23 PM
i believe those are the defaults
and then its up to
graphql-java
execution strategy to actually execute the futures
l

Lenny

05/21/2020, 10:25 PM
yeah that was my impression too
d

Dariusz Kuc

05/21/2020, 10:56 PM
If you could share some code that repro the issue that would be great
But such a big difference seems suspicious
l

Lenny

05/21/2020, 11:00 PM
yeah i agree … i’ll spend some time trying to create a minimal reproduction
thanks for the responses so far!
sighh false alarm — i don’t know java and made a mistake structuring my app. i was recreating the schema on every request. which makes wayyyy more sense than a problem with graphql-kotlin!
👍 1
d

Dariusz Kuc

05/22/2020, 2:03 PM
👍
3 Views