The gettext filter is a really handy filter that I’ve written about before. The filter provides a way to easily change international-ready text via a simple filter call, but it can also have a serious impact on performance if overused.
For the last several weeks one of my client sites has been having some serious server problems. The site in question has really large amount of traffic and runs on an extremely beefy Rackspace server, one that should be able to handle the traffic without any trouble.
To give an idea of the sort of problems this server was having, here are a few highlights:
- It would go down at least once per day
- Response times averaged around 1200 – 2400ms per request
- In NewRelic (a server monitoring app), the site has almost never seen anything but red
Tonight we finally discovered the source of our problems: a huge number gettext filter calls.
We had been using a string-swap plugin to modify some front-end strings, and usually these kind of plugins don’t cause any significant issues, since it is just a few strings that are usually being changed. What we had failed to realize was that this particular plugin was setup in such a way that nearly every single localized string on the site was being filtered. This was thousands and thousands of text strings.
When modifying a few text strings, the performance impact can be quite minimal, but when accidentally modifying thousands upon thousands, the impact can be disastrous. See the server response time graph below for proof:
[lightbox link=”https://pippinsplugins.com/wp-content/uploads/2013/11/Screenshot-from-2013-11-08-222413.png” thumb=”https://pippinsplugins.com/wp-content/uploads/2013/11/Screenshot-from-2013-11-08-222413.png” width=”511″ align=”none” title=”Screenshot from 2013-11-08 22:24:13″ frame=”true” icon=”image”]
It should be very apparent when the offending plugin was disabled.