Dec 18 2008

Yes, I’m not dead. ;-)

Category: Programming, ProjectsJim Powers @ 7:48 pm

Been a while.

Fortunately, for good reason: I do have some freelance work that I’m cranking on, all thanks to Andy Parsons. Anyway, cranking away on Rails while Andy pounds out (and drinks) the Java.

“What?” you say: “you’re doing a Rails project with all that purty purty Ruby code why do stuff in a blech language like Java?!” Well, because we do need parts of our system to have both higher intrinsic performance capability and to naively scale with available processors to pick up the thread load.

When the Ruby folks get serious about threading and performance (hint: dump YARV and hit up Parrot) we can revisit this conversation.

I have a number of posts in queue, hopefully I get them out soon.

Tags: , , , , , , ,


Dec 09 2008

The right way to produce pervasive break-through technology.

Category: Computers, ProgrammingJim Powers @ 11:50 am

Google is open-sourcing technology to enable secure execution of native code through browsers. This has long been the holy grail. Yes, JavaScript is cool, but you can’t write a video codec in it, or implement a relational DB efficiently, and it’s not multi-threaded. There are examples of the absolute wrong way to do this, so let’s hope that the engine of open-source development continues to demonstrate it’s superiority.

Tags: , , ,


Dec 07 2008

Waiting for Guffman, er… I mean Google

Category: Computers, ProgrammingJim Powers @ 3:43 pm

Well, in looking for gainful employment one of the places I applied to was Google. Honestly, I have no way to gauging my chances, but I guess I’d be better off assuming I’m a long shot. With this in mind I came across a really good blog: good coders code, great reuse. In addition to some really excellent posts Mr. Krumins also interviewed for Google and wrote about it here: My Job Interview at Google.

It’s a great write-up, and his prep for it has inspired me to break out some of my algorithms books (including my first edition of the fantastic Introduction to Algorithms ;-) ) and check out the online classes from MIT. The “Introduction to Algorithms” class material can be found found here.

Web programming can rot the brain: there is so much more than SQL and constructing snippets of HTML strings. Time to get back into shape.

Tags: ,


Dec 07 2008

Oh the joys of suburban power

Category: Blog MaintenanceJim Powers @ 11:49 am

Well, last night had a brown out or power-surge or something but it locked up the router and my switch. Ugh. Then it also froze the laptop that runs the site — a first!

Everything seems to be back to good health.

Tags:


Dec 04 2008

Quick update…

Category: Blog Maintenance, Ethics/Morality, ProgrammingJim Powers @ 2:48 pm

It has been a while since I updated the blog, apologies to all you loyal readers: been doing some Merb hacking on the site, and finally got a version of my resume up, now I’m sure to get a job! ;-)

Anywho, I do have some essays/entries lined up:

  • A Merb tutorial/HOW-TO — No joke I got a hit from a Google search (Woo hoo! Google knows I exist!) looking for a Merb tutorial, and I have none! I can’t let that stand!
  • An essay on Web development and ideas on how to build big
  • I have been following a lot of the work that Jonathan Haidt has been publishing recently, and looking at the criticisms that Sam Harris has been making of that work. I have a number of opinions to share in this subject. In the mean time check out Jon Haidt’s web site and the Moral Foundations site, really good stuff.

Sorry for the radio silence. Looking for work that doesn’t suck, and hacking code for this site take their toll on my attentions. Fun on its way!

Tags: , , , ,


Dec 01 2008

DRR decompression and Merb

Category: Programming, ProjectsJim Powers @ 10:58 pm

Some people know me as the retired “Chief Pain-in-the-Ass” (a.k.a. “Director of Platform Architecture”) of DigitalRailroad (warning: previous link may not work too much longer!) (DRR). Not quite sure how much weight should be placed in that title as the primary applications that ran DRR merely grew rather than being “architected”. Oh, don’t get me wrong, there were parts of DRR’s software that had a lot of careful design and thought put into them, but the core apps were basically monolithic ASP.NET applications that started out with a particular structure and simply grew that structure over time.

Eventually it became clear to all that something had to change.

Sometime in the last two years I finally made a successful case to not only do something about the code base that was crushing the life out of the development team (especially me), but to finally get off of the Microsoft platform and migrate to GNU/Linux. I vigorously argued for a complete rewrite in some new framework, but lost that argument. Instead, it was agreed that we would eventually get everything off of ASP.NET but it had to be done incrementally.

What should we use?

The first thing at that point was to decide on some framework to work with. I wanted to avoid a compile+deploy system so I wasn’t considering Java-based solution at the time (more on this in another post). The shortlist basically consisted of:

  • Ruby on Rails
  • PHP+<something that made developing with php not suck>
  • Perl+<some wicked-cool toolset to make perl Web development nice>

Yes, some will say that I should have considered Python and a framework like Django or Twisted, but seriously, I’m just not a Python fan, I can code in it, but I get no joy out of it (yes, I know it’s good enough for Google ;-) ).

After some testing, and a lot of discussion Rails was the winner. Now, I had been doing a lot of work in Rails the prior year and change. I had been showing off mockups of DRR in Rails since something like version 0.10 of Rails, but in all that I had learned a fair amount about what does and does not work well in Ruby and Rails.

Rails? What worries?

There were, and are, a lot of things to like about Rails, and frankly, I am rather happy that David Heinemeier Hansson (a.k.a. DHH) got inspired to use Ruby the way he did. Ruby is really a pretty language, and Rails is a pretty framework, but both have their demons.

Firstly, Ruby is slow. Yeah, yeah, I’ve read all over the place that I shouldn’t obsess over Ruby performance: “it’s almost never Ruby’s fault the your application runs slowly: focus on the DB.” Except that that bit of advice is complete bullshit. Ruby is slow and exhibits it slowness in painful ways, i.e. when you’ve done something to waken the Ruby slowness demon you will know it right away, it is not bashful. Like what for instance? How about looping over something with conditional code in it, such as:

def do_something(args)
  result = []
  args.each do |i|
    if i < 0
      result << "Less than zero"
    elsif i == 0
      result << "Zero"
    elsif i == 1
      result << "One"
    else
      result << "Greater than one"
    end
  end
  result
end

Now, the above is a bit contrived, I agree, but it shows the basic nature of the beast: if your code is chock full of executable statements as opposed to things that map directly to a C-call (like working with a Hashtable) you run the risk of your code being very slow. Much of this problem is being addressed in Ruby 1.9.x with the YARV VM1, but in Ruby 1.8.x innocuous day-to-day programming can become your worst nightmare. The solution, in general, is to re-design your code to eliminate the use of intrinsic Ruby statements and structure your code in a way that almost exclusively uses constructs that are directly implemented in C (i.e. native). This performance feature ;-) of Ruby periodically makes an appearance resulting in lost development time appeasing the Ruby performance gods2. Then there are all sorts of performance problems that arise from garbage collection activity, but I won’t go into details on that (lucky you).

What about Rails? Well, Rails has it’s own performance issues (not the speediest of frameworks, but not horrible either), but more importantly, Rails had (at the time) a tendency of being a memory hog and potentially unstable3, furthermore, deploying Rails apps was not fun using FCGI. Fortunately, the FCGI problem was solved with Mongrel4, but memory and stability were still a concern. Also, one of the painful lessons we learned with the ASP.NET site is that monolithic applications suck-ass in all directions: we wanted our “new” system to be modular, so we could update parts of the site easily, as well as scale-out apps individually instead of having one big app scaled to meet the performance needs of the slowest part. So, how would Rails help with that? Well, it didn’t out of the box. There were also a number of wacky things DRR was doing with URLs that simply did not play nice with Rails either.

Arguing with Rails

DHH says Rails is “opinionated software”5, so when you have to change something about Rails, I call it arguing with Rails;-). I had a number of fundamental arguments with Rails, the two most devilish were:

  1. Getting Rails to work with and generate the URLs that DRR used on the site
  2. Making it easy to build what appeared to be a single application to the outside world as a discreet set of Rails instances. 6

On our site there were 1 or 2 ways to address a particular photographer’s archive. If you did not have a custom domain for your archive then your URLs looked like this:

 http://www.digitalrailroad.net/<archive name>/...

If you had a custom domain (a.k.a. “domain pointed”) for your archive then either of the following URLs would work, but preference was given to the one using your custom domain:

 http://<custom domain>/...
     - OR -
 http://www.digitalrailroad.net/<archive name>/...

Now, for various reasons, including the fact that in a development environment you didn’t want to keep having to edit your /etc/hosts files it was necessary for Rails to intrinsically be able to deal with and generate both kinds of URLs using Rails’ built-in routing mechanism. In order to accomplish this I created the DRR Rails plugin7. This plugin monkey-patched Rails’ routing guts to transparently deal with the DRR urls, and to boot it made available all sorts of wonderful data about the archive the user “was in”.

The other problem of making it easy to build DRR as a set of Rails instances was solved with a number of additions to the DRR Rails plugin. The plugin enabled an easy way to package a shared collection of routes and route files in the plugin itself. It also effectively implemented a namespace mechanism (I called them grouped routes) that allowed URLs to be generated to any route (using named routes only, then again, naked route generation has been shunned for quite some time now) but only recognize routes for the current application instance. This approach promoted a lot of DRY8 code and made it possible to work on and develop isolated parts of the DRR application. The whole approach I called the “micro-apps” way to build a site.

The above approach worked really well9, and it resulted in achieving the sought-after goals: componentized development, and performance and process isolation. Slowly but surely we could replace the old ASP.NET application.

Towards the end of DRR I began working on a port of the plugin to Rails 2.x. Since the plugin is a lot of monkey-patching of Rails core I knew there was no way it would just work in Rails 2.x. Probably 1-2 weeks of concerted effort and it would have been done. Rails 2.x did also promise performance improvements.

Hey, didn’t you mention something about Merb in the title?

Yes, yes I did. The tie in to Merb is that Merb has a more hacker friendly approach to building things than Rails IMAO. In particular, because of Merb “slices” Merb has a clean and robust implementation of URL namespaces and application componentization that would have worked very nicely at DRR, also the Merb routing mechanism is nicely pluggable meaning a lot less (perhaps even no) monkey-patching! This would have been a real productivity boost had I had it early on. Alas, at the time I was doing all of this Merb was barely a glimmer in someone’s eye, but it seems clear that the Merb folks have intelligently learned from Rails’ history. Furthermore, the Merb folks take performance very seriously and have done wonders to achieve high performance with a powerful framework that runs in a fraction of the footprint of a typical Rails app. In fact, Merb has shown up on this site as it runs all of the non-blog content (not much at the moment, but I “have plans”).

Expect to see more on Merb in the future. For now, if you are considering a Ruby Web+ framework Merb should rank prominently on your “short-list”.

  1. Why the Ruby folks will not use the Parrot VM is still beyond me. []
  2. Frankly, I think that the Ruby folks are risking losing control of the Ruby language. All that is necessary is for one viable alternative implementation, other than “Matz’s Ruby Implementation” (MRI) to have good performance and have a decent debugging environment and MRI will be threatened with extinction. Just my opinion. []
  3. DHH even mentions numerous app restarts on their various 37signals sites []
  4. Thank you Zed []
  5. This approach to software lead to one of my favorite slides of all time! []
  6. All tied together with some Apache rewrite and proxy magic. []
  7. This plugin did a lot more than what is mentioned here. I do plan on breaking apart the plugin and releasing individual components as Rails plugins. Stay tuned. []
  8. Don’t Repeat Yourself []
  9. There was some getting used to this approach. []

Tags: , , , , , , ,