Wednesday, June 12, 2013

Java Spring Profiling with Spring Insight

We will be using Spring Insight to profile a Spring MVC application in Amazon EC2. As long as you are using Ubuntu, you should be able to follow this post.

Specs:
  • Ubuntu Server 12.04.1 LTS
  • m1.small instance
  • a pre-existing Java Spring application deployed on tomcat7
  • Java Open JDK 1.7
Being by connecting to you machine via ssh.

Download Spring Insight. Select the vfabric tc server developer edition instead of the springsource tool suite (STS). You will need to sign on an account in the VMware website. Use wget to fetch the file to your ubuntu instance.
wget {link to vfabric-tc-server-developer-2.9.2.RELEASE.zip}
cd /opt
mkdir /opt/tools
cd /opt/tools
unzip vfabric-tc-server-developer-2.9.2.RELEASE.zip
mv vfabric-tc-server-developer-2.9.2.RELEASE
Inside the vfabric-tc-server-developer-2.9.2.RELEASE folder, run
./tcruntime-instance.sh create insight -t insight
You will see
Creating instance 'insight' ...
  Using separate layout
  Creating bin/setenv.sh
  Applying template 'base'
    Copying template's contents
    Applying fragment 'context-fragment.xml' to 'conf/context.xml'
    Applying fragment 'server-fragment.xml' to 'conf/server.xml'
    Applying fragment 'web-fragment.xml' to 'conf/web.xml'
    Applying fragment 'tomcat-users-fragment.xml' to 'conf/tomcat-users.xml'
    Applying fragment 'catalina-fragment.properties' to 'conf/catalina.properties'
  Applying template 'base-tomcat-7'
    Copying template's contents
    Applying fragment 'server-fragment.xml' to 'conf/server.xml'
    Applying fragment 'web-fragment.xml' to 'conf/web.xml'
    Applying fragment 'catalina-fragment.properties' to 'conf/catalina.properties'
  Applying template 'insight'
    Copying template's contents
    Applying fragment 'server-fragment.xml' to 'conf/server.xml'
  Configuring instance 'insight' to use Tomcat version 7.0.39.B.RELEASE
  Setting permissions
Instance created
Connector summary
  Port: 8080   Type: Auto-Switching HTTP 1.1   Secure: false
A folder called insight is created.

If you change into the insight directory, you will see a folder called webapps (this is almost same as the Tomcat directories). Copy your war file into this directory.
cd insight
cp {your_java_war_file} webapps/
Start the insight instance.
./tcruntime-ctl.sh insight start
You will see
Using CATALINA_BASE:   /opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/insight
Using CATALINA_HOME:   /opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/tomcat-7.0.39.B.RELEASE
Using CATALINA_TMPDIR: /opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/insight/temp
Using JRE_HOME:        /usr/lib/jvm/java-7-openjdk-amd64/jre
Using CLASSPATH:       /opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/insight/bin/insight-bootstrap-tomcat-extlibs-1.9.2.SR1.jar:/opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/tomcat-7.0.39.B.RELEASE/bin/bootstrap.jar:/opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/tomcat-7.0.39.B.RELEASE/bin/tomcat-juli.jar
Using CATALINA_PID:    /opt/tools/vfabric-tc-server-developer-2.9.2.RELEASE/insight/logs/tcserver.pid
Status:                RUNNING as PID=503
Be sure to open port 8080 in your security group.

Now browse to the webpage.
http://{external_ec2_address}:8080/{war_name}

No comments:

Post a Comment