Databases Roundup: Data Sharding for ActiveRecord and Faster Postgres IO

| by Mirko Stocker Follow 0 Followers on Jul 21, 2008. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

In this databases roundup we take a look at a new data sharding plug-in for ActiveRecord and how Postgres data access can be improved with the asynchronous client API.

Data Sharding for ActiveRecord

Data sharding is a technique to break a database into small partitions and to distribute them over several servers to improve the performance and scalability. How the data is partitioned is highly application dependent, eBay for example could partition by article category.

ActiveRecord does not support data sharding out of the box—this is where FiveRuns' DataFabric comes into play. DataFabric is an ActiveRecord plug-in that adds data sharding and also replication abilities to your models.

Introducing sharding into your models is quite easy, as this example from the README shows:

class MyHugeVolumeOfDataModel < ActiveRecord::Base
  data_fabric :replicated => true, :shard_by => :city

 See the FiveRuns blog or the DataFabric GitHub repository for more information.

Faster IO for Postgres

In other database-related news, Muhammed Ali was able to boost Ruby's Postgres access by about 40%. He uses Postgres' asynchronous client API and Ruby 1.9 Fibers to implement a nonblocking connection pool and a fiber pool. The interaction from the user program's perspective looks as follows:

[..] once a fiber calls cpool.exec the query is sent to the pool for processing and the fiber is halted, giving way for another one to start processing. The other one will halt as well once it hits a cpool.exec. Later during the event loop you will get notifications of completion of queries (in any order) and resume the fiber associated with the finished query.

Muhammed also thinks about working on a better integration with EventMachine, which might improve the performance even more. Take a look Muhammad's Blog where he describes his analysis in full detail and the code he used.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you