Tuesday, December 9, 2008

New Ruby Shootout 12/08

Antonio Cangiano has released another Ruby Shootout which are always fun to check out.  Looks like Ruby 1.9 is leading the pack with JRuby 1.1.6RC1 close behind.  Some of the JRuby tests failed which I'm sure pissed Charlie off!

Friday, December 5, 2008

JRuby vs. Java speed (re: Stochastic Simulation with SSJ)

Just read Ali Rizvi's blog post about "JRuby: Stochastic Simulation with SSJ" and decided to take a look at the implementation real quick... of course the Java version will be much faster, but the numbers given seemed a little strange.  After setting up the environment and running the tests, I saw the major slowdown as expected, then I decided to take a look at the Ruby code to see if I could speed things up a little.  This was done rather quickly, if you have better result... please share!

First, the Java version:
real    0m7.960s
user    0m7.839s
sys     0m0.056s

The JRuby version took too long to run (I'm pressed for time) so I added a few options to the runtime:

jruby -J-Djruby.compile.fastest=true --server collision.rb
real 3m55.834s
user 3m53.684s
sys 0m2.355s

Not as bad as reported by the blog ref'd above... but still pretty bad. I had a hunch the loops were what was killing the time and made the following changes to the collision.rb file:

@k.times { |i| @used[i] = false}
changed to:

That brought the time down a bit:

real 1m1.430s
user 1m1.344s
sys 0m0.538s

It would seem loops are a sore spot. (kinda expected? the loop for setting happens in the Java impl) Decided to make one last change to see what happened. I condensed the "generate_c" method back into "simulate_runs" method to get the loops in one place. Some (not much) benefit was shown in my tests:

real 0m59.081s
user 0m59.027s
sys 0m0.502s

CONCLUSION: Yes, straight java is faster. Yes, there are ways to tune your Ruby to make things a bit more efficient. Yes, I'm sure there are other ways to make this run faster. I think prototyping this sort of thing in JRuby is just fine... then when you need more perf (if this stuff will be called from say a JRuby on Rails app) you can code it up in Java (Collision.java) and just call that from JRuby layer.

Here is the final collision.rb I ended up with :

require 'java'
require 'ssj.jar'

import 'umontreal.iro.lecuyer.rng.RandomStream' import 'umontreal.iro.lecuyer.stat.Tally' import 'umontreal.iro.lecuyer.rng.MRG32k3a' class Collision def initialize(k, m) @k = k @m = m @lambda = m * m / (2.0 * k) @used = Array.new(k, false) end
def simulate_runs(n, stream, stat_c)
n.times do
c = 0
@m.times do
loc = stream.nextInt(0, @k-1)
if @used[loc]
c += 1
@used[loc] = true
puts stat_c.report(0.95, 3)
puts " Theoretical mean: #{@lambda} "

def self.run
stat_c = Tally.new("Statistics on collision")
col = Collision.new(10000,500)
col.simulate_runs(100000, MRG32k3a.new, stat_c)



Thursday, December 4, 2008

JRuby getting lots of attention lately

Of course while I'm away, toiling on projects using Spring/Hibernate, JBoss/EJB3/GWT things with the JRuby world get really exciting.  New versions of JRuby are rolling out everytime you turn around and the gems and projects that run on jruby are getting refreshed daily it seems.  Here are just some of the highlights I've seen fly by...

Hopefully I'll get some time of the holidays to dust off some of my (now old) projects and give them a whirl with all the new hotness... I'd love to do some more benchmarks and see if the thread-safety of Rails does anything to improve things on jruby outright.  Of course, I'll post results if I can get around to it.

For a sort of realtime look at what folks are doing with jruby:

Tuesday, September 9, 2008

So where is Pogo?

I just remembered a while back AT&T was looking to get into the browser market with Pogo.  Some of the features look interesting... but where is it?

Tuesday, September 2, 2008

Taking a look through Google Chrome's eyes

Google just released their new browser on the windows world... figured I'd give it a shot.

google chrome

Google Chrome

Have already found and reported a few minor issues... some javascript horking.  In all, I dig the UI.  Could maybe use a "manage bookmarks" feature.  Maybe it's in here somewhere. 

(NOTE: posting this from chrome right now... found another JS issue.)

Thursday, July 17, 2008

Interesting... that is all

Just read this post...

Just saying... it's interesting.  Seems to be a lot of the benchmarking bug going around these days.

Thursday, July 3, 2008

JRuby slowdown from Rails 2.0.2 to 2.1.0

Before you decide to bring your current JRuby on Rails app to the latest 2.1.0 version... you may want to take a look at the performance. I was running the console benchmark from this blog post with jruby trunk and saw some numbers I wasn't expecting:
[sourcecode language="ruby"]
in console: 6.times {puts Benchmark.measure {10000.times {Person.find :first}}.total}
4.47 : jruby 1.1.2 & rails 2.0.2 (jdbc) (best out of 6 runs)
5.43 : jruby 1.1.2 & rails 2.1.0 (jdbc)
4.12 : jruby 1.1.3 (trunk) & rails 2.0.2 (jdbc)
5.06 : jruby 1.1.3 (trunk) & rails 2.1.0 (jdbc)

JRuby trunk IS faster than 1.1.2 as expected, but JRuby overall is experiencing a (pretty significant) slowdown when running Rails 2.1.0.

Hopefully finding the culprit for this slowdown will open the floodgates for improving JRuby on Rails performance.

Friday, May 30, 2008

Loss of internet connection...

When you have to write something like this (on mac), things are bad mmmmkay?

[sourcecode language="ruby"]
loop do
if system('curl -m 2 http://google.com')
system("say \"Mike! Cox Communications has finally fixed the lines, we're back in business!\"")

Tuesday, May 27, 2008

Syntactic Sugar...

Was reading this post about Groovy syntactic sugar... closures and ++ operator are nice... but you could open up Hash and Array to get the other stuff.

[sourcecode language="ruby"]
# working with hashes
class Hash
def method_missing(name, *args)
fetch(name) if has_key?(name) or nil
user = {:save => true, :destroy => false}
puts "--hashes"
puts "save? : #{user.save}"
puts "destroy? : #{user.destroy}"

# working with arrays
class Array
def method_missing(name, *args)
collect {|i| i.send(name)}
puts "--upcase"
puts ["Mike", "McKinney"].upcase

# fetching attributes of arrays
name1 = {:first_name => "Mike", :last_name => "McKinney"}
name2 = {:first_name => "Bo", :last_name => "Diddley"}
names = [name1, name2]

puts "--first names "
puts names.first_name
puts "--last names "
puts names.last_name
puts "--middle names "
puts names.middle_name

Of course you would want to look a little closer at the implications this type of patch would have on your code, but it's sure nice how flexible ruby can be.

Tuesday, May 13, 2008

JavaOne '08 - Script Bowl apps for JRuby released

This year's JavaOne had an interesting competition... the Script Bowl.  Pitting 4 different languages (Groovy, Scala, Jython & JRuby) on the JVM against each other in three different categories.  (Rich Client Application, Web Application and an Open event)  Check the results here on Rags' blog.

Headius just posted the JRuby Script Bowl artifacts for your viewing pleasure.  Anyone know if the other languages have posted their apps/code?

Monday, May 5, 2008

Re: RSS Feeds for Subversion

I was reading a friend's blog post about RSS feeds for Subversion repositories earlier... he couldn't find anything that was not written in a scripting language which he has no access to in his environment... he needed a Java based solution.  He solved his problem with a war.  I came back to this after dinner (and a few glasses of wine) and decided to show him another way to solve this problem on the JVM... (you knew it was coming Matt.)

Assuming you already have JRuby setup (of course you do), we'll do the following to get the one gem we'll need:
[sourcecode language="css"]
> jruby -S gem install rscm

The RSCM (Ruby Source Code Management) gem provides a nice interface to SVN, CVS, ClearCase, StarTeam, etc. and since it's written in pure Ruby, it runs just fine on the JVM.

Then download this file. Not much to it, 106 lines and 45 of that is the template for creating the rss xml doc.

Command line has a few options, here's an example:
[sourcecode language="css"]
> jruby -J-server server.rb -p 8080 -m svnlog
or just get help
> jruby server --help

-p, --port=3003 Which port do you want the server to listen on.
-m, --mount-point=svnrss http:///
-h, --help Show help (this).

Point your RSS reader @ the following: http://localhost:8080/svnlog?url=http://svn.codehaus.org/jruby/trunk/&num_revs=15 and here's what you get:


(Firefox 3 beta)

Nice, think I'll actually use this.

Thursday, May 1, 2008

Some Rails perf numbers on JRuby 1.1.1 part 2 (Linux, JDK 6)

After this post, I got a lot of suggestions to re-run the benchmarks using JDK 6. I'll let you read the previous post to see what exactly I did... here's what the runtime looks like for this run:

  • Ubuntu 7.10 / Dell Latitude D830

  • Ruby 1.8.6

  • JRuby 1.1.1

  • JDK 1.6.0_03

*NOTE: could not run benchmarks without jdbc drivers (jdbcmysql adapter) due to JRUBY-2303

First the Rails console benchmark numbers:

Rails console numbers

[sourcecode language="css"]
5.15 seconds - Ruby console
2.41 seconds - JRuby console (jdbc)

(side-note: re-running the console test with JDK 5 on same machine, best out of 6 runs: 3.31 seconds)

Next the Web Server numbers: (numbers in parens are the number of benchmark runs)

Rails ab numbers

[sourcecode language="css"]
272.84 Mongrel (6)
257.02 GlassFish (40)
235.17 Mongrel (jruby/jdbc) (20)
188.12 Glassfish (-n 2, 20)
179.76 Mongrel (jruby/jdbc) (10)
168.52 Glassfish (6)
161.12 Mongrel (jruby/jdbc) (6)
151.04 Glassfish (-n 2, 6)
131.89 Tomcat 6 (30)
105.72 Tomcat 6 (6)

The console numbers show JDK 6 really kicking in... contrast that with the numbers for actually serving the Rails app and you can see there is still some work to be done to make Ruby on Rails serve faster on the JVM.

Again, not very scientific, just something to show where things stand for now. If you have better benchmarks, please link to them from the comments section below.

Monday, April 28, 2008

Some Rails perf numbers on JRuby 1.1.1

UPDATE: Next up will be the same benchmarks using Java 6 on ubuntu.

Just before JRuby 1.1.1 was released, I was surfing around and found this post which shows JRuby running basic Rails bench tests slower than MRI. I wondered what those numbers would look like now, so I got to testing.

I started by downloading the latest binary release of JRuby here.

I setup a Rails app following the theme mentioned by the blog post above, then ran the console benchmark 6 times with each runtime and list the lowest time below:
[sourcecode language='css']
jruby -J-server script/console production
>> Benchmark.measure {10000.times {Person.find :first}}.total
=> 10.352999925613403

ruby script/console production
>> Benchmark.measure {10000.times {Person.find :first}}.total
=> 4.98

Now I wanted to see if the ActiveRecord-JDBC drivers would help the situation:
[sourcecode language='css']
jruby -S gem install activerecord-jdbcmysql-adapter
vi config/database.yml ("mysql" -> "jdbcmysql")

jruby -J-server script/console production
>> Benchmark.measure {10000.times {Person.find :first}}.total
=> 4.134999990463257

console results

Sped things up quite a bit... Now for Mongrel:
[sourcecode language='css']
> mongrel_rails start -e production
Requests per second: 202.27 [#/sec] (mean)

jruby -S gem install mongrel
jruby -J-server -S mongrel_rails start -e production
Requests per second: 96.47 [#/sec] (mean)

# now with adapter: jdbcmysql about the same... got a bit faster after warm-up
Requests per second: 120.05 [#/sec] (mean)

MRI's Mongrel beats JRuby version even after a little warm-up period. I also wanted to see what GlassFish would do :
[sourcecode language='css']
jruby -S gem install glassfish

jruby -S glassfish_rails start ../person_test/
Requests per second: 132.93 [#/sec] (mean)

# now with jdbcmysql adapter
jruby -S glassfish_rails start ../person_test/
Requests per second: 139.96 [#/sec] (mean)

Just goofing around, I used an experimental setting to see what would happen. I repeated the benchmark for some time and you can then really start seeing the JVM 'harden' the execution path... I'm sure the tests above may have benefited in the same way had I let them run but here are the numbers of a glassfish_rails server with 2 Rails instances (probably ran the benchmark about 10-15 times?)
[sourcecode language='css']
jruby -J-server -J-Djruby.compile.fastest=true -S glassfish_rails start -n 2 ../person_test/
Requests per second: 211.64 [#/sec] (mean)

I also wanted to see some numbers for Tomcat 6, a war'd Rails app using Warbler. The numbers were not at all what I was expecting... even though I know things out of the box are not tuned for this type of deployment. The best numbers I could get were:
[sourcecode language='css']
Requests per second: 67.68 [#/sec] (mean)

Rails perf chart

So what does this tell me? JRuby is getting faster each release. There is more work to be done to make JRuby on Rails apps faster. GlassFish is a very easy way to deploy JRoR apps. And last, I am definitely doing something wrong with my war'd depoyment!

I could not find much else in the way of JRuby on Rails benchmarks... if you know of any, please link in comments!

All these benchmarks were run on a MacBook 2GHz Core Duo with 1GB mem., Java 5, JRuby 1.1.1, Ruby 1.8.6, Ruby on Rails 2.0.2, MySQL 5.0.27.

Aloha Color Theme for NetBeans 6.1*

UPDATE: The Aloha theme is included in the Extra Ruby Themes module
for NetBeans.

Finally... (sorry for the wait) The Aloha Color Theme for NB 6.1 is available for download.

The original version for 6.0 (here) had issues coming over. If you have not updated yet, you will want to with this list of features.

Aloha Color Theme for NetBeans

Aloha Look








NetBeans Download the NBM here. NetBeans

After the download, open NetBeans and go to Tools > Plugins. In the Download tab, add the AlohaTheme.nbm and install. To use it, just select it from the Fonts & Colors profile "Aloha."

You will want to go change the "Diff" colors which are not included in the theme (not yet anyway). Color of Added Text: Black, Color of Changed Text: Dark Grey.

Monday, April 21, 2008

JRuby 1.1.1 to be released today!

2 short weeks after the JRuby team released version 1.1 we'll see the next release some time today.  Version 1.1.1 resolves 41 issues and focuses on stability, performance and compatibility according to Charles Nutter.

Issues still exist with JRuby on GCJ and possibly on IBM's JVM 5.  Anyone using these platforms is encouraged to submit bugs or possibly fixes.

The pace on this project is truly amazing...  I plan to write-up a few posts about a recent project I worked on which used JRuby and Rails to speed development, exciting times my friends!

Monday, February 4, 2008

Project PEA - test coverage with a magnifying glass

Matt Harrah recently wrote about his new toy: Project PEA. This thing is like test coverage reporting with a magnifying glass. Matt, Jeff Richley and I have had conversations in the past about the topic and the way test coverage reporting tools can give you a false sense of security.

Project Pea

The idea is to find the spots in your test coverage that may be 'accidental' having been buried beneath too many layers to be effective. (hence the name of the project.)

If you work in an environment with test coverage requirements, you may want to take a closer look at Project PEA.

Friday, January 25, 2008

Aloha Color Theme for NetBeans 6

UPDATE: The Aloha theme is included in the Extra Ruby Themes module
for NetBeans.

UPDATE: Go get the new version for NB 6.1 here.

UPDATE: I've started looking into updating the theme for NB 6.1 (due out in a few days) I'll create a new post and link to the download once it's complete. Thanks for your patience.

I've been giving NetBeans 6 a try lately and I'm enjoying it very much... but I really like the color themes available for TextMate. I'm not a big fan of the defaults and I wanted something different... so I started looking. The Ruby Dark Pastels theme by Jerrett Taylor comes with a plugin download, I found this theme called Fade to Grey by Brasten Sager and then I stumbled upon this color theme by Carmelyne Thompson. The theme Carmelyne created was what I was looking for with a few tweaks. And since I do work with a lot of different file types, I wanted to make sure most if not all the file types held the color theme. So after a few tweaks and writing something to help me create my NetBeans Module file... here are the results:

Aloha Color Theme for NetBeans

Aloha Look






NetBeans Go get NB 6.1 and use the theme on this page instead!!! NetBeans

After the download, open NetBeans and go to Tools > Plugins. In the Download tab, add the AlohaTheme.nbm and install. To use it, just select it from the Fonts & Colors profile "Aloha."

I can't get the CSS to stop painting the keywords neon blue and it can be a little hard on the eyes... if anyone knows how to fix this, please let me know.

Thursday, January 24, 2008

Small, portable http proxy for windows

This is a short one, mostly so I don't forget where to find this tool later.

I needed to monitor some SOAP traffic and do some debugging... just wanted something small, won't take over my work laptop (Win XP) and just show me the HTTP messages raw. Enter TcpTrace, a small footprint http proxy that comes in handy when you need to do some troubleshooting at that level.  Great for junior folks to actually learn something about HTTP protocol and for sticking on your thumb drive and taking with you.

This tool is for windows only, there are plenty for *nix out there... what's your favorite?

Wednesday, January 9, 2008

JRuby / Ruby Continuous Integration with Hudson

Hudson is a great tool for your continuous integration needs. It's very easy to setup and can run/monitor multiple types of tasks. Some have used it for Python and this blog entry will show you how to get Hudson setup quickly for running your Ruby or JRuby tests. (including reporting)

(This step-by-step is assuming you have Java installed on the machine you are using.)

First we'll need to download Hudson here and start our Hudson instance: (just grab the latest stable release)
[sourcecode language='css']
java -jar hudson.war
(see Hudson site for other deployment options.)

Next, grab the CI::Reporter gem we'll need for test results xml formatting :
[sourcecode language='css']
gem install -y ci_reporter
OR for JRuby
jruby -S gem install -y ci_reporter

UPDATE: Make sure you insert the following lines in your Rakefile:
[sourcecode language='ruby']
require rubygems
gem ci_reporter
require ci/reporter/rake/test_unit

Hit your running Hudson instance: http://localhost:8080/ and configure a new build by clicking the "New Job" link. Enter the name of your build and select the "Build a free-style software project" (click OK.)

Configure your SCM data, then scroll down to the "Build" section and select either "Execute Windows batch command" (windows) or "Execute shell" (*nix). This is where we'll call our 'rake test' task using the CI::Reporter gem and specifying a spot for the report XMLs to live:
[sourcecode language='css']
//rake ci:setup:testunit test CI_REPORTS=results
OR for JRuby
//jruby -S rake ci:setup:testunit test CI_REPORTS=results

UPDATE: When using Subversion, it will check things out into a sub directory of your "workspace" (found ~<user running hudson>/.hudson/jobs/<your job name>/workspace) If you are checking out 'trunk' and don't specify a different name for the directory, your shell execution settings should look like this:
(be sure to know how your SCM works before applying the following)
[sourcecode language='ruby']
cd trunk
//rake ci:setup:testunit test CI_REPORTS=results

This will setup the CI::Reporter and place the XMLs in the "results" directory for us.

We are almost done, now under the "Post-build Actions" section, check the "Publish JUnit test result report" box and enter the following in the "Test report XMLs" field:
[sourcecode language='css']

Now click Save and go test it out... Select your newly created job from the Dashboard.

Click the "Build Now" link... done. After a few builds you should see a graph on the job's main page that looks like this:

If you have a failure, you can drill down by clicking the "Test Result" link on an individual build's page.

Clicking on an individual failed test's name will show you the output from that failure

That's all it takes, pretty simple and works like a charm. Now you can go back and play with the other settings Hudson has, triggers, scheduling, job artifacts, notifications... you could even have a job that prepares a build by generating all your static content so your server doesn't have to take the initial hit after startup. (web projects)

If interested, there is a way to create plugins for Hudson.

Tuesday, January 8, 2008

Latest JRuby release is faster

The latest JRuby release (Jruby 1.1RC1) improves on the past numbers showing the recent push for speed. I have been out of the loop for a while but am not surprised to see these improvements.

But speed was not the only thing happening in the JRuby camp lately :
- 143 issues resolved since JRuby 1.1b1
- Landing of Java port of Oniguruma (Joni)
- Most Posix methods supported (e.g. stat, kill, getuid)
- Latest Rubygems 1.0.1, RSpec 1.1.1, and Rake 0.8.1 gems
- Updated standard library to be Ruby 1.8.6 compatible

more details here

Makes one wonder... with JRuby's speed increases, Java integration (remember Java is everywhere) and a great tooling story... when does JRuby replace Rhino as an alternate pre-packaged language in the JDK? (or the JRE for that matter?)