Archive for the 'Ruby' Category

Boost Rails performance by generating constants

Thursday, March 11th, 2010

This may be obvious to everyone already, but it was new to me.

Serendeputy hits a few Tokyo Cabinets when it assembles a page. I was having trouble with these sometimes getting hung up, especially when looking up some of the ancillary information. I keep all the tag metadata in the main librarian cabinet. The site looks up this data pretty often. This would manifest itself on the site with a 500 error, and the Passenger Rails process would hang. The site would return 500s until I restarted the process. Ugh.

So, I did a couple of things (which I’ll likely talk about later.) The easiest one was probably the simplest.

I ended up adjusting the librarian build to not only populate the appropriate cabinet, but to also generate a ruby source code file in which I declared a constant with the tag metadata hash defined. I then restart Passenger to pick up the new constant.

Now, Rails only loads this once, and it’s in memory for the rest of the time. This not only saves me the network latency, it makes the individual responses much faster.

It’s always fun to solve complex problems with simple brute-force actions.

Make everything as simple as possible but no simpler

Tuesday, January 26th, 2010

How to prevent browsers from caching a page in Rails

Tuesday, April 14th, 2009

How to reload a class in irb

Tuesday, September 16th, 2008

Stack Overflow is pretty impressive

Tuesday, September 16th, 2008

How to test tag attributes using assert_select

Wednesday, September 10th, 2008