# Better XML Parsing with Rails
> 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…
Author: Matthew Ford
Published: 2010-03-15

<p>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.</p><p>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 <a href="https://railstips.org/2008/8/12/parsing-xml-with-ruby">parsing xml with ruby</a> and the rubyinside post: <a href="https://www.rubyinside.com/ruby-xml-performance-benchmarks-1641.html">ruby xml performance benchmarks</a>.</p><p>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</p><p><a href="https://github.com/rails/rails/commit/694998ee4fb8d257ba78424cab630846327a0889">https://github.com/rails/rails/commit/694998ee4fb8d257ba78424cab630846327a0889.</a></p><p>YES! All you have to do (besides installing Nokogiri on your server) is specify:</p><p>ActiveSupport::XmlMini.backend = 'Nokogiri'</p><p>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:</p><figure class="kg-card kg-image-card"><img src="/images/blog/better-xml-parsing-with-rails-1.png" class="kg-image" alt="cpu0" loading="lazy" width="496" height="571"></figure>
