BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Databases Roundup: Data Sharding for ActiveRecord and Faster Postgres IO

Databases Roundup: Data Sharding for ActiveRecord and Faster Postgres IO

This item in japanese

Bookmarks

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.

Rate this Article

Adoption
Style

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.

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

Community comments

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

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

BT