Now that you have a functional GraphQL Java server running with some business logic, its time to profile the JVM!!
Profiling your java application has massive benefits, such as increasing the chance of finding redundant memory allocation and memory leaks. The first being critical for low latent and highly concurrent APIs.
In this tutorial we will plant a memory allocation bug and identify it with VisualVM.
The first thing we do it setup a small Apache JMeter load testing script for our GraphQL requests. We configure this to send 3 concurrent batches of 1000 requests.
We then start our spring boot graphql server with the VisualVM IntelliJ launcher. Navigate to your application and select the profile tab. Open settings and add an asterisk symbol to record all classes/methods. Click start profiling.
Execute the Jmeter script.
Navigate back to VisualVM and stop the profiler.
You should now have insight into hot stack traces, heavy method calls and heap memory allocation. If you see "Unknown", restart VisualVM... sometimes it has this bug.
VisualVM identified the memory allocation bug and told us the exact class and method. Thanks!!!
You can also try the sampling tab for memory allocation and CPU profiling.
Other than the above, there are many kinds of application metrics you should consider such as
Service percentiles
Service availablity / uptime
Internal http/grpc client percentiles
Executor metrics (queue depth etc)
GC execution
Kubernetes memory requests
JVM memory
Method counts
Exception counts / classes
GraphQL queries / execution time
GraphQL resolver execution time / counts
Kubernetes CPU requests
Database connection pools
etc etc etc!
Other tools I like are, micrometer, stackdriver, java mission control and gatling load testing.
I had fun making this one, profiling is one of my hobbies :)
See you in the next video!
Cheers, Philip
Spring Boot GraphQL Java: https://github.com/graphql-java-kicks...
VisualVM for graphql jvm profiling: https://visualvm.github.io/
Apache Jmeter for load and performance testing: https://jmeter.apache.org/
IntelliJ VisualVM Launcher: https://plugins.jetbrains.com/plugin/...
GraphQL Java DataLoader: https://github.com/graphql-java/java-...
GraphQL Connection Cursor Pagination Tutorial: • Spring Boot GraphQL Tutorial #21 - Pa...
Gatling load testing: https://gatling.io/