Как протестировать скорость запроса MySQL с меньшим количеством несоответствий?

<div class="parentDiv" style="display:inline-block">
    // HTML elements
</div>

Это сделает ширину родительского div такой же, как наибольшая ширина элемента.

6
задан farinspace 27 July 2009 в 22:45
поделиться

4 ответа

Your first query may be slower because MySQL is actually hitting the disk on the first query, and not on the second.

Your operating system may cache files in memory as they are read; as a result, subsequent reads may not need to actually hit the disk, and will return much faster.

As a rule of thumb, I generally run a query a few times, and look for consistency. More often than not, the first run will take several times longer, while the 2nd 3rd and 4th take about the same amount of time. Those subsequent runs are probably more representative of the sort of performance you'll see on an actual production system -- since your production database should keep that data in the OS cache, while your dev system is rarely accessed.

In the end, when it comes to query performance, for the most part, you should just give it a quick pass in development, and monitor the slow query log in production to see which queries really need work.

As far as programatically running queries for performance data goes -- take several samples, and use the median. But in practice, this isn't going to be terribly representative of the actual performance issues you'll run into in production.

4
ответ дан 8 December 2019 в 17:25
поделиться

Попробуйте использовать SELECT BENCHMARK (раз, запрос)

Дополнительная информация: http://dev.mysql.com/doc/refman/5.0/en/information-functions. html # function_benchmark

8
ответ дан 8 December 2019 в 17:25
поделиться

Предположим, что:

  1. вы не используете постоянное соединение
  2. база данных, установленная на сервере, где выполняется статистика (нет сетевого подключения)
  3. никто другой не использует база данных (блокировки строк / таблиц)
  4. другие тяжелые процессы не выполняются
  5. и т.д ....

Если вы действительно хотите протестировать свой запрос, вы должны сделать следующее:

$database->query('SET SESSION query_cache_type = OFF');

Затем вы запустите запросить 2-3 раза в цикле (чтобы "прогреть" сервер).

И только потом:

$database->query('FLUSH STATUS'); #If you use the stats to profile your query

$t = microtime(TRUE);
$fp = $sub->generateFingerprint();
echo microtime(TRUE)-$t;

$database->query('SHOW STATUS');

Et voila !! :)))

Кстати, скорость запроса - это один из параметров для чтения. Узнайте, как читать очень ценную информацию, возвращаемую ПОКАЗАТЬ СОСТОЯНИЕ и ОБЪЯСНИТЬ ... . Так будет намного лучше.

Вот ссылка, которая вам понравится: http://www.xaprb.com/blog/2006/10/12/how-to-profile-a-query-in-mysql/

Наслаждайтесь. :)

2
ответ дан 8 December 2019 в 17:25
поделиться

You might be using persistant connections in your class. A pconnect will reuse the connection and would account for this type of lag.

0
ответ дан 8 December 2019 в 17:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: