In non trivial projects we often use SOA approach. Thereby one big monolithic application can be segregated into smaller applications or services. The benefit is obvious – it’s easy to control and maintain small applications. If you use Rails framework you probably already use ActiveResource for requesting your services because if follows ActiveRecord conventions.
Definitely ActiveResource operations are much slower than ActiveRecord operations because first one use HTTP connection and second one use usually persistent connection to database and database is usually always faster than application service.
The problem is that ActiveResource does not support keep-alive connections.
But not for Railsware :).
ActiveResource is Persistent
After playing a bit with sources we released small gem ActiveResource::Persistent that allows ActiveResource to use HTTP keep-alive feature.
Installation is trivial. Just drop line into your Gemfile
gem 'activeresource-persistent', :require => 'active_resource/persistent'
And all your resources will automatically reuse connections to services! You should NOT modify any line of your code.
Under the hood
Persistent connections are handled by excellent net-http-persistent library. The gem actually is very simple and provides ActiveResource::Persistent::HTTP object wrapper for ActiveResource.
However we covered library with specs that ensure it will work with different ActiveResource versions.
Currently it works with: