Back to All posts

Better XML Parsing with Rails

Mar 2010

We recently built a Ruby on Rails application that was receiving a large amount of XML. This as you can imagine was pretty CPU intensive, especially as Rails (ActiveSupport) uses REXML under the bonnet to parse the incoming requests.

I started to wonder if it was possible to use a different XML parsing library, for an overview of some of the available libraries and benchmarks see John Nunemaker’s post about parsing xml with ruby and the rubyinside post: ruby xml performance benchmarks.

I’ve used most of these libraries at some point or another for parsing XML but I was really impressed with Nokogiri, and I desperately wanted to use it in production for the Rails backed parsing. So I started to look at the Rails source and I noticed this commit

YES! All you have to do (besides installing Nokogiri on your server) is specify:

ActiveSupport::XmlMini.backend = 'Nokogiri'

In your production.rb environment and your done. The results speak for themselves, here is a snapshot of our CPU usage before and after, with the same load:


Stay up to date with our blog posts

Keep up-to-date with our latest blog posts, news, case studies, and thought leadership.

  • This field is for validation purposes and should be left unchanged.

We’ll never share your information with anyone else. Read our Privacy Policy.