in Business, Challenge, Crash Course, Interesting, Performance

WordPress page_rewrite_rules many URL rewrite mysql slow

There are use cases that WordPress core isn’t well optimized for. The end result is poor page load and sub optimal performance.  One of these use cases is the too-many-URLs or menu links issue. WP is then forced to break down these requests into smaller chunks to process them. Except that smaller chunks almost always amount to significant overhead especially with a high number of URLs.

WP function page_rewrite_rules is where the page rewrites happen for every URL. But for several reasons, we won’t go as far as to modify this function to reduce the overhead. After profiling this function and code, we were able to understand the culprit and implement a fix with the least resistance path (i.e. not in the code).

The fix consists of increasing the max_allowed_packet parameter in  the my.cnf configuration file for MySQL in section [mysqld] (usually located in /etc/my.cnf) like this:

max_allowed_packet = 32M

A high max_allowed_packet helps WP process the URL rewrites in one fell swoop (larger query pull leads to faster processing).

We hope you enjoyed this entry. Interesting tidbit to note is that we happily did this work for a client who didn’t care one bit about the inner workings of WP. They just wanted things to work on their managed server. And so we did.

That’s all folks!