rollbar / rollbar-java

Rollbar for Java and Android
https://docs.rollbar.com/docs/java
MIT License
71 stars 76 forks source link

Native agent adds 10x startup time to Spring Boot app #227

Open phillipuniverse opened 4 years ago

phillipuniverse commented 4 years ago

I added a sample project to reproduce it at https://github.com/phillipuniverse/rollbar-native-test. Without the agent, startup time is ~2s. With the agent, startup time is ~20s. The project uses the .dylib and .so files that I used to validate with, both with the same results (although Linux was slightly faster). I build the .dylib and .so files from the master branch just to make sure I had all the changes.

In this example it isn't so bad, but it takes a different Spring Boot project (that has Spring Data, Rabbit, Mongo, JPA, etc etc) go from ~15s startup time to ~400s which makes the whole native agent a non-starter.

I will say though, once it starts up I get locals in my Rollbar traces which is why I would really like this to work!!

image

Might be relevant, but when I turn on debug logging with ROLLBAR_LOG=debug I get this:

 INFO  rollbar_java_agent > Agent load begin
 INFO  rollbar_java_agent > Agent load complete success
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
 DEBUG rollbar_java_agent > JNI call failed: 'com/rollbar/jvmti/ThrowableCache class not found: com/rollbar/jvmti/ThrowableCache'
...
...

The ThrowableCache class not found is emitted an insane amount of times. If I were to bet, it seems to indicate that the cache is not being used by the native agent, which contributes to the super slow startup times??

phillipuniverse commented 4 years ago

I'm happy to contribute more here, any hints on what path to go down for this?

alif commented 3 months ago

@phillipuniverse have you still been seeing this issue? I know it's been many years, but it would be helpful for us to know if you continue to have this problem.

phillipuniverse commented 3 months ago

@alif my guess is yes. However I can't build the latest version of the native agent. I'm using an M1 mac and this cargo:

~/rollbar-java/native-agent ‹master*› » cargo --version                                                                                                                                                        [23:41:23] 101 ↵
cargo 1.78.0 (54d8815d0 2024-03-26)

Going to native-agent and cargo build --release based on these docs fails:

failure ``` Compiling pretty_env_logger v0.2.5 Compiling rollbar-java-agent v0.1.0 (/Users/phillip/rollbar-java/native-agent) error: this file contains an unclosed delimiter --> /Users/phillip/rollbar-java/native-agent/target/release/build/rollbar-java-agent-dd71d7539b1ccf95/out/jvmti_bindings.rs:108:372066 | 108 | ...um_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_1 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 805371904 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_1_0 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 805371904 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_1_1 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 805372160 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_1_2 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 805372416 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_9 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 805896192 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_11 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 806027264 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_19 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 806551552 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION_21 : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 806682624 ; pub const enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1)_JVMTI_VERSION : enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/include/jvmti_h_39_1) = 806682624 ; pub type enum_(unnamed_at_//opt/homebrew/Cellar/openjdk/21_0_3/libexec/openjdk_jdk/Contents/Home/inclu ```

And it doesn't seem to work with Java 21 when I run my project with Java 21 and Spring Boot 3:

Error occurred during initialization of VM
Could not find agent library ./librollbar_java_agent.dylib in absolute path, with error: dlopen(./librollbar_java_agent.dylib, 0x0001): tried: './librollbar_java_agent.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS./librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/lib/server/././librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/lib/server/.././librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/lib/server/server/./librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/bin/./librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/bin/server/./librollbar_java_agent.dylib' (no such file), '/opt/homebrew/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home/bin/../lib/./librollbar_java_agent.dyl

There have also not been any builds of the native agent published since 1.4.1.

FYI in case you want to take another look I updated my example project to Spring Boot 3.

So seems like the native agent still needs a lot of work!