<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://brokenco.de//feed/by_tag/jruby.xml" rel="self" type="application/atom+xml" /><link href="https://brokenco.de//" rel="alternate" type="text/html" /><updated>2026-10-31T17:58:32+00:00</updated><id>https://brokenco.de//feed/by_tag/jruby.xml</id><title type="html">rtyler</title><subtitle>a moderately technical blog</subtitle><author><name>R. Tyler Croy</name></author><entry><title type="html">Marching towards JRuby/Gradle 2.0</title><link href="https://brokenco.de//2019/05/25/working-towards-jruby-gradle-2.html" rel="alternate" type="text/html" title="Marching towards JRuby/Gradle 2.0" /><published>2019-05-25T00:00:00+00:00</published><updated>2019-05-25T00:00:00+00:00</updated><id>https://brokenco.de//2019/05/25/working-towards-jruby-gradle-2</id><content type="html" xml:base="https://brokenco.de//2019/05/25/working-towards-jruby-gradle-2.html"><![CDATA[<p><a href="http://jruby-gradle.org">JRuby/Gradle</a> is one of the few open source projects
which I created that <em>actually</em> resonates with people. One that I find myself
continuing to work on, despite not using it in my day-to-day work. JRuby/Gradle is a
collection of Gradle plugins which make it easy to build, test, manage and
package Ruby applications. By combining the portability of JRuby with Gradle’s
excellent task and dependency management, JRuby/Gradle provides high quality
build tooling for Ruby and Java developers alike. With my fellow maintainer,
<a href="https://github.com/ysb33r">Schalk
Crojné</a>, I started working towards the <a href="https://github.com/jruby-gradle/jruby-gradle-plugin/milestone/27">2.0
milestone</a>.</p>

<p>I have tried to name each release after a different German city, a callback to
some JRubyConf EU events many years ago where Schalk, <a href="https://github.com/mkristian">Christian
Meier</a>, 
<a href="https://github.com/colinsurprenant">Colin
Surprenant</a>, and I had the good fortune to
meet up and work together. Since two point zero is so very exciting, I thought
I would name it after a very exciting city: Stuttgart (<em>the joke being that
it’s about as exciting as a bowl of cold oatmeal</em>).</p>

<p>With two point zero, we have an opportunity to make major backwards compatible
changes and adopt newer APIs provided by Gradle underneath. We’re also taking
the opportunity to remove support for older end-of-lifed JRuby versions, namely
JRuby 1.7.x, and all the gnarly code which was necessary to support those
versions.</p>

<p>I don’t have a date in mind for releasing 2.0.0, but it will likely happen
within the next month or so, depending on how my own hobby-hacking schedule
shapes up.</p>

<hr />

<p>I recently started playing around with the idea of combining Ruby with <a href="https://spark.apache.org">Apache
Spark</a> under the moniker
“<a href="https://github.com/jruby-gradle/redspark">redspark</a>.” To get started with
the project I made use of JRuby/Gradle and I was almost giddy with excitement
at how <em>easy</em> building fat <code class="language-plaintext highlighter-rouge">.jar</code> files with Ruby was, and how quickly I was
able to get a Ruby-based Spark job running. The code below is an example which
I am working with. There are still some bugs with how
Ruby objects are serialized and re-constituted on Spark worker nodes. The
redspark project has already fulfilled the main goal for JRuby/Gradle: making
it easy to bring the best of the Ruby and Java worlds together.</p>

<p>On to two point zero!</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#!/usr/bin/env ruby</span>
<span class="c1">#</span>
<span class="c1"># To run, first execute `./gradlew jrubyJar` to package the jar, then call</span>
<span class="c1"># `./run.sh` to send the jar to a local spark cluster installation</span>
<span class="c1">#</span>

<span class="n">java_import</span> <span class="s1">'org.apache.spark.sql.SparkSession'</span>
<span class="n">java_import</span> <span class="s1">'org.apache.spark.api.java.function.FilterFunction'</span>
<span class="n">java_import</span> <span class="s1">'org.apache.spark.api.java.function.ForeachFunction'</span>

<span class="n">logfile</span> <span class="o">=</span> <span class="s1">'build.gradle'</span>
<span class="n">spark</span> <span class="o">=</span> <span class="no">SparkSession</span><span class="p">.</span><span class="nf">builder</span><span class="p">.</span><span class="nf">appName</span><span class="p">(</span><span class="s1">'Simple Application'</span><span class="p">).</span><span class="nf">getOrCreate</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">spark</span><span class="p">.</span><span class="nf">read</span><span class="p">.</span><span class="nf">textFile</span><span class="p">(</span><span class="n">logfile</span><span class="p">).</span><span class="nf">cache</span><span class="p">()</span>

<span class="k">class</span> <span class="nc">BeeForeach</span>
  <span class="kp">include</span> <span class="n">org</span><span class="p">.</span><span class="nf">apache</span><span class="p">.</span><span class="nf">spark</span><span class="p">.</span><span class="nf">api</span><span class="p">.</span><span class="nf">java</span><span class="p">.</span><span class="nf">function</span><span class="o">.</span><span class="no">ForeachFunction</span>
  <span class="k">def</span> <span class="nf">call</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
    <span class="nb">puts</span> <span class="s2">"foreaching item: </span><span class="si">#{</span><span class="n">item</span><span class="si">}</span><span class="s2">"</span>
  <span class="k">end</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">BeeFilter</span>
  <span class="kp">include</span> <span class="n">org</span><span class="p">.</span><span class="nf">apache</span><span class="p">.</span><span class="nf">spark</span><span class="p">.</span><span class="nf">api</span><span class="p">.</span><span class="nf">java</span><span class="p">.</span><span class="nf">function</span><span class="o">.</span><span class="no">FilterFunction</span>
  <span class="k">def</span> <span class="nf">call</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
    <span class="nb">puts</span> <span class="s2">"filtering item: </span><span class="si">#{</span><span class="n">item</span><span class="si">}</span><span class="s2">"</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="nb">puts</span> <span class="s2">"about to filter"</span>
<span class="n">alphas</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="nf">distinct</span>
<span class="c1">#</span>
<span class="c1"># Failure caused while deserializing on the spark worker</span>
<span class="c1">#</span>
<span class="c1"># java.lang.ClassCastException: cannot assign instance of</span>
<span class="c1"># scala.collection.immutable.List$SerializationProxy to field</span>
<span class="c1"># org.apache.spark.rdd.RDD.org$apache$spark$rdd$RDD$$dependencies_ of typ</span>
<span class="c1">#betas = data.filter(BeeFilter.new).count</span>

<span class="c1"># Failure caused while deserializing on the spark worker</span>
<span class="c1">#</span>
<span class="c1"># java.lang.ClassNotFoundException: org.jruby.gen.BeeForeach_799252494</span>
<span class="n">betas</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="nf">foreach</span><span class="p">(</span><span class="no">BeeForeach</span><span class="p">.</span><span class="nf">new</span><span class="p">).</span><span class="nf">count</span>

<span class="c1"># Failure caused while serializing on the spark master</span>
<span class="c1">#</span>
<span class="c1"># java.io.IOException: can not serialize singleton object</span>
<span class="c1">#betas = data.filter { |line| line.contains('b') }.count</span>
<span class="nb">puts</span> <span class="s2">"filtered"</span>

<span class="nb">puts</span>
<span class="nb">puts</span> <span class="s2">"Hello from Ruby, we read </span><span class="si">#{</span><span class="n">logfile</span><span class="si">}</span><span class="s2">"</span>
<span class="nb">puts</span> <span class="s2">" and found </span><span class="si">#{</span><span class="n">alphas</span><span class="si">}</span><span class="s2"> 'a' characters"</span>
<span class="nb">puts</span> <span class="s2">" and </span><span class="si">#{</span><span class="n">betas</span><span class="si">}</span><span class="s2"> 'b' characters"</span>
<span class="nb">puts</span> 

<span class="n">spark</span><span class="p">.</span><span class="nf">stop</span><span class="p">()</span>
</code></pre></div></div>]]></content><author><name>R. Tyler Croy</name></author><category term="jrubygradle" /><category term="jruby" /><category term="gradle" /><summary type="html"><![CDATA[JRuby/Gradle is one of the few open source projects which I created that actually resonates with people. One that I find myself continuing to work on, despite not using it in my day-to-day work. JRuby/Gradle is a collection of Gradle plugins which make it easy to build, test, manage and package Ruby applications. By combining the portability of JRuby with Gradle’s excellent task and dependency management, JRuby/Gradle provides high quality build tooling for Ruby and Java developers alike. With my fellow maintainer, Schalk Crojné, I started working towards the 2.0 milestone.]]></summary></entry><entry><title type="html">JRuby/Gradle at JRubyConf EU 2015</title><link href="https://brokenco.de//2015/07/19/jrubyconfeu-jrubygradle.html" rel="alternate" type="text/html" title="JRuby/Gradle at JRubyConf EU 2015" /><published>2015-07-19T00:00:00+00:00</published><updated>2015-07-19T00:00:00+00:00</updated><id>https://brokenco.de//2015/07/19/jrubyconfeu-jrubygradle</id><content type="html" xml:base="https://brokenco.de//2015/07/19/jrubyconfeu-jrubygradle.html"><![CDATA[<p>Mid-way through last year, <a href="http://hackers.lookout.com">Lookout</a>’s investment
in <a href="http://jruby.org">JRuby</a> started to really take off. Having struggled with
the harsh realities of <a href="https://en.wikipedia.org/wiki/Ruby_MRI">MRI</a>, we
finally had a platform that gave us a way to grow our technology without having
to throw out vast amounts of existing Ruby code. After an exciting weekend at
<a href="http://2014.jrubyconf.eu">JRubyConf EU 2014</a> and
<a href="http://eurucamp.org">eurucamp</a> I started hacking on a brand new project, one
that I hoped would bring Ruby into harmony with the rest of the JVM ecosystem:
<a href="http://jruby-gradle.org">JRuby/Gradle</a></p>

<p>From <a href="http://jruby-gradle.org">jruby-gradle.org</a>:</p>

<blockquote>
  <p>JRuby/Gradle is a collection of Gradle plugins which make it easy to build,
test, manage and package Ruby applications. By combining the portability of
JRuby with Gradle’s excellent task and dependency management, JRuby/Gradle
provides high quality build tooling for Ruby and Java developers alike.</p>
</blockquote>

<p>The past twelve months have seen some incredible developments in the
JRuby/Gradle toolchain. Much of which would not have been possible without
<a href="https://github.com/ysb33r">Schalk W. Cronjé</a>’s massive contributions and help
getting the project off the ground. And more recently the help of <a href="https://github.com/mkristian">Christian
Meier</a> whose contributions have been partially
funded by Lookout, Inc.</p>

<p><em>Currently</em>, JRuby/Gradle is ready for prime-time. Lookout is using
it to unify dependency and task management across a number of different
projects, as well a few other notable
<a href="https://github.com/robfletcher/gradle-compass">use-cases</a> here and there.</p>

<p>As such, I’m very excited to be <a href="http://2015.jrubyconf.eu/speakers/agentdero.html">presenting
JRuby/Gradle</a> at this year’s
<a href="http://2015.jrubyconf.eu">JRubyConf EU</a> in Potsdam, Germany on <strong>July 31st</strong>. My
abstract is as follows:</p>

<blockquote>
  <p>One of the most useful aspects of JRuby is the ease at which one can integrate
tools from the Java ecosystem. For developers building hybrid applications
though, using Ruby tools like Bundler and Rake can result in unpleasant hacks.
If you stick to classic Java tools like Maven, it can feel like writing Ruby
with a straight-jacket on. This lack of mature tooling to support Java/Ruby
applications leaves developers in an uncanny valley between the two universes..</p>

  <p>With the recent rise of Gradle, which was designed to support a polyglot
ecosystem through a rich plugin architecture, there is light at the end of the
tunnel for JRuby developers!</p>

  <p>This talk will introduce the jruby-gradle project, an effort to combine the
very best in Java tooling with the Ruby world, providing top-notch integration
for JRuby devs. During the talk we will cover the motivations of the
jruby-gradle project and describe how it helps bridge the gap between Java and
Ruby. By combining the flexibility of JRuby with the power of Gradle, we can
breathe new life into JRuby, opening it up to an even broader audience than
before.</p>
</blockquote>

<p>I’m <em>very</em> excited to give this talk at JRubyConf, less than a calendar year
since the project was inspired at the very same conference.</p>

<p>If you’re in Europe and have the time/means to get to Potsdam, I cannot
recommend JRubyConf EU and <a href="http://eurucamp.org">eurucamp</a> highly enough, and I
hope to see you there!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jrubygradle" /><category term="jruby" /><category term="jrubyconfeu" /><summary type="html"><![CDATA[Mid-way through last year, Lookout’s investment in JRuby started to really take off. Having struggled with the harsh realities of MRI, we finally had a platform that gave us a way to grow our technology without having to throw out vast amounts of existing Ruby code. After an exciting weekend at JRubyConf EU 2014 and eurucamp I started hacking on a brand new project, one that I hoped would bring Ruby into harmony with the rest of the JVM ecosystem: JRuby/Gradle]]></summary></entry><entry><title type="html">JRuby demos from the JavaOne Script Bowl 2014</title><link href="https://brokenco.de//2014/11/02/javaone-jruby-demos.html" rel="alternate" type="text/html" title="JRuby demos from the JavaOne Script Bowl 2014" /><published>2014-11-02T00:00:00+00:00</published><updated>2014-11-02T00:00:00+00:00</updated><id>https://brokenco.de//2014/11/02/javaone-jruby-demos</id><content type="html" xml:base="https://brokenco.de//2014/11/02/javaone-jruby-demos.html"><![CDATA[<p>This past October I was invited to represent <a href="http://jruby.org">JRuby</a> in the
JavaOne 2014 “Script Bowl.” A panel where community members from various
projects which implement scripting languages on top of the JVM pitch their
language to a live studio audience. This year’s panel consisted of a members
from the Groovy, Clojure and Scala communities, and me representing JRuby of
course.</p>

<p>The session consists of two segments, historically with one focusing on
the capabilities of the language itself and the second segment focusing on the
community built around the scripting language.</p>

<p>Instead of choosing to create a presentation, I took the road less traveled and
created a series of live coding demos to demonstrate the utility of JRuby.</p>

<p>The collection of demos that I created can be found in this <a href="https://github.com/rtyler/javaone-jruby-demo">demo
repository</a>. For all of my demos
I used <a href="http://pryrepl.org">Pry</a> as a live JRuby interpreter to load and
execute Java and Ruby code on the fly, which I hope made for a compelling
presentation.</p>

<p>The following are the demos worth mentioning here:</p>

<h3 id="ascii-table-from-jar">ascii table from jar</h3>

<p>In <a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/ascii-table-from-jar.rb">this
demo</a>
I had grabbed some random Java code from the internet to print ascii-only
formatted tables, and wrote some Ruby glue to make use of it. Copying and
pasting this code into a running Pry session and you’ll get a nice table drawn
in your console.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[16] pry(main)&gt; puts make_table(headers, mails)
+-----------------------------+--------------------------+
|           Subject           |           From           |
+-----------------------------+--------------------------+
|         NOT SPAM WE PROMISE | sirspamsalot@hotmail.com |
| Important work related info |     yourboss@example.com |
|       Don't forget the milk |         spouse@family.io |
+-----------------------------+--------------------------+
=&gt; nil
[17] pry(main)&gt;
</code></pre></div></div>

<h3 id="anonymous-classes">anonymous classes</h3>

<p><a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/anonymous-classes.rb">This
demo</a>
demonstrates how JRuby merges the use of <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html">anonymous
classes</a>
in Java with Ruby’s concept of blocks. Instead of creating an anonymous class
that implements the <code class="language-plaintext highlighter-rouge">Runnable</code> interface, we can just use pass a block of code
to be executed inside of a <code class="language-plaintext highlighter-rouge">java.lang.Thread</code>.</p>

<h3 id="turtles">“turtles”</h3>

<p>This might be <a href="https://github.com/rtyler/javaone-jruby-demo/tree/master/turtles">my favorite
demo</a> because
it demonstrates one of the more compelling (to me) features of JRuby, it’s
embeddability. In the “turtles” demo, I’ve got an entirely embedded and
separate Ruby runtime environment, nested within an already existing Ruby
runtime.</p>

<p>The result is that I can create isolated Ruby environments within the same JVM,
which opens the door to all kinds of interesting sandboxing applications.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[44] pry(main)&gt; require './turtles/first'
=&gt; true
[45] pry(main)&gt; puts "Our original JRuby has version: #{JavaOne::VERSION}".colorize(:magenta)
Our original JRuby has version: 1
=&gt; nil
[46] pry(main)&gt; puts

=&gt; nil
[47] pry(main)&gt; # Now let's load a the same module with a different version inside the runtime environment
[48] pry(main)&gt; evaler.eval(runtime, "require './turtles/second'"); nil
=&gt; nil
[49] pry(main)&gt; evaler.eval(runtime, "puts \"Our embedded JRuby has version: \#{JavaOne::VERSION}\".colorize(:green)"); nil
Our embedded JRuby has version: 2
=&gt; nil
[50] pry(main)&gt;
</code></pre></div></div>

<h3 id="jruby-gradle">jruby-gradle</h3>

<p>The final <a href="https://github.com/rtyler/javaone-jruby-demo/tree/master/jruby-gradle-example">demo that I
gave</a>
is a little self-promiting, in that I demonstrated the capabilities of the
<a href="https://github.com/jruby-gradle">jruby-gradle</a> project. A project which allows
you to use the <a href="http://gradle.org">Gradle</a> tool for managing projects,
obviating the need for Bundler, JBundler, Warbler and RVM.</p>

<p>During the demo I showed the
<a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/jruby-gradle-example/build.gradle">build.gradle</a>
file which references a Ruby gem and demonstrated how to build a
self-contained, self-executing <code class="language-plaintext highlighter-rouge">.jar</code> file with the tool:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>% ./gradlew shadowJar
</code></pre></div></div>

<p>Then executed it:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>% java -jar build/libs/jruby-gradle-example-all.jar
REQUIRED RELATIVE
Hello from JRuby built with Gradle!
%
</code></pre></div></div>

<p>That is a jar file, running Java and Ruby code all from within the file, pretty
spiffy if you ask me!</p>

<hr />

<p>Predictably, JRuby didn’t win the Script Bowl, unpredictably Clojure did. The
event was enjoyable, but for me my favorite part was creating the demos and
honing my pitch for JRuby, which I’m sure I’ll have the opportunity to reuse in
the future.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="jruby" /><category term="javaone" /><summary type="html"><![CDATA[This past October I was invited to represent JRuby in the JavaOne 2014 “Script Bowl.” A panel where community members from various projects which implement scripting languages on top of the JVM pitch their language to a live studio audience. This year’s panel consisted of a members from the Groovy, Clojure and Scala communities, and me representing JRuby of course.]]></summary></entry><entry><title type="html">Profiling of remote JVMs with VisualVM and JConsole</title><link href="https://brokenco.de//2014/07/07/profiling-remote-jvms.html" rel="alternate" type="text/html" title="Profiling of remote JVMs with VisualVM and JConsole" /><published>2014-07-07T00:00:00+00:00</published><updated>2014-07-07T00:00:00+00:00</updated><id>https://brokenco.de//2014/07/07/profiling-remote-jvms</id><content type="html" xml:base="https://brokenco.de//2014/07/07/profiling-remote-jvms.html"><![CDATA[<p><strong>Note:</strong> I originally posted this
<a href="http://hackers.lookout.com/2014/06/profiling-remote-jvms/">here</a>, on the
<a href="http://hackers.lookout.com">Lookout hackers blog</a>. I encourage you to check
the blog out and follow <a href="https://twitter.com/lookouteng">@LookoutEng</a>.</p>

<hr />

<p>Recently I found myself hosting a bit of a “bake-off competition” between
servlet containers for JRuby applications here at
<a href="https://www.lookout.com/about/careers">Lookout</a>.</p>

<p>The goal of the bake-off was to determine whether we should host some
<a href="https://github.com/jruby/warbler">warbled</a> JRuby applications in Tomcat or
Jetty. Not having a huge amount of experience, or bias, towards one or the
other I elected to run a simple <a href="https://github.com/rtyler/hellowarld">Hello
Warld</a> application in both and see how
well the containers performed.</p>

<h3 id="the-bake-off-environment">The Bake-Off Environment</h3>

<p>For the bake-off of servlet containers I used to identical EC2 instances. EC2
instances were chosen instead of running both containers on my local machine to
keep the machines consistent, isolated and more representative of the
environment we would be running webapps in. The test bed specs were:</p>

<ul>
  <li>Ubuntu 12.04 LTS</li>
  <li><code class="language-plaintext highlighter-rouge">m1.small</code> instance size (hey, I’m not made of money!)</li>
  <li>us-west-2 region</li>
  <li>A security group with everything open to the other machines in that security
group. This is important for later.</li>
  <li>OpenJDK 7 (u55)</li>
</ul>

<p>The machines were then provisioned with the Tomcat 7 and Jetty 6 respectively,
only because those were available directly from the native packages on Ubuntu 12.04.</p>

<p>Both containers were also set up to perform hot-deploys; a feature which relies
on live-reloading of an application without restarting the JVM.</p>

<h3 id="problems-ahoy">Problems, ahoy!</h3>

<p>After performing a number of successive hot-deploys in Tomcat, I found my logs
clobbered with the following errors:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
</code></pre></div></div>

<p>The actual problem here will need to be covered in another blog post, but
something fishy was clearly going on with hot-deployments in Tomcat.</p>

<h2 id="profiling-in-the-cloud">Profiling in the cloud</h2>

<p>My favorite tool for understanding a running JVM is
definitely <a href="http://visualvm.java.net/">VisualVM</a>, with
<a href="http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html">JConsole</a>
running in a close second place. Fortunately, both tools are quite easy to set
up for connecting to remote JVMs.</p>

<h3 id="setting-up-jstatd">Setting up jstatd</h3>

<p>Previously I mentioned the importance of the EC2 security group. It’s important
that port <strong>1099</strong> is open within the security group. This is the port
<a href="http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstatd.html">jstatd</a>
runs on by default. <code class="language-plaintext highlighter-rouge">jstatd</code> is what will provide VisualVM with live
instrumentation data from the JVMs running on the machines.</p>

<p>It’s also important to provide a liberal security policy file to <code class="language-plaintext highlighter-rouge">jstatd</code>. If
this were anything more than a simple test implementation, I would recommend a
more restrictive policy, but we’re optimizing for easiness here, so a wide open
policy is fine:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grant codebase "file:${java.home}/../lib/tools.jar" {
    permission java.security.AllPermission;
};
</code></pre></div></div>

<p>Save the policy above into a file named <code class="language-plaintext highlighter-rouge">jstatd.policy</code>, which we can run
on each machine:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ec2-tomcat% sudo jstatd -J-Djava.security.policy=./jstatd.policy &amp;
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ec2-jetty% sudo jstatd -J-Djava.security.policy=./jstatd.policy &amp;
</code></pre></div></div>

<h3 id="jmx-for-interactivity">JMX for interactivity</h3>

<p><code class="language-plaintext highlighter-rouge">jstatd</code> only gives us half the picture we want. We also want
<a href="http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html">JMX</a>
to be configured for both containers to allow us to extract more information
and interact with the running JVMs.</p>

<p>Again, we’ll set up very liberal security policies since this is for testing
only! The native packages for both containers put a file in <code class="language-plaintext highlighter-rouge">/etc/defaults</code>
which contains a <code class="language-plaintext highlighter-rouge">JAVA_OPTS</code> variable, to which the following should be added:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=1098
</code></pre></div></div>

<p>After restarting the container processes, they will now have the right JMX
settings and we should be able to finally be able to connect VisualVM or
JConsole to the JVMs.</p>

<h3 id="proxying-for-connectivity">Proxying for connectivity</h3>

<p>In order to give tools running locally on my machine access to these processes
running inside of a security group within EC2, I’ll rely on <code class="language-plaintext highlighter-rouge">ssh</code>’s ability to
provide a SOCKS5 proxy;</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kiwi% ssh -D 9696 ubuntu@ec2-66-166-66-66.us-west-2.compute.amazonaws.com
</code></pre></div></div>

<p>This will provide a path for both VisualVM and JConsole to use when accessing
the JMX information (port 1098) and the <code class="language-plaintext highlighter-rouge">jstatd</code> information (port 1099) on the
machines running inside of a security group within EC2. While not wholly
necessary, exposing these ports to the wide-open internet seems like a Bad
Idea™.</p>

<h4 id="running-jconsole-with-a-proxy">Running JConsole with a proxy</h4>

<p>JConsole doesn’t have any GUI configuration for a proxy, so it’s necessary to
set some command line parameters:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kiwi% jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=9696
</code></pre></div></div>

<p>Once JConsole is up and running, you only need to enter the EC2 hostname and
appropriate JMX port (1098) to connect to the running JVM:</p>

<p><img src="http://hackers.lookout.com/images/post-images/profiling-remote-jvms/jconsole-with-proxy.png" alt="JConsole with EC2
hostnames" /></p>

<p>After clicking “Connect”, JConsole will use the SSH-based proxy to connect to
the host, and you should be able to poke around with a real live JVM:</p>

<p><img src="http://hackers.lookout.com/images/post-images/profiling-remote-jvms/jconsole-connected-remotely.png" alt="JConsole connected to
EC2" /></p>

<h3 id="running-visualvm-with-a-proxy">Running VisualVM with a proxy</h3>

<p>Unlike JConsole, VisualVM allows for a GUI-based configuration of a SOCKS
proxy:</p>

<p><img src="http://hackers.lookout.com/images/post-images/profiling-remote-jvms/visualvm-proxy-conf.png" alt="VisualVM proxy
configuration" /></p>

<p>With the proxy configuration saved, we can then add a remote host by
right-clicking on “Remote” and selecting “Add remote host”.</p>

<p><img src="http://hackers.lookout.com/images/post-images/profiling-remote-jvms/adding-remote-host-visualvm.png" alt="Adding remote VisualVM
host" /></p>

<p>Provided <code class="language-plaintext highlighter-rouge">jstatd</code> is running on the remote host, your SSH-based proxy is
running and the remote JVM is running, you should be able to connect to the
remote JVM and start profiling it like you would a local JVM!</p>

<p><img src="http://hackers.lookout.com/images/post-images/profiling-remote-jvms/profiling-tomcat-remotely.png" alt="Profiling Tomcat
remotely" /></p>

<hr />

<p>Both JConsole and VisualVM give you access to a lot of the instrumentation data
available from a running Java Virtual Machine, but neither will magically
identify or solve performance problems. There’s still more work to be done to
triage and ultimately resolve those kinds of issues, but at least these tools
give you the information you need to know what’s going on, and <a href="http://cdn.churchm.ag/wp-content/uploads/2014/03/knowing-is-half-the-battle.jpg">knowing is half
the
battle</a>.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jvm" /><category term="jruby" /><category term="visualvm" /><summary type="html"><![CDATA[Note: I originally posted this here, on the Lookout hackers blog. I encourage you to check the blog out and follow @LookoutEng.]]></summary></entry><entry><title type="html">Catch me at JRubyConf EU 2014</title><link href="https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014.html" rel="alternate" type="text/html" title="Catch me at JRubyConf EU 2014" /><published>2014-07-06T00:00:00+00:00</published><updated>2014-07-06T00:00:00+00:00</updated><id>https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014</id><content type="html" xml:base="https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014.html"><![CDATA[<p>This has already been posted on the <a href="http://hackers.lookout.com/2014/07/join-us-at-jrubyconfeu">Lookout hackers
blog</a> but I figured
I would repost on my personal blog in lieu of actual content.</p>

<p>My colleague <a href="https://github.com/ismith">Ian Smith</a> and I will be presenting a
talk at <a href="http://2014.jrubyconf.eu/">JRubyConf EU 2014</a> titled:</p>

<blockquote>
  <p><strong>Building a scalable messaging fabric with JRuby and Storm</strong>.</p>
</blockquote>

<p>The abstract can be found below, but since this is my personal blog I’d like to
expand a bit more on why we’re giving the talk.</p>

<p>Last year my team and I deployed <a href="http://activemq.apache.org">ActiveMQ</a> in
order to provide an inter-service messaging bus between a new product we were
developing and some legacy infrastructure at <a href="http://www.lookout.com/about/careers/">Lookout</a>.
Alongside ActiveMQ we deployed a number of different worker daemons to consume
and dispatch messages. These were <a href="http://jruby.org">JRuby</a>-based processes
that polled a <a href="http://stomp.github.io/">STOMP</a> connection for new messages and
then performed some amount of “work.”</p>

<p>In the process of building out all of this infrastructure we learned a couple
of important lessons:</p>

<ul>
  <li>ActiveMQ scales like MySQL. That is to say it kind of <em>doesn’t</em> scale, the
most effective way to scale out a number of ActiveMQ brokers is to perform
some amount of application-layer “sharding” across message brokers. We did
not do ActiveMQ any favors in attempting to scale it out effectively, so minus one
point us.</li>
  <li>Many of our problems became less of shoveling work from a single app server
into a work-queue, where tools like <a href="http://sidekiq.com">Sidekiq</a> excel, and
more about complex message routing and processing, which
<a href="https://storm.incubator.apache.org/">Storm</a> was built specifically to solve for.</li>
  <li>If you provide a good stream of events, everybody, <strong>everybody</strong> will want
to take part in it. One of the unexpected results of deploying ActiveMQ and
some messaging facilities was that nearly every team in the company then wanted
to take part in the event streams. This wouldn’t have been a problem if we
had planned to become the “messaging team” or even had a roadmap to scale out
the deployment and managing of messaging infrastructure with ActiveMQ+STOMP.
Alas, we did not, and quickly ran into scaling challenges both technically and
organizationally.</li>
</ul>

<p>In our talk, Ian and I will discuss some of these lessons coming from our “old
messaging infrastructure” along with some of the important lessons that we’ve
learned moving to the newer system. Naturally, neither Storm nor
<a href="http://kafka.apache.org">Kafka</a> are silver bullets for scalability, but
I believe that they’re the right path to moving towards a broader Lookout-wide
messaging fabric.</p>

<p>As previously mentioned, this talk will be at <a href="http://2014.jrubyconfeu.org">JRubyConf
EU</a> which will be held <strong>August 1st</strong> in Potsdam,
Germany. We hope to see you there!</p>

<h4 id="abstract">Abstract</h4>

<blockquote>
  <p>As Lookout has grown the number of backend Ruby services the need for
reliable, asynchronous service-to-service messaging has gone from “nice to
have” to “absolute requirement.”</p>

  <p>Our first attempts included some names you may be familiar with: <a href="http://activemq.apache.org/">ActiveMQ</a>,
<a href="https://github.com/resque/resque">Resque</a>, <a href="http://redis.io">Redis</a>, and
<a href="http://sidekiq.org/">Sidekiq</a>. As our infrastructure grew, we found we were
reinventing many of the concepts “Storm,” an open source real-time
computation/stream-processing system, was specifically designed to handle such
as message routing, durability, streaming from multiple inputs, delivering to
multiple outputs, etc.</p>

  <p>In this talk we’ll cover how we built a scalable service-to-service messaging
fabric on top of Storm and Kafka, with <a href="http://jruby.org">JRuby</a> playing a starring role.</p>
</blockquote>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="jruby" /><summary type="html"><![CDATA[This has already been posted on the Lookout hackers blog but I figured I would repost on my personal blog in lieu of actual content.]]></summary></entry></feed>