How many queries are considered too much?

How many queries are considered too much in a CMS ?
How many queries are usually executing in a CMS index.php ?
How to track the queries by mysql ?

  1. Why worry about it if you have every scripted correctly.
  2. Depends how busy the website is.
  3. Why?

Number of queries isn’t a particularly useful measurement on its own. 100 queries that run in 0.001 seconds each is better than 1 query that takes half a minute to run.

1 Like

Any more than you need is an excessive amount.

There’s no answer for this. Not only does it change per CMS, it changes per conditions as well.

You could determine how many are occurring by writing a wrapper for your query functions in which you increment a var and just spit it out in your footer.

Not looping queries is a huge factor. I fixed a site (page) for someone that was performing poorly. There were only 5 queries on the page BUT each was inside the last. Turned out that over 8000 queries were being run. I converted it to a single joined query.

2 Likes

1 more than you need.

1 per ‘block’/widget/whatever of the CMS on display is a -VERY- general guideline. Optimally? 1.

You… shouldnt need to?

1 Like

Because I want to see Wordpress/Joomla/ other cms sql queries

There is many ways to do this, you can do it by using New Relic on the server and create a transaction entry for the page in question. Though this is a paid service, so it is not something you would normally use during development. But rather after launching the website.

The easiest way is by using Z-Ray for Zend Server, if you are working on a open source project or are Zend Certified you get a developer license for free.

Been using it for a few months, when I want to look at the executed queries for a call. Makes it very easy to see what is being called, and also what performance impact any changes you did had to the code.

DreamHost has what they call CONUERIES
http://wiki.dreamhost.com/Conueries

tl,dr

Database Connections are an important factor

Alternatively, if your code uses PDO or even a class that wraps the database functions you can extend it and log all queries

class MyPDO extends PDO {
    public $log = [];

    public function query($sql) {
        $this->log[] = $sql;
        return parent::query($sql);
    }

    public function prepare($sql) {
        $this->log[] = $sql;
        return parent::prepare($sql);
    }
}

Then change new PDO to new MyPDO where PDO is instantiated and at the end of the script you can read $pdo->log to see all the queries.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.