NextGen Gallery

NextGen Gallery causing too many MySQL queries


Looks like it is time to troubleshoot the NextGen Gallery plugin for WordPress again. The other day, while going through different server log files, i noticed an increase in MySQL queries. To give you some figures: With all the bits and bobs of the frontpage, like image, articles, widgets, etc. the site takes an approx. of 90-120 queries to render. While this is quite high already, render time is within reasonable limits, like 0.8 to 1.3 seconds (uncached). The query logs showed spikes of 900+ queries for building the frontpage, and when i saw that i was like “….WHOA….something wrong there….” and started investigating what is causing that unusual high amount of MySQL queries. So here is what i’ve done so far (and nothing of that really fixed it hehe). The actual problem seems to be the two NextGen Gallery plugins i use (NextGen Gallery and NextGen Gallery Plus).


The first step of troubleshooting was adding a line of code to the footer.php file of the current theme i am using. Said line displays the amount of queries and the time it took to render the page. In case you are interested in seeing how many queries/time your site takes to render, simply add the line of code before the closing HTML tag of your footer.php file:

The result looks like this:

Query Time WordPress
Query Time WordPress






To show you what i mean with “unusual high amount of queries” here is another screenshot:

MySQL High Query Cound
MySQL High Query Cound






Looking at the plugins i use on this blog i couldn’t imagine any of them increasing the amount of queries tenfold. So the basic troubleshooting started. Here are the steps i took thus far.

– Changing to the default theme
– Disabling all plugins

With the default theme active and all plugins disabled the query count stays relatively now and no spikes show up in the logs. So i enabled the plugins one at a time and refreshed the page a couple of times to see if the query count stays low. The last plugin i enabled were the NextGen Gallery and NextGen Gallery Plus plugins and that was where i noticed an increase in the number of queries again. With both of them disabled the query count remained around 80-90 queries, with both of them enabled the query count increased to 900+ queries again. So the problem clearly is with the NextGen Gallery plugin imho.

I also used severl MySQL tuners, like to no avail. Except for some recommendations about setting certain MySQL variables in /etc/my.cnf it did not show anything that looked dodgy. Here is an excerpt of one of the results it came up with

Right now i am somewhat at a loss, everything seems to be fine but WordPress still sometimes needs about 900 queries to render the front page. I didn’t check actual blog posts yet, but i suspect it to be the same issue. I will keep investigating as fixing this will certainly help to reduce load on the MySQL server and make the site load faster in general because of less queries used.

If any of you have an idea of what might be causing it…suggestions are highly appreciated
It’s probably worth testing the setup on my local machine as well, and see if it behaves the same way.

Be the first to comment

Leave a Reply

Your email address will not be published.

I confirm