· · Matthew Ford  · 1 min read

Better XML Parsing with Rails

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 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

https://github.com/rails/rails/commit/694998ee4fb8d257ba78424cab630846327a0889.

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:

cpu0

Do you need help with your application?

At Bit Zesty, we specialise in building and maintinaing bespoke software and intergrating AI into existing applications.

Looking to build an application, but unsure of the price? Keen to discuss our experience, processes and availability?

Back to Blog

Related Posts

View all
Brighton Ruby 2024

Brighton Ruby 2024

Brighton Ruby 2024 was nothing short of amazing. It brought together passionate Ruby developers from around the world to share knowledge, network, and have fun.

Ruby on Rails: Top 5 Gems to Enhance your Application

Ruby on Rails: Top 5 Gems to Enhance your Application

Creating a Ruby on Rails app can be a challenging task, but it can be made easier by utilizing different gems. These gems consist of third-party code libraries that can significantly speed up the development process. While some of these gems are necessary for Rails,…