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.
Related
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
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
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.
Have you heard of any library which would allow me to set up tracing for specific methods at runtime?
Instead of adding (and removing) lots of System.out.println in my code (and having to re-compile and re-deploy) I would like to have a magic thing which would print out a line for each call of selected method without any change in the code. This would work without re-compiling, so some kind of JVM agent (or some non-standard JVM would be needed?). Sounds like a job for aspect programming?
A typical scenario would be to start an application, configure the traced methods dynamically (in a separate file or similar) and then everytime a selected method is called a line with its name (and arguments) is printed out to System.out (or some log file).
Naturally one could think of tens of additional features, but this basic set would be a great tool. BTW, I use Eclipse interactive debugger too, not only the System.out tracing technique, but both have some advantages and sometimes Eclipse is not enough.
Yes what you are referring to is known as Aspect oriented programming. A typical library providing this for Java is AspectJ. You define what are called pointcuts, essentially regular expressions for classes and method names, including wildcards, and the code to execute at each pointcut, known as an advice. This is useful for logging and also security checks and similar cross cutting concerns.
You can turn pointcut advices on and off through configuration. You can have an advice execute before a method call, after it returns or even after it throws an exception. Arguments are also available.
An aspectj java agent is needed for this to work.
In my experience, that kind of very detailed tracing (much more detailed than one would normally use for logging) as a debugging technique is indicative of insufficient unit testing and integration testing.
You can do this using a tool called InTrace.
NOTE: InTrace is a free and open source tool which I have written.
Log4J useful for disabling logging depending on "log-level" (DEBUG, INFO, WARN, FATAL).
You specify in configuration file what the least level you want to appear in logs, e.g., don't log anything below INFO level, and voila!
Looks like there's yet another solution - called Byteman. In their own words:
Byteman is a tool which simplifies tracing and testing of Java
programs. Byteman allows you to insert extra Java code into your
application, either as it is loaded during JVM startup or even after
it has already started running. The injected code is allowed to access
any of your data and call any application methods, including where
they are private. You can inject code almost anywhere you want and
there is no need to prepare the original source code in advance nor do
you have to recompile, repackage or redeploy your application. In fact
you can remove injected code and reinstall different code while the
application continues to execute.
Jackplay is the tool you are looking for.
It allows you to enable logging on method entry and exit points without any coding or redeployment.
It also allows redefining a method body. It gives you web based UI as control panel to enable or undo tracing on your class.methods.
I want to be able to expose various time and count based metrics dynamically from my applications. Perf4j works out pretty well for the time ones but does not allow for count in a straightforward way that I'm aware of.
for instance I can do
StopWatch dbWriteTime = new Log4JStopWatch("ServiceName:DBWrite");
dbWriteTime.start();
... execute DB stuff here
dbWriteTime.stop();
and you can set these metrics to get logged at whatever interval and it does a great job of that. But sometimes I want to do something like
Metric metric = new Metric("ServiceName:OrdersPerRequest");
metric.put(50);
I could call the perf4j timer lib 50 times but that is a horrible and inefficient hack to get my metrics in the log. Does anyone know a good open source library that can do both types of metrics? Also if it could monitor the output metric logs and dump them to a centralized DB that would be great. Additionally if you know of a good open source web front end to graph and display this sort of data I'd be very interested in that. It seems this must be something a lot of people have needed before.
I like Coda Hale's metrics library the best but you might also want to look at Java Simon. Other options include stajistics, JAMon, and parfait.
I would suggest taking a look at Coda Hale's presentation, and his metrics library. That should cover you from a Java perspective.