http_keepalive

Speed up your ActiveResources!

| 1 Comment

Preface

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.

But modern HTTP/1.1 servers support persistent connection and as Ilya Grigorik already mentioned in his awesome article we can have serious speedup for resources usage.

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

Installation is trivial. Just drop line into your Gemfile

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:

  • v2.3.x
  • v3.0.x
  • v3.1.x
  • v3.2.x

Enjoy! :)

References

Share
* Railsware is a premium software development consulting company, focused on delivering great web and mobile applications. Learn more about us.
  • http://www.drugbank.ca Craig Knox

    Awesome, works fantastic!

Want to get more of Railsware blog?

RSS FEED

We're always ready to help!

CONTACT US