SLACKWORKS / BLARG

At Vocel we use the New Relic plugin to monitor the performance of our production Rails apps.

In addition to the built-in ActiveRecord and Controller metrics, you can define your own custom metrics. The documentation clearly shows how to add a metric to an instance method, but how do you add one to a class method?

Thanks to a somewhat well known statistical behavior known as the Birthday Problem, collisions of randomly generated keys are much more likely than you would expect. You can estimate how likely with some quick Ruby.

I like to explain the relationship between Rails and Java is that Rails makes the things I hate doing easy and Java makes the things I like doing possible.

In this mind set, when using Rails on JRuby I want to do as little configuration in Java (XML sit-ups are bad) and leverage Rails as much as possible (a few yml stretches are good). The most common configuration cross over is the database connection. This is where JNDI helps out, now both sides can use the same connection pool.

I have two worlds that need to collide. Rails solves the decade long problem of abusive Java web stacks and Java provides mature codebase to the Rails paradigm. JRuby has brought me the spark, now if I can only get the fire burning.

The problem: I need a Spring context to startup with Rails and use the config/database.yml.

The most common Rails config wants a separate hostname for each application. If you tend to create new ones frequently, this can mean a lot of running back and forth to your DNS config. At best this means waiting for the changes to propagate, at worst it could mean waiting for corporate IT to get around to it.

Luckily, in addition to normal names, DNS allows you to create “wildcard” records that match any name not otherwise defined.

So far I have been doing all my CouchDB queries using “temporary views” which are Javascript strings which are POSTed to the database and used to select the records you’re interested in. A more efficient way to do it is to save the Javascript strings as documents, these can be called with less traffic and a simpler API. “Permanent views” also create cached indexes, so they offer performance advantages over temporary views as well.

The attachment_fu plugin for Rails is great, and it’s support for S3 as a backend sounds really handy. Sadly tho
ugh, it isn’t practical for anything other a demo or a proof-of-concept. Luckily its limitations can be worked around with the cunning use of Bj .