I am developing a Java application that reads data from a Redis Database, I use Lettuce library to connect to Redis which in turn uses 'Netty' library to communicate with Redis
I suspect that the execution time of my application is greater than expected, so a conducted a profiling experiment using JProfiler, I was surprised that a FastThreadLocalRunnable takes a significant portion of the execution time with no justification as the tree shows no function calls taking time:
So, is it a bug in Lettuce library?, or is it a problem in the profiler measuring the execution time?
Any help is appreciated
Edit:
Thanks to Ingo's answer I can now expand the tree but it turns out that the java NIO is consuming my processor:
Any idea?
The call tree in JProfiler only shows classes that are included in the call tree filters that you define in the profiling settings:
By default, this excludes a lot of common frameworks and libraries so that you can get started without configuring anything. It is better if you delete these filters and add your own profiled packages here.
In addition to the profiled classes, JProfiler shows the thread entry point even it is not a profiled class, such as io.netty.util.concurrent.FastThreadLocalRunnable. Also, the first call into non-profiled classes is always shown at any level in the call tree.
In your case there are call chains to non-profiled classes below io.netty.util.concurrent.FastThreadLocalRunnable that never call a profiled class. They could belong to some framework or to some part of your code that is not included in the profiled classes. This time has to go somewhere, so it is attributed to the io.netty.util.concurrent.FastThreadLocalRunnable node.
An easy way to check is to disable filtering in the profiling settings, then you see all classes.
More information about call tree filters can be found at
https://www.ej-technologies.com/resources/jprofiler/help/doc/main/methodCallRecording.html
Related
I have a Java Spring application that is running on my PC (I can attach debugger), I am looking for a way to profile a single method, preferably one that does have an UI to drilldown the child methods that consume the most time.
I tried JDK mission control and IntelliJ 's default profiler which I believe both are based off Java Flight Recorder. The issue is that most of the time it does not sample my method and my method spend lots of time waitting for (async?) I/O which cause the profiling result to be unusable
Why does the Java flight recorder take too few samples?
How to include IO-bound methods in Java Flight Recorder sampling?
What should I do in this case? Given that
I can already debug the method
I want to profile a single run on that single method only
I can get the drill down of child methods (Flame/Icicle chart) like what Google Chrome can do, including time when function is pending IO?
Preferably, without changing source code.
As supplemental detail, I already looked at some questions here that does not address the issue I mentioned: Some require to update to source code and some is dependent on JFR method sampling which I do not know how/if can profile a single specific method run and include the async I/O in the drill-down view
Any recommended Java profiling tutorial?
Profiling a Java Spring application
Please suggest an Application performance tool for Spring boot, I am using Jamon API right now but I need the logs at very granular level like graph and all instead of AVG, Min, MAX time only. I don't want to deploy it as additional service, I am looking something integrated within Micro service (Via Maven or Jar). Thanks in advance.
<Monitor> monitorName = <MonitorFactory>.start("Function Name");
//Some code here
monitorName.stop();
What I need is EveryDetails for this function name : Every Time Stamp it invoked, how much time this function took at that timestamp.
Sounds like you want to monitor just java methods. If that is the case then Automon should work.
JAMon has lots of modules that monitor web hits, jdbc, garbage collector, and more. Automon doesn't do all that, but can monitor any java code (even 3rd party libraries) with a simple configuration file. Automon doesn't actually do the monitoring, but instead calls any monitoring code that either you provide and out of the box it works with well-known monitoring libraries (i.e. JAMon, JavaSimon, Yammer Metrics, new relic, StatsD, Micrometer). It is also easy to implement your own callback code that would log (using sl4j, log4j etc). In fact, a similar example referenced below does just that with calls to System.out.println. You could even have it both log messages and call jamon.
automon - https://github.com/stevensouza/automon
automon System.out.println implementation - https://github.com/stevensouza/automon/blob/master/automon/src/main/java/org/automon/implementations/SysOut.java
Here is sample output using SysOut, however if you implement it you could add anything else you want.
SysOut.start(..): execution(String com.stevesouza.helloworld.HelloWorld.getLastName())
SysOut.stop(..) ms.: 0
Full disclosure. I wrote both JAMon and Automon.
I am doing a project where I need all the API calls to take less than 1s but I am facing an issue with the first call to each route that is slower than the following ones.
Currently the first call to /login takes 3.6s and the next ones take 170ms and same for all the other routes.
I found out using -XX:+TraceClassLoading that on the first call, the classes were loaded in memory and that caused the performance issue.
However I did not find an easy way of loading all the classes at start up and for each new service, I need to add a warm up call in an ApplicationRunner.
Does anyone have a solution to automatically load the classes of a SpringBoot application or warm up all its routes?
Java's class loading is lazy. This means a class is only loaded by the JVM when it needs to and if it needs to.
If you want to force it to eagerly load classes you just need to reference them. One way of doing it is to iterate through the jar contents or class files to get the class names and then use them to call Class.forName(className).
Additionally, if startup time and performance is very important for your use case, you might want to look into ahead of time compilation solutions like GraalVM, or reduce JIT's threshold for compilation (-XX:CompileThreshold).
To me, the only viable option you have is class data sharing, spread across JEP 310, JEP 341 and JEP 350, but this requires java-13 most probably. We are testing this internally at my work place (mostly for fun, not going to lie) and the results look good, so far.
The other option is calling your endpoints when the application starts - if that is an option. Again, it is for us for example: we call them with dummy data a couple of hundreds of times to warm up the code. But, at the same time, we have services where this would be impossible - that's why the exploring of CDS too.
I have a Java project with Gradle as build environment.
Simplifying my scenario:
I have a module called Utils and one of its interfaces is TimeProvider which is implemented by either a real time provider (System.currentTimeMillis()) or a logic time provider (incrementing a counter). Another example is instead of sleeping for some time, I can just increment the timestamp. The goal is to run tests independently of the current time. An example use case is to be able to stop at break points without worrying aobut the time to progress and disrupting my tests.
(BTW if you have a betteer way to do do, I would appreciate any insight).
My question is how to force all the parts in the code to use this infrastructure and not the real Java time solutions (Thread.sleep, System.currentTimeMillis, etc.)
I want to prevent a scenario where a programmer accidently writes a code that uses the real Java time instead of my infrastructure.
One option is to use a Security Manager but this is tricky because the error will be catched "some time" during run time.
I prefer a way to catch this during compile time.
I wonder if there is a way, maybe in Gradle to forbid some modules use part of Java code? Maybe there is another way to do so?
Thanks,
The idea is to utilize AOP for designing applications/tools to debug/view execution flow of an application at runtime. To begin with, a simple data(state) dump at the start and end of method invocation will do the necessary data collection.
The target is not application developers but high level business analyst or high level support people for whom a execution flow could prove helpful. The runtime application flow can also be useful in reducing the learning curve of an application for new developers especially in configuration loaded systems.
I wanted to know if there already exists such tools/applications which could be used. Or better, if this makes sense, then is there a better way to achieve this.
You could start with Spring Insight (http://www.springsource.org/insight) and add your own plugins to collect data appropriate for business analysts/support staff. If that doesn't meet needs, you can write your own custom aspects. It is not that hard.
You could write your own aspects, as suggested by ramnivas, but to prepare for the requests from the users, you may want to just have the aspects compiled into the application, so that you don't have to take a hit at run-time, and then they could just select which execution flows or method groups they are interested in, and you just call the server and set some variable to give them the information desired.
Writing the aspects is easy, but to limit recompiling, you may want to get an idea what the users will want, for example, if they want to have a log of every call made from the time a webservice is called until it gets to the database, then you can build that in, but it would be easier to know this up-front.
Otherwise the aspect does nothing, if the variable is not set, and perhaps unset the variable when finished.
You could also have where they can pick which type of logging and for which user, which may lead to more useful information.