-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JVM Profiling #2635
Comments
I've done a bit of research into this and the closest to what we have in other languages and also most useful seems to be the
|
I've experimented a bit with Findings
Possible solutionCurrently, the only possible avenue (I can see) to make this profiler work for our use-cases is by altering the c++ source code to:
ProblemsWithin my limited experiments, I have encountered a SIGBUS after enabling the profiler (happens almost every time) on Java 17.0.7 While this specific crash is caused by a JVM bug, it seems it's not uncommon and there's a lot of crashes reported. I haven't evaluated those yet to see whether async-profiler is to blame or other bugs in JVM, e.g. as the first one... |
By a chance, I came across this research from a linked issue.
There is no open source version of async-profiler for Windows. Your best bet on Windows is probably JDK Flight Recorder. It comes with a number of flaws, but given the limitations of the platform, it is hard to achieve the same level of Java profiling quality as on Linux or macOS anyway.
There are 3 main ways to run async-profiler:
All are equally supported, fully functional and widely used.
Minimalistic does not mean rudimentary. Async-profiler's Java API is quite mature.
Depends on the definition of "useful". But it's true that JFR is the most comprehensive, flexible and suitable for automated parsing format. It's also de facto standard for Java profiling: there is a standard API for processing JFR recordings, many tools support JFR files: JMC, VisualVM, IntelliJ IDEA etc. Async-profiler has a built-in JFR reader and a number of converters from JFR to other formats.
Async-profiler records thread information in JFR recordings by default. For other output formats it can be enabled with
Why would this be needed?
As mentioned earlier, there is a
Yes, this is a notorious JVM bug specific to JDK 17.0.7 on macOS/ARM.
If I search for "crash" in the JDK bugtracker, I'll find 19K issues. Not sure what to conclude from this fact though, except that JDK is quite popular, and being a complex piece of software it sometimes works not as expected. If the project is alive and supported, the issues are continuously discovered and addressed. |
Thanks @apangin for your valuable input and for filling in more context. I really appreciate that. Firstly, to clarify parts of my comment which may have been misunderstood: all the info and assumptions I've written down were in the context of Sentry SDK JVM profiling, not meant as general async-profiler summary. For example, when I was saying JFR is the only useful output, that was meant as the only output supported by async-profiler that is useful for our use-case in sentry-java for JVM profiling. Similarly, with my other comments, for example saying that the Java API is rudimentary, this may have come along as offensive but was meant as "basic/limited", i.e. not really a fully-fledged API with methods for individual functionalities of the underlying profiler but rather that it had just a few most used methods and the rest was available through the With regards to per-thread and continuous profiling - it seems I have missed/misunderstood some of the behaviour and this will need further investigation on our end. We'll need to find out whether it can be used to achieve the most important use case at hand, which can be simplified as: "collect sample-profiler sessions for individual transactions, which are actually individual requests served by Spring boot". Assuming requests are served on individual threads, this means collecting short profiles for individual threads. And because the requests are served in parallel, we need to run multiple independent (as in independent start&stop and independent data output) profiler sessions in parallel. |
Hey, I've gotten back to this and I think the async-profiler with some adaptations is a viable option. As I've already mentioned above, I still feel the best approach (performance wise) would be to fork/derive from the original source and make it produce profile output tailored specifically to Sentry, without the intermediate JFR conversion. I think we could do this by picking the select sources and compiling the library with Gracle CppCompile so we don't have additional complexity with submodules and a separate fork. Alternatively, I could try integrating the async-profiler as is, with the default profiler and let it dump output to disk in JFR format periodically and then (read & convert to Sentry profile format in our SDK. This may be slightly easier to implement but will have higher runtime overhead due to disk access & conversion. I'm a bit reluctant with this because I think we may end up with an additional layer that would act as a buffer that would be collecting the data from files and slicing it, basically like another continuous profiler but instead of actually profiling, it would be just reading JFR files and combing them to form an in-memory model for the past 30 seconds, so that we can slice it at will on transaction end (like in some other SDKs) Any thoughts? |
Agreed!
Wouldn't this make it harder to keep it up-to-date with the changes upstream? I tend to prefer a submodule on the fork |
We would likely need just a part of the repo but yeah, a fork is an option too, if you so prefer. I agree it's easier to follow the updates. |
More context in this thread: |
Hi folks, what is the latest on this? profiling for springboot. |
Hello @Bkbest we currently don't have an ETA for this. |
Hi @adinauer , do you suggest any work around for this? |
@Bkbest there are some investigation comments above that could be useful but this won't get data into Sentry, so I don't think there's a real workaround here. |
But I think this will be a great win if we are able to to do this! |
Description
Support Sentry profiling running in the JVM
Milestones
The biggest opportunity here is supporting Spring Boot specifically. But generically supporting JVM for both per-thread or per-request (webflux/async) will be the complete deliverable.
Assuming here that if we get Java it won't matter the actual language that compiled to bytecode. It would be valuable to support Kotlin, Scala, Clojure, Groovy (in this order, if it mattered).
Related profiling issues and PRs:
.NET: getsentry/sentry-dotnet#1955 and getsentry/sentry-dotnet#2206
iOS profiler: * getsentry/sentry-cocoa#1652
Android: #1897 and #1973
NodeJS: https://github.com/getsentry/profiling-node
Python: getsentry/sentry-python#1481
Ruby: getsentry/sentry-ruby#2013
The text was updated successfully, but these errors were encountered: