Mike Perham

On Ruby, software and the Internet

Entries Tagged as 'Rails'

DataFabric – database sharding for Rails

October 5th, 2009 · 1 Comment

With the closing of FiveRuns, the blog post that was the main page for DataFabric has disappeared. I’m creating this blog post as a replacement.
DataFabric is a Rails plugin/gem that adds sharding support to ActiveRecord. It supports Rails 2.x and is theoretically database independent, although I haven’t tested it personally with anything but [...]

[Read more →]

Tags: Rails

Rails Engines at LSRC

August 28th, 2009 · 1 Comment

Here’s my slides for LSRC covering the new Engines feature in Rails 2.3. Basically I cover Rails’ history from monolithic application to supporting code reuse via plugins to supporting MVC reuse via engines.
Rails Engines (PPT, 2.9MB)
Rails Engines (Keynote, 1.8MB)

[Read more →]

Tags: Rails

Old versus New

July 29th, 2009 · No Comments

We had some performance issues recently and discovered we were using memcache-client 1.5.0. Our daemon was blocked by memcached socket operations hanging forever, which caused monit to kill and restart the daemon after 5 minutes.
I performed the brain surgery to use 1.7.4 (since we are using Rails 2.1) and deployed. See if you [...]

[Read more →]

Tags: Rails · Ruby

Adding multi-get support to Rails

June 13th, 2009 · No Comments

Memcache-client has the ability to fetch multiple keys in one request but Rails does not expose this functionality. It’s really easy to add it yourself though:
config/initializers/rails_patches.rb

Rails.cache.instance_eval <<-EOM
def read_multi(*keys)
@data.get_multi(*keys)
end
EOM

Rails uses read/write for its API naming so we name the method read_multi rather than get_multi. Here’s a [...]

[Read more →]

Tags: Rails

Engines in Rails 2.3

April 18th, 2009 · 1 Comment

Engines have been around Rails for years but it wasn’t until the recent 2.3 release that Rails officially supported Engines. So what is an Engine? An Engine is a Rails plugin with full MVC capabilities. In essence, that means your Engine has an app directory with helpers, controllers, models and views just [...]

[Read more →]

Tags: Rails

Caching and Rails

March 25th, 2009 · 3 Comments

Here’s the slides from my AOR talk last night: Caching, Memcached and Rails (600KB).
Caching, Memcached And Rails

I was a little unhappy with my wrapup – the one thing I wanted to teach people was when to use each different caching mechanism provided by Rails and I didn’t really revisit and summarize that content. So [...]

[Read more →]

Tags: Rails · Ruby

Using memcache-client 1.6.x in Rails < 2.3

March 3rd, 2009 · 12 Comments

Jemery Kemper recently upgraded Rails 2.3’s vendored copy of memcache-client to the 1.6.4 release. But what do you do if you are running Rails 2.1/2.2 and want to take advantage of the massive speedup in 1.6.x? You write some really ugly code that performs brain surgery on the Ruby environment to override ActiveSupport. [...]

[Read more →]

Tags: Rails

FiveRuns Dash, now with 100% more rimshot!

February 24th, 2009 · No Comments

I’m giving away a free copy of my iPhone app, Zinger, to every person who gets their app running with our new metrics service, Dash. Just email me. Steps (documented in more depth here):
1) Request an invite by signing up at https://dash.fiveruns.com
2) Log into Dash, create a new Rails application and note your [...]

[Read more →]

Tags: Personal · Rails

Improved Deadlock Retry

February 7th, 2009 · 2 Comments

Anyone who’s built a reasonably complex web site on top of a database has seen database deadlock. MySQL will throw a timeout error after waiting for 30 seconds, thereby ending the deadlock in a brutal but effective manner. Rails has a plugin, known as deadlock_retry, which will catch those errors and simply retry [...]

[Read more →]

Tags: Rails

DataFabric 1.2 released

December 1st, 2008 · No Comments

DataFabric 1.2 supports ActiveRecord 2.2 and its overhauled connection handling. Believe me, this is a good thing. The old connection handling code was awful; the new code is much nicer.
How It Works
data_fabric 1.0 supported dynamic connections by proxying the connection stored in the global static connection hash. This is thread-unsafe and therefore [...]

[Read more →]

Tags: Rails