BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Databases Roundup: Data Sharding for ActiveRecord and Faster Postgres IO

by Mirko Stocker on Jul 21, 2008 |

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
end

 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.

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

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT