28Apr/110

MySource Matrix performance analysis : Log dump all database SQL queries

Posted by Rianto Wahyudi

MySource Matrix

Wanted to know why your mysource matrix installation running slow ?One major issue with our installation is  matrix execute large  number of SQL queries. The individual query by itself is very lightweight and executed fairly quick, but there are hundreds to thousands of queries required just to bring up a page.

I've experienced up to 5,000 SQL queries (  2 Mega Bytes in size !) just to bring up  2 KB html page. In this case,  powerful , grunty and well tuned  database server  just won't help improving  page load time. ( Network latency between app server and database server is  0.6 ms at best, so theoretical minimum page load time is 3 seconds. On top of that, there are databases and applications processing overhead. If combination of the database and application overhead takes around 0.5 millisecond to process, the page load time will be around 5.5 seconds. 5.5 seconds to bring up 1 html page with no assets  is too long !)

 

 

 

 

 

If you curious  to see these how many queries your matrix produce, you can use log_dump tools to log these queries into system.log To do this ,edit the  following file :

core/lib/MatrixDAL/MatrixDAL.inc

Add following  line at the top of the line :

require_once ('/fudge/dev/dev.inc');

Add log_dump() function at the end of  preparePdoQuery function ( Around line 285 - just before "return $query" )


log_dump($query);
return $query;

Output will be written to'/data/private/logs/system.log

UPDATE :

Squiz Matrix 4.4.1 ships with awesome "Performance Mode".  It can be accessed just by appending /_performance at the end of  the URL of your matrix site.

From : http://www.squizlabs.com/squiz-matrix/squiz-matrix-performance-mode

Performance Mode will analyse the performance of the currently viewed asset present its findings at the base of your browser

These performance results will report the total time taken to load the asset and how much of this time can be attributed to system processing; the remaining time due to individual asset loading.

The individual assets that have been loaded will be listed chronologically, displaying their name, asset ID and asset type, as shown in the image below.

mysource matrix squiz performance
10Apr/110

Purge squid cache using curl (without squidclient)

Posted by Rianto Wahyudi

Squid Logo Purging cached document from squid can easily be achieved using squidclient. But in some cases where squidclient is not available you can use curl to purge squid cache.

Purging squid cache is relatively simple, as you only need to specify PURGE http method instead of GET or PUT.

Your need to allow your web server   to PURGE data from squid. This is achievable  by specifying  ACL on squid server to allow web server , ie :

acl purgehosts src 192.168.1.10
http_access allow PURGE purgehosts

Bash

curl -X PURGE -x [squid-server:port] [URL to purge] -Is | head -n1

Example :

curl -X PURGE -x http://squid.example.com:80 http://www.example.com/contact -Is | head -n1

PHP

<!--?<span class="hiddenSpellError" pre=""-->php
$proxy="http://squid.example.com:80";
echo clearcache("http://www.example.com/contact",$proxy);

function clearcache($url,$proxy)
{
    if (!function_exists('curl_init')) { die('cURL is not installed!'); }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST , "PURGE");
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);

    if (!curl_exec($ch)) { return false; }
    $output = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    return ($output == '200') ? "success": "not cached";
}

?>
Filed under: Linux No Comments