Profiling a Rails app

Any recommendations for the best way to profile a rails app? I saw there
was a post several months ago about some troubles here that was never
responded to:
https://groups.google.com/d/topic/jruby-users/gtal0h7s5sw/discussion

Is anybody using these profiling tools with useful results?

On 17.07.2012 22:10, Matt H. wrote:

Any recommendations for the best way to profile a rails app? I saw
there
was a post several months ago about some troubles here that was never
responded to:
https://groups.google.com/d/topic/jruby-users/gtal0h7s5sw/discussion
Is anybody using these profiling tools with useful results?

I’ve had good results with Java profilers. I have used:

JXinsight/Opus: http://www.jinspired.com/products/opus

JProfiler: ej-technologies - Java APM, Java Profiler, Java Installer Builder

Netbeans Profiler: http://profiler.netbeans.org/ (part of Netbeans IDE;
not a separate program)

I generally used them in “sampling” mode which is the lightweight but
less
accurate profile where the profiler periodically peeks at the stacks of
all
running threads. It can thus miss some method calls.

I typically run with a filter to restrict profiling to Java packages
“org.jruby” and “rubyjit”, but this is not required, or some other
filter
may be more appropriate.

I have not used Opus JRuby edition. I believe it converts the somewhat
obscured Java class and method names into normal looking Ruby class and
method names.

Opus is very nice, but won’t show a call stack; only a flat list of
methods
(of course, you could buy more advanced versions). It tends to “just
work”
in my experience (I think it does more than just sampling but has
dynamic
tuning to avoid making your app too sluggish). Netbeans is nice since
its
free and open source, but I’ve had fewer problems with Opus and
JProfiler.

One issue with digging into a call stack within Netbeans or JProfiler
is
that each Ruby method involves several Java method calls, so call
stacks
get very very deep. But with a little patience and a lot of clicking,
you
can get useful information.

Keep in mind that before JRuby compiles your Ruby code to bytecode, all
you’ll
see are org.jruby methods interpreting an abstract syntax tree. Once
it compiles
you’ll start to see things in the rubyjit package that will mostly
retain the
Ruby class and method names.

If you have never used a Java profiler, they all typically work by
specifying a JVM option to load some code. This code starts before any
of
your Java classes (JRuby etc.) are loaded so it has the chance to
instrument these classes. Typically, the profiler will wait until you
launch the profiler’s GUI and connect to it, at which point your Rails
app
will start up.

Example for Opus:

$ cat jxinsight.aspectj.filters.config
rubyjit.
org.jruby.

$ jruby -J-javaagent:/absolute/path/to/Opus/opus-aj-javaagent.jar

$ java -jar Opus/console/opencore-console.jar

if app is running on localhost, opus console should connect

automatically

or you may need to click “Console → Add Server…”. I’ve had to do

this

locally to connect to my 192.168.x.x address

Example for Netbeans:

There is some setup work to do in Netbeans to export the profiling pack
or
native code agent or whatever it’s called. This can be done via the
“Profile → Attach Profiler” dialog.

tells netbeans profiler to start and wait for a connection on port

5140
$ jruby
‘-J-agentpath:/absolute/path/nb-remote-mac-jdk6/lib/deployed/jdk16/mac/libprofilerinterface.jnilib=/absolute/path/nb-remote-mac-jdk6/lib,5140’
Profiler Agent: Initializing…
Profiler Agent: Options: >/Users/pat/apps/nb-remote-mac-jdk6/lib,5140<
Profiler Agent: Initialized successfully
Profiler Agent: Waiting for connection on port 5140 (Protocol version:
12)

Now inside Netbeans, attach the profiler, edit the filter to include
only
“org.jruby., rubyjit.”, let it run for a while, then click “Take
Snapshot”.


Patrick M.

Thanks for the tips =)


Matt H.

Wow, I started taking a look at JXinsight/Opus, and it is really easy to
use and really helpful. Thanks again!


Matt H.

This is awesome, I have no use for this ATM but I just simply love the
helpful and kind Netbeans/Ruby folks.
patrick.awesomeness += 1

2012/7/20 Matt H. [email protected]