Silent Blog and JRuby

Posted by – 24/09/2008

I’ve been silent in this blog last few days, but that has an explanation: I’ve been trying to make JRuby 1.1.4 work with one of my scripts.

The problem is that after having done all the tweaks I can imagine, I still can’t get enough performance with Ruby 1.8.7 (latest etch-backports). Our client will not allow Ruby 1.9 in the server (what is really a pity, for the performance boost I had with Ruby 1.9 is awesome!), but it already have Java6… So the only option I have left is trying JRuby beast.

Since our script deals with system stuff, it uses syslog a lot, and that is where the main problem seems to be. Syslog support is new in JRuby, has had some implementation problems, and sure are not something to rely on right now… so I dropped it from the script, and it run! Twice as fast (not as good as Ruby 1.9, though)!

There are some other problems with this script and JRuby, more important ones being (1) at_exit doesn’t work; and (2) errors are not easy to backtrace (when JRuby fails it seems to mess up with the backtrace stack), but not preventing it to work…

So… with the increased performance of JRuby, and after fixing those minor glitches, I was still left with the syslog problem… Until I investigate some final solution (I think I’ll have to use some Java native syslog library – given such a thing exist), I’ve split the script in “performance-boost needing” and “syslog-needing” parts; the first is using JRuby, and the second, Ruby 1.8.7… They communicate using sockets (I know… ugly… I would like to use DRuby, but I would not introduce another point of failure in an already messy situation) and the overall performance was brought to a satisfactory level.

So far, it’s been interesting to study the issue… Mainly because I haven’t used JRuby since it’s early versions, and it has improved a lot. But also because I read a lot about the future of Ruby (bytecode compilation, YARV and so on), and it made me even happier with my primary-do-it-all programming language.

Now I’ll try to compile java bytecode generated by JRuby into a native binary with GCJ :-D. Let’s see if that is do-able…

Updated 2008-09-24 18:03:00: As you can see in the comments, syslog actually works. I figured this out this morning, but JRuby Subversion already had a patch. Anyway, I submitted another bug I found.

4 Comments on Silent Blog and JRuby

  1. spectra says:


    Actually I just found the syslog bug. I was prepared to send the following patch against syslog.rb to the issue tracker:

    --- syslog.rb.old       2008-08-28 15:35:09.000000000 -0300
    +++ syslog.rb   2008-09-24 11:27:23.000000000 -0300
    @@ -25,10 +25,10 @@
       module Foreign
         # methods
    -    attach_function "openlog", :open, [:string, :int, :int], :void
    -    attach_function "closelog", :close, [], :void
    -    attach_function "syslog", :write, [:int, :string, :string], :void
    -    attach_function "setlogmask", :set_mask, [:int], :int
    +    attach_function :open, "openlog", [:string, :int, :int], :void
    +    attach_function :close, "closelog", [], :void
    +    attach_function :write, "syslog", [:int, :string, :string], :void
    +    attach_function :set_mask, "setlogmask", [:int], :int
       class << self

    … but then I decided to check the subversion, and there it was already. I still have some minor glitches, but today I was able to run the script with logging. Still no luck with at_exit, though… That will go to issue tracker ASAP.

    Thanks for your comments.

  2. Shot says:

    In the future, if you have further performance issues with Ruby, first try to hand-compiling it. From my experience, the Debian/Ubuntu packages are about 40% slower (due to—with-phtreads being used in the packages), and the word on the streets is -O3 and the proper -mtune/-march can give you another 30%:

  3. 1. If you haven’t filed bugs for the syslog issues, you should do so. Even if they’re duplicates, it will help get some attention to the problem.
    2. If you’re looking for more performance, try running JRuby with—server. For longer-running scripts the “server” setting does more optimization, at a cost of somewhat slower startup and warmup time.
    3. We seek to make JRuby consistently faster than 1.9, so if your particular case is still slower than 1.9 with—server, there may be a bug. File an issue for it, and if you’re able to reduce it to something specific that’s slower, we will probably be able to fix it.

  4. ””“(I think I’ll have to use some Java native syslog library – given such a thing exist)”””
    log4j will do everything and then some for logging in java.

Leave a Reply

Your email address will not be published. Required fields are marked *