Forum: JRuby Profiling a Rails app

6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-18 05:11
(Received via mailing list)
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/gtal...

Is anybody using these profiling tools with useful results?
27598e1b77ce41fb0bd8a6fc4a3715d4?d=identicon&s=25 Patrick Mahoney (Guest)
on 2012-07-18 19:04
(Received via mailing list)
On 17.07.2012 22:10, Matt Hauck 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/gtal...
> 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: http://www.ej-technologies.com/company/profile.html

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
<in another terminal>
$ 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 Mahoney
6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-20 08:43
(Received via mailing list)
Thanks for the tips =)

--
Matt Hauck
6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-20 09:09
(Received via mailing list)
Wow, I started taking a look at JXinsight/Opus, and it is really easy to
use and really helpful. Thanks again!

--
Matt Hauck
Fe3bda5efab4f341304dee628e9a5dc2?d=identicon&s=25 Peter Lamber (Guest)
on 2012-07-20 10:20
(Received via mailing list)
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 Hauck <matthauck@gmail.com>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.