简体   繁体   中英

How to profile memory of a spring boot webapp running on cloud foundry?

I have a Spring boot application running on internal cloud foundry space. I want to monitor the Stack and Heap memory of this web app, in order to find a StackOverflow exception originating from code.

What could be the best way to profile the application.

1. Run your app with JMX settings

  • To test profiling on your local machine run theapp with the following JMX configuration and then go to the last step "3. VisualVM configuration" :

     java \\ -Dcom.sun.management.jmxremote=true \\ -Djava.rmi.server.hostname=localhost \\ -Dcom.sun.management.jmxremote.port=9999 \\ -Dcom.sun.management.jmxremote.rmi.port=9999 \\ -Dcom.sun.management.jmxremote.ssl=false \\ -Dcom.sun.management.jmxremote.authenticate=false \\ -jar theapp.jar ...
  • To pass the JMX configuration to theapp in CF use the JBP_CONFIG_JMX environment variable (or JAVA_OPTS with params as above), manifest.yml :

     applications: - name: theapp buildpack: java_buildpack env: JBP_CONFIG_JMX: "{enabled: true, port: 9999}" # JAVA_OPTS: "-Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

2. Create SSH tunnel to theapp's container

cf ssh -N -T -L 9999:localhost:9999 theapp

3. VisualVM configuration

  • Download VisualVM
  • Run VisualVM: visualvm --jdkhome "$JAVA_HOME"
  • Add JMX connection: localhost:9999


You can also create SSH tunnel using PuTTY

  • Retrieve and display theapp's guid:
     cf app theapp --guid # example: 12345678-1234-1234-1234-123456789012
  • Get a one time password for ssh clients:

     cf ssh-code # example: PolSkAjEzyKtrUdnA
  • Create PuTTY SSH connection:

    • hostname: theapp.your.cloud
    • port: 2222
    • username: cf:<app-guid>/<app-instance-index>@ssh.your.cloud
      • example: cf:12345678-1234-1234-1234-123456789012/0@ssh.your.cloud
    • password: <ssh-code>
      • example: PolSkAjEzyKtrUdnA
    • connection/ssh/tunnels/:
      • source port: 9999
      • destination: 127.0.0.1:9999

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM