query in a page

Events happening in the community are now at Drupal community events on www.drupal.org.
navaneeth_r's picture

How/where to check the number of queries running in a page other than devel module.

Regards
R.Navaneethakrishnan.

Comments

You need to write a custom

Jonah Ellison's picture

You need to write a custom module for this. Drupal doesn't have a built-in way to do this.

First enable query logging:

<?php
variable_set
('dev_query',1);
?>

Then add code to display query info. A global variable called $queries will contain the time and SQL statements used. Here's an example:

<?php
 
// Database benchmarks
 
if(variable_get('dev_query',0)) {
    global
$queries;
   
$page_render = timer_read('page');

   
$time_query = 0;
    foreach(
$queries as $q) {
     
$time_query += $q[1];
    }
   
$time_query = round($time_query * 1000, 2); // Convert seconds to milliseconds
   
$percent_query = round(($time_query / $page_render) * 100);
   
   
$output = count($queries) . " queries @ {$time_query} ms ({$percent_query}%)";
  }
?>

This will output something like "122 queries @ 165.49 ms (44%)." To be really accurate, use PHP's register_shutdown_function and dump it at the end of the page.

Thanks for your response

navaneeth_r's picture

Thanks for your response Mr.Jonah. How to do " PHP's register_shutdown_function and dump it at the end of the page"

In _db_query function in database.mysql.inc I am using following code to log the queries.

if($_SERVER['REMOTE_ADDR'] == '192.168.99.180') {
$file = '/var/www/html/example/files/query.txt';
$handle = fopen($file,'a+');
fwrite($handle,$query."\r\n");
fclose($handle);
}

Regards,
R.Navaneethakrishnan

I am trying to use the

navaneeth_r's picture

I am trying to use the memcache.

I am logging the queries after and before enable memcache.

I am using following in _db_query function in database.mysql.inc I am using following code to log the queries.

if($_SERVER['REMOTE_ADDR'] == '192.168.99.180') {
$file = '/var/www/html/example/files/query.txt';
$handle = fopen($file,'a+');
fwrite($handle,$query."\r\n");
fclose($handle);
}

Before enable the memcache file size is 1.09 kb after enable the memcache the log file size is 11.09 kb.

In the memcache enable state I commented the following code then the queries are becoming 1.09 kb.

$conf = array(
'cache_inc' => './sites/all/modules/memcache/memcache.inc',
'memcache_servers' => array('localhost:11211' => 'default'),
'memcache_bins' => array('cache' => 'default','cache_views' => 'default', 'cache_page' => 'default', 'cache_path' => 'default','cache_filter' => 'default','cache_menu' => 'default'),
);

  1. I think the log file size should reduce after enable the memcache is it right?...
  2. Am i missed any configuration?.

I have attached the log file before and after memcache. I need your support.

Regards
R.Navaneethakrishnan.

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: