Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Anna Filina:
Reduce number of queries
Oct 29, 2014 @ 10:53:10

In her most recent post Anna FIlina makes a recommendation to those looking to increase the performance of an application, especially one that's already in place: simply reduce the number of queries. It sounds simple enough, but can sometimes prove to be difficult depending on the application.

Customers often call me because their site is slow. One of the most common problems I found was a high number of queries that get executed for every single page hit. When I say a lot, I mean sometimes more than 1000 queries for a single page. This is often the case with a CMS which has been customized for the client’s specific needs.

In this article, aimed at beginner to intermediate developers, I will explain how to figure out whether the number of queries might be a problem, how to count them, how to find spots to optimize and how to eliminate most of these queries. I will focus specifically on number of queries, otherwise I could write a whole tome. I’ll provide code examples in PHP, but the advice applies to every language.

She suggests starting from "the top", looking at the browser's own information on which pieces of data are taking the longest to return back to the client (the latency). This gives a starting direction and tells you where to look for the worst offenders. She talks about a technique to locate and count the queries being made and some common issues found in multiple kinds of software (hint: loops). Then she gets down to the optimization - combining similar queries and better queries through joins.

tagged: query database performance join similar tips

Link: http://afilina.com/reduce-number-of-queries/

Trending Topics: