Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 957
pritamprasad Avatar asked Oct 28 '25 09:10

pritamprasad


1 Answers

  • https://content.pivotal.io/blog/new-cloud-foundry-java-buildpack-improves-developer-diagnostic-tools
  • https://community.pivotal.io/s/article/How-to-Remotely-Debug-Java-Applications-on-Cloud-Foundry

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/[email protected]
    • password: <ssh-code>
      • example: PolSkAjEzyKtrUdnA
    • connection/ssh/tunnels/:
      • source port: 9999
      • destination: 127.0.0.1:9999
like image 142
kinjelom Avatar answered Oct 31 '25 07:10

kinjelom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!