syntatic

Archive for the ‘programming’ Category

The Closet JRubyists

with 15 comments

For too long we’ve let the JRuby core contributors be the only voice for JRuby. I for one am guilty of taking and taking and taking from the tireless and thankless work the JRuby team has done. Charles, Ola, Tom, Nick, Vladimir and many others need to be thanked.

Almost all of the JRuby projects I’ve been aware of or a part of are nowhere to be found on blogs, twitter or any other techno-coder communication flavor of the month. These projects aren’t going to become popular or have the codista spotlight on them. Most JRuby work is done in the deep inner workings of the corporate bureaucratic sinkhole that is enterprise IT. JRuby work is hidden behind non-disclosure agreements and kept secret because of the technological edge secrecy provides. The great stories haven’t been told and Charles is only able to hint at them because they really aren’t his to tell.

This is one such story and I hope that this post encourages other JRubyists to speak up and at least share parts of their JRuby experience. You owe it to the JRuby team and the Ruby community in general.

I’ll start out by being blunt and if you want to dismiss the rest of the post due to the next sentence then go ahead and move along because this post is not for you. JRuby is fantastic. The rest of this post will hopefully explain why that statement is true.

I joined a project that started out using MRI to wrap a C library, which built into a gem. The C library is a financial analytics package used to price instruments and extract contract specifications. Working in C with MRI was easy. The Ruby C API methods are simple and you almost get the sense you’re working in Ruby. Everything was lollipops and gumdrops just as working with Ruby should be. A rails application was built to display data provided by the gem. As the rails community moved through new deployment strategies so did we moving from webrick to mongrel with lighttpd, etc.

Then some of the business specifications required pricing to be done on hundreds of thousands of instruments at a time. An order of magnitude change in usage made speed and memory usage become very important. Pricing that many instruments in 3 months is not helpful. It needed to be done in parallel.

With this many instruments needing to be priced my team and I created a simple system for distributing the data and processing it in parallel using DRb similar in many ways to Hadoop. Had we been using JRuby at the time Hadoop would be perfect to wrap, but MRI didn’t give us that option.

Right around this point in time MRI became a huge bottleneck. MRI wasn’t going to handle the over 6 million objects we needed to push through DRb and even if it could get data to the workers on a grid of machines it couldn’t fully utilize all the cores on each machine. A combination of running out of memory and MRI failing to fully utilize all the cores of 64-core servers ground the project to a halt.

JRuby 1.0 had just been released and was starting to gain some traction. A 1.0 project? Certainly that can’t handle these problems. With nowhere else to go we took part of the C Ruby API and moved to a C, JNI, Java and JRuby stack. The new stack of tools wasn’t lollipops and gumdrops, but if it worked then who cares? Not me. I enjoyed the polygot work passing ruby objects into C callbacks and unit testing C from JRuby. Mind streaching stuff.

Turns out JRuby had no problems managing 8GB of memory and 6 million plus objects being passed around over DRb. Having the JVM do memory management for your Ruby objects isn’t that bad. I didn’t have to care about it anymore and not caring about the JVM is light years ahead of caring about MRI memory management. Yes, there is real value to using the JVM.

Additionally, JRuby fit into the rest of our MRI system because we weren’t having any problems with MRI talking to JRuby over DRb. I ran into a few problems with IO and Socket, but Charles and Ola were available via IRC and the problems were fixed in a matter of days. The availability of the JRuby team is something I haven’t found in any other community. Charles always put my questions before his other tasks and if you know anything about the man, he is busy. I don’t know how many talks he’s done recently, but his twitter messages list so many cities I’m not sure where he lives anymore.

The initial pricing times came in at around an hour and fifteen minutes. Not bad considering the client was ok with 2 days. JRuby FTW!

Now the story could end here and I’d consider the transition to JRuby a success, but the story goes on.

Tweaking the JVM options allowed us to move the time to about 45 minutes once we upgraded to JRuby 1.1.1. I added some of my findings to the performance tuning wiki page, which you can find here. When was the last time you heard of someone passing some options to MRI’s garbage collector and see performance increases?

Exporting this much data turned out to be a problem as well. Excel’s 256 column limit wasn’t to happy about my 9,000+ column files and the standard ruby spreadsheet gem had trouble handling anything more than 7MB. Fortunately, the Apache POI (Java) project could handle some these problems as well as other features like auto-sizing columns and freeze panes, which no other MRI compatible gem could provide (Yes, there are Ruby POI bindings). I never thought I’d enjoy working with POI/Excel’s API, but JRuby plus POI libraries had me smiling. Excel with a ruby feel rocks. Using JRuby to wrap pre-existing Java solutions is a great way to sleep at night.

Next we moved our Rails apps over to JRuby by deploying them as wars in JBoss.  Managing the mongel problem was gone and JBoss turned out to be much faster anyway provided you give it enough memory. Nick Seiger has done some great work with warbler and the process was a breeze.  Unfortunately, with the number of apps we moved over the DBAs were starting to get upset about the 60+ database connections we used. Rails 2.2 wasn’t around yet so connection pooling inside of Rails wasn’t an option, but using JNDI inside of JBoss worked perfectly. Using prexisting Java tool’s with an adapter written by the JRuby team made my job a lot easier again.

Meanwhile, JRuby was still releasing new versions. Using 1.1.3 moved our pricing time to about 15 minutes. Yes, from 1 hour and 15 to 15. There were some other tweaks we made along the way, but the most significant improvements came from JRuby itself. In it’s current state the C/Java/JRuby API is now exposed through Merb (http/json), DRb (druby), Rails (http/xml, http/html) and an Excel plugin and more opportunities are ahead.

We’re able to upgrade to a new version of JRuby within a day of release. Yes, it is that stable and easy to switch. Yes, 1.1.5 is currently in our production environment. Upgrading to new versions of MRI was usually a nightmare for me so I welcome the stability. JRuby being a jar has some wonderful benefits.

I won’t go into detail about the other libraries we’ve wrapped with JRuby including JFreeChart and QuicKFIX/J. I won’t go into detail about using JRuby with CORBA or RMI and the many other tools that become available to you with the use of JRuby.

Currently, MRI isn’t even installed on our production servers and I don’t see it being installed in the future. Most if not all the ways that the data is available or usable is due to JRuby. JRuby made my job much easier and many of the features I’ve implemented possible. Give it a try.

Advertisements

Written by syntatic

November 25, 2008 at 11:11 am

Posted in programming, rails

Tagged with

MacPorts erlang “Bus error” due to Mac OS X 10.5.3 Update

with 11 comments

The past few weeks, I’ve used my train ride home to dig deeper and deeper into erlang. Then after an OS X update released on May 28, 2008 my macports erlang installation stopped working! Running erl caused a “bus error” to occur.  Trying to recompile erlang caused the same bus error to occur.  Directions below work whether you have an existing erlang installation or you’re trying to compile erlang without prior installation.

Here’s how I was able to get it working again:

Open the erlang portfile with your favorite text editor, I prefer vi.

cd /opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/erlang
sudo vi Portfile

Delete this line from configure.args attribute:

--enable-hipe \

The MacPorts configuration doesn’t depend on the enabling of HiPE and erlang will work fine without it. By default HiPE (Hi-Performance Erlang) isn’t enabled or supported on Mac OS X so I’m not sure why the Portfile enables it. HiPE is a project aimed at creating a faster Erlang by compiling to native code. You can find out more about HiPE here.

Reinstall erlang:

sudo port uninstall erlang
sudo port install erlang

You should see a message that says: Portfile changed since last build; discarding previous state.

Use erlang again!

If you want to know when the MacPorts issue is solved you can follow the Trac ticket here.

Written by syntatic

June 12, 2008 at 8:16 pm

Posted in erlang, programming

Tagged with , ,

Impedance Matching

leave a comment »

As I’ve moved further into software development consulting, I’m becoming more aware of the role that empathy plays in all client relationships. When a client calls because disaster has struck their software, it is imperative that I match their level of concern. If my level of concern doesn’t match their level then I’ve failed as a consultant. I can deliver software on time. I can estimate projects accurately. I can have technical mastery. If I can’t be in their shoes and convey that state to them then I’m not developing a long-term relationship. Genuinely share in their work by staying on the same page.

Impedance matching isn’t solely about the words that you say or write. Your overall attitude and tone of voice matter too. Additionally, it’s important to recognize the form of communication used has implicit levels of concern and care. Impedance matching is the act of meeting your clients social attitude, orientation and behavior to maximize communication transfer and minimize problems with the client.

In my realm of work receiving messages often occur via instant message. Unfortunately, instant messages are easy to overlook and relay little context. Receiving a message that says “the server is down” can mean hundreds of different things. Most of them require a simple reply, “I’ll take a look.” Receiving a message that says “SERVER!! DOWN!!” means that the instant messaging needs to stop. While the client is choosing to use instant message the amplitude of the conversation is far beyond any instant message can convey appropriately. Pick up a phone, their impedance demands it.

How I communicate over instant message changes drastically with each client. Most of the time, I think it is best to adopt whatever format the client uses. If they write in complete sentences with capitalization and punctuation then I meet that formality. I let them set the stage for professional communication.

As consultants we want our clients to have positive feelings about us. We want the work to be collaborative instead of adversarial. We need to bend our thoughts and actions to meet theirs. As consultants it is our job to be in their shoes and earn their trust.

Written by syntatic

April 28, 2008 at 8:32 pm

Tools in the Studio

with one comment

Process

Obtiva’s Studio is busy churning out projects and I thought it would be good to let the rest of the world what we are up to. Most of our rails projects are now using CruiseControl.rb, Zentest, restful_authentication, gems, query_trace, attachment_fu, Rcov, redgreen, exception_notification and mocha. While the list may seem long we are always looking for new tools. If you have any suggestions please comment.

As a team we’ve setup growl integrations for cruise, autotest and redgreen which is strongly suggested. Make TDD easier for yourself. As a team we really need to put out a tutorial on how to set all of this up properly. In my opinion you are doing yourself a disservice without them.

A quick side note, grep -r is mostly dead around here due to ack. Try ack, you’ll love it.

Interests

We’ve also pushed a lot of our interest into JRuby and Erlang. We are all extremely excited for the opportunities those two tools will provide. JRuby’s memory usage have our mouths drooling. If you are not paying attention to Charles Nutter’s blog you are missing out! The pace of everything surrounding JRuby is astounding. Merb and Sinatra are on our radar.

People

Joseph Leddy is deep in the bowels of ActiveWarehouse and FasterCSV where he is making millions of SQL rows consumable for our clients. Joseph is also exploring ETL Tool. He’s been aggressively implementing state machines alongside access control also. Tools unique to Joseph are query_analyzer and tail_logs which I’m eager to take a look at. Joseph recently implemented some multi-server file uploading using BackgrounDRB with tests!

Nate Jackson’s work involves sphinx via acts_as_sphinx mashed into will_paginate and aspell. He’s created an intelligent word suggestor for misspelled words and phrases using raspell. Nate spent a day or two scraping the web with hpricot, WWW:Mechanize , csspool and sass. Nate’s also pushing the studio into NetBeans for Ruby, RSpec, Dvorak and Leopard. Nate likes to include svn_tools and dot.rake in his projects.

Dave Hoover‘s working on innovative interfaces with Ajax and BackgroundDRB. Dave has picked up AR::Extensions as a hammer for memory and speed intensive ActiveRecord imports. He’s also weaving together fleximage and attachment_fu in a few projects. I don’t know much about it yet, but Dave seemed please with ZIYA and Flash chart delivery. Dave’s spent some of his time plunging into Sinatra too. Dave’s editor of choice is Textmate. Other things in his camp include: liquid, RedCloth, and chronic.

Dave also released a gem called TamTam using hpricot that will inline css. You can find the gem here. Dave and Nate paired up to create Obtiva’s first OS X widget here. I paired up with Dave to create a rails plugin for TamTam too which is named inline_css.

Ryan Platte has put together some sweet mashups with GWT, AIM Presence API, BackgrounDRb and ActiveScaffold. While Ryan wasn’t a huge fan of ActiveScaffold I was impressed. His editor of choice is rails.vim. For testing he is using UnitRecord to speed up his test suite among its other benefits. Ryan is now promoting the use of factories over fixtures. Ryan and Gareth demoed Ruby Prof to the rest of the studio. Ryan introduced me to the wonderful world of GNU Screen. The little exposure I’ve had to his projects has me very impressed.

Gareth Reeves is doing work in Event Driven Architecture and Event Driven Programming. He introduced me to testing Java with jMock.

I’ve been working with Amazon ECS, Streamlined and a session bridge between rails and Perl’s CGI Session. I strapped subdomain/SEO love onto a project using request_routing, url_for_domain, and acts_as_sluggable. Nate and I pulled ActiveMerchant into a project which was much less painful than expected. If you’re doing complex condition building my tool of choice is condition_builder. I also extended restful_authentication so that it can support authentication for multiple types of users.

Written by syntatic

November 30, 2007 at 9:42 am

ruby on rails: merge! ‘params’ with a hash indifferently

with 3 comments

When using a merge! with the params method key value pairs are not clobbered if the calling hash is using symbols as keys.

If params[:colors] contains:

params[:colors] = { "blue" => false, "green" => true }

and sym_hsh contains:

sym_hsh = { :blue => true, :red => false }

a merge! of the two will result in this:

sym_hsh.merge!(params[:colors])
=> { "blue"=> false, :blue => true, :red => false, "green" => true }

Notice the duplicate blue key and mixed key types. Some are symbols and some are strings.

Using rails you probably haven’t run into this problem much. Behind the scenes in most of rails hashes are made indifferent to key type. Indifference protects developers from running into problems with strings and symbols as hash keys.

The rails code base uses the class HashWithIndifferentAccess allowing hashes to use strings and hashes interchangeably.

When creating new hashes in a rails project it is best to avoid the problem alongside rails. You can do this by creating hashes two different ways:

hsh = HashWithIndifferentAccess.new( :blue => true, :red => false)

or this which does the above for you:

{ :blue => true, :red => false }.with_indifferent_access

Now the merge! will clobber :blue instead of appending another :blue key.

Written by syntatic

November 28, 2007 at 10:01 pm

Posted in programming, rails

Get In Over Your Head

leave a comment »

Today was spent weaving a sabotaged rails project back together. Usually, I would tell you all the gory details but I’m a little concerned. I enjoyed the experience. Actually, I did more than enjoy the experience. I was in ecstasy all day. Today was the most enjoyable work day I’ve had in a month or two, but why?

Being unchallenged or on the same project everyday causes me to lose hope. I would venture to guess that your job is the same way. If you are a developer then I know your job is that way. Any self-respecting developer hates to be bored. We hate any work day that we do not grow by learning something new. As a developer few things are worse than being stagnant.

Everything that I did today was fresh. I advanced my abilities as a developer and rescued a poor abused rails app from being replaced by static html. The horror! I was in an environment I’d never been in before and was probably in over my head. I loved it. It felt like I kicked the crap out of whoever left rails and the server in that state of affairs.

From now on, I’ll be fighting for another opportunity to jump into some totally screwed up project where I get to throw a few punches again.

Written by syntatic

August 23, 2007 at 6:01 pm

Posted in programming, rails

Craftsmanship as a Bridge

with 8 comments

As a third grade teacher, my wife has an instant connection with anyone she meets. She can captivate anyone for endless hours with the thousands of stories her classroom provides. People want to know what we are teaching our children, they want to know if there is still a smelly kid, and if the schools still teach children how to play The Oregon Trail, which they do. For most, talking with my wife is a nostalgic experience.

As a software developer, I generally get blank stares and questions about how to fix some problem caused by a website that was accidentally visited. Few people feel nostalgic when I explain what I do everyday in front of a computer. A year ago, conversations about my job never developed or bloomed since I couldn’t bridge the gap from what I do into their lives.

Thinking and speaking about software development in terms of craftsmanship has bridged that gap for me. It gives non-technical people a door into understanding what I do everyday. It even has me excited to talk about software development with friends and family. Treating my job as a craft or a group of skills that are artistic practices draws needed parallels to other disciplines.

Usually, I explain how blacksmithing and programming correlate. Both crafts start with very basic materials iron ore and data. Blacksmiths smelt the ore and combine it with an alloy which determines the properties of the metal. Programmers data cleanse and apply a data type which determines the properties of the data. The two disciplines are heavily dependent on strong tool sets also. Wikipedia has an interesting tidbit concerning a blacksmith’s tool set:

Over the centuries blacksmiths have taken no little pride in the fact that theirs is one of the few crafts that allows them to make the tools that are used for their craft.

The same can be said for software developers since the frameworks, scripts and commands used to build software are made up of software. However, the greatest parallels between the two crafts do not come from similar processes.

I find that the biggest eureka moments when talking with non-technical people come from the connotations of blacksmithing. Software is forged. Applications are bent, punched and hammered into shape. Different programs are welded together seamlessly. Before delivery everything must be hardened and tempered. The process is dirty and it is hot. The final product is sculpted to be both aesthetic and functional. The emotional associations the previous sentences draw upon are foreign to most when thinking about software development.

One context non-technical people discover is that blacksmiths are rare now and the craft is archaic. Shouldn’t it be more related to the assembly line or some other post industrial revolution set of practices? No, software development began in 1940 or later. Relatively speaking, the discipline is not that old. Today’s view of blacksmithing describes the current state of software development. A quote from a well known programming book applies here:

One hundred years from now, our engineering may seem as archaic as the techniques used by medieval cathedral builders seem to today’s civil engineers, while our craftsmanship will still be honored. —The Pragmatic Programmer, Dave Thomas and Andy Hunt

There is so much untapped potential that lay ahead.

Another context that I usually bring up is that of apprenticeship or more specifically craftsmanship. At the studio we follow a system of apprenticeship that is similar to craft guilds which were common when blacksmiths could be found in every town. We regularly share new practices, techniques and tools as we refine our craft together. Our job descriptions and roles mimic those of apprentice, journeyman and master also. If you’re more interested in software development as craftsmanship here are some good places to start: the next big thing, software craftsmanship.

One final side note, I’m beginning to read more about software development as an artistic medium. Few non-programmers realize how much computer languages mimic human language. Computer languages have verbs, nouns, grammar, and hundreds of other syntactic structures that parallel human languages. Programming can be a poetic experience when a few lines of code are succinct and powerful. If you’re more interested in programming as poetry join me and take a look: The Poetry of Programming, Diving for Perls – the poetry of programming, Programmers as Poets.

Written by syntatic

July 13, 2007 at 12:15 am