<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Building the Web &#187; optimization</title>
	<atom:link href="http://www.filonov.com/blog/tags/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.filonov.com/blog</link>
	<description>Web development notes, tips, tricks, ideas, thoughts</description>
	<lastBuildDate>Fri, 04 Mar 2011 15:43:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Joomla profiling log</title>
		<link>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/</link>
		<comments>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/#comments</comments>
		<pubDate>Mon, 25 May 2009 21:37:39 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=37</guid>
		<description><![CDATA[I am using Joomla for the content management, and it looks like my site is getting slow, no, not just slow, it&#8217;s SLOW. Quick check in the MySQL database showed that there is no really big tables which could cause some delays if not indexed properly or getting locked. So, next step would be naturally [...]]]></description>
			<content:encoded><![CDATA[<p>I am using Joomla for the content management, and it looks like my site is getting slow, no, not just slow, it&#8217;s SLOW.</p>
<p>Quick check in the MySQL database showed that there is no really big tables which could cause some delays if not indexed properly or getting locked. So, next step would be naturally looking into the PHP code itself trying to identify bottlenecks.</p>
<p>First of all &#8211; copy everything to test site &#8211; I don&#8217;t really want to shut the site down or display some debug info to the visitors. My test site is actually a linux box which is pretty old one, so it probably will run slower comparing to production, but hopefully still allow me to find which areas of code are causing that.</p>
<p>Next step &#8211; tools. To profile PHP scripts I&#8217;ll use APD (http://pecl.php.net/package/apd). Best case scenario &#8211; you type<br />
<code>pecl install apd </code><br />
in the shell to install package from PECL.<br />
You may also need to add it to PHP configuration, I just created extra config file<br />
<code>/etc/php.d/apd.ini</code><br />
with content<br />
<code>[apd]<br />
zend_extension="/usr/lib/php/modules/apd.so"<br />
apd.dumpdir = /var/apd<br />
apd.statement_tracing = 0</code><br />
(make sure directory specified in dumpdir is created and writable for PHP)</p>
<p>Now we need to add<br />
<code>apd_set_pprof_trace();</code><br />
at the beginning of the index.php script and open the page we want to profile, front page would be a good place to start.</p>
<p>In the dump directory a file created after each page opening, something like<br />
<code>/var/apd/pprof.08711.0</code></p>
<p>Let&#8217;s see what consumes resources now, by running<br />
<code>/usr/bin/pprofp -R /var/apd/pprof.08711.0</code></p>
<p>Oh, that hurts:</p>
<p><code>Total Elapsed Time = 23.58<br />
Total System Time  = 0.65<br />
Total User Time    = 7.18</code></p>
<p>Log in to Joomla admin, go to Extensions->Module Manager, delete all modules I do not really use, but which came pre-setup with Joomla.</p>
<p><code>Total Elapsed Time = 19.51<br />
Total System Time  = 0.24<br />
Total User Time    = 2.48</code></p>
<p>Ok, I am starting to see results already <img src='http://www.filonov.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now let&#8217;s pay attention to the actual calls and time spent by script in functions.</p>
<p>14 seconds spent in JDocumentRendererModule->getFeed&#8230;<br />
Hm&#8230; I do have a feed from my blog, now I wonder what the cache settings for that block is. So, in admin Module Manager -> mod_feed, advanced settings, cache : use global, time 60 minutes (I think I am ok with blog posts delayed for 1 hour, but it&#8217;s your call, just make sure it won&#8217;t come on every page load). That slashed a lot from the page load &#8211; over 15 sec of wasted time (note &#8211; check why blog feed is so slow, there should be some reasons!!!)</p>
<p>JDocumentHTML->_parseTemplate &#8211; I reviewed template and got rid of calls for modules which are not required or not used (like user1, user2, user3 areas which came with template and similar) &#8211; that saved 1-2 seconds per call.</p>
<p>At this point I have</p>
<p><code>Total Elapsed Time = 2.82<br />
Total System Time  = 0.21<br />
Total User Time    = 2.48</code></p>
<p>Which is way better, but still makes me wonder if it can run faster. </p>
<p>There are other options to play with<br />
<code>/usr/bin/pprofp -u /var/apd/pprof.09573.15</code><br />
gives an idea what subroutines consumed most user time.</p>
<p>Last but not least: for the profiling purposes I turned off cache (Site->admin->global configuration). For life site it should be turned on with reasonable time to keep cached copy, that shaves off another 50% of execution time on subsequent calls of the same page.</p>
<p><code>Total Elapsed Time = 1.78<br />
Total System Time  = 0.17<br />
Total User Time    = 1.55</code></p>
<p>For now it&#8217;s as good as it gets on my old server, next thing to do would be profiling the script on the production server to see what it looks like there.</p>
<p>Another tip: if you profile a live site, restrict profiler calls to your own IP:<br />
<code>if($_SERVER['REMOTE_ADDR'] == "xxx.xxx.xxx.xxx") {<br />
apd_set_pprof_trace();<br />
}</code><br />
otherwise you may get buried in a number of trace logs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check Google webmaster tools now</title>
		<link>http://www.filonov.com/blog/2009/04/30/check-google-webmaster-tools-now/</link>
		<comments>http://www.filonov.com/blog/2009/04/30/check-google-webmaster-tools-now/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 23:13:51 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://filonov.com/blog/?p=27</guid>
		<description><![CDATA[The biggest traffic source for the web site is search engines traffic. There is a lot what can be written on search engine optimization (SEO). But I just realized that often web masters or web site owners missing quite important application from the Google itself Google Webmaster Tools That&#8217;s a valuable data on what Google [...]]]></description>
			<content:encoded><![CDATA[<p>The biggest traffic source for the web site is search engines traffic. There is a lot what can be written on search engine optimization (SEO). But I just realized that often web masters or web site owners missing quite important application from the Google itself</p>
<p><a href="https://www.google.com/webmasters/tools/">Google Webmaster Tools</a></p>
<p>That&#8217;s a valuable data on what Google &#8220;knows&#8221; about your web site, definetely worth checking and should be a starting point of the search engines optimization.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/04/30/check-google-webmaster-tools-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FogBugz speed issue &#8211; an example of MySQL slow queries troubleshooting</title>
		<link>http://www.filonov.com/blog/2009/04/02/fogbugz-speed-issue-an-example-of-mysql-slow-queries-troubleshooting/</link>
		<comments>http://www.filonov.com/blog/2009/04/02/fogbugz-speed-issue-an-example-of-mysql-slow-queries-troubleshooting/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 21:15:06 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://filonov.com/blog/?p=13</guid>
		<description><![CDATA[We are using FogBugz application for the bugs and support requests tracking. And it&#8217;s configured to receive support@companyname.com emails (means tons of spam). Once the database size hit approximately 20,000 requests, we started really wonder: why so slow? It looks like there was another table BugEvent which size is around 200,000 records at that time. [...]]]></description>
			<content:encoded><![CDATA[<p>We are using FogBugz application for the bugs and support requests tracking. And it&#8217;s configured to receive support@companyname.com emails (means tons of spam). Once the database size hit approximately 20,000 requests, we started really wonder: why so slow? It looks like there was another table BugEvent which size is around 200,000 records at that time.</p>
<p>It could be some other application, could be your own code. Doesn&#8217;t matter &#8211; just it happens, one database size grows, performance of the application is degrading.</p>
<p>First step to troubleshoot &#8211; enable slow queries log in the MySQL config file (/etc/my.cnf is popular location). Open file in editor and add lines</p>
<pre><code>log_slow_queries        = /var/log/mysql-slow.log
long_query_time = 10</code></pre>
<p>(path for the log file is totally up to you, I use MySQL 5.0*, so in other versions syntax can be different)</p>
<p>Those lines tell mysql to log all queries lasted 10 seconds or more. Restart MySQL now and wait.</p>
<p>After a while run  mysqldumpslow as root. If there are any slow queries logged, you will see summary, here is mine:</p>
<pre><code>Reading mysql slow query log from /var/log/mysql/mysql-slow.log

<strong>Count:</strong> <strong>36  Time=549.81s</strong> (19793s)  Lock=0.00s (0s)  Rows=0.0 (0)
SELECT Bug.ixBug AS ix, Bug.ixBugEventLatest AS ixChild,
       Area.nTypeAs nAreaType
FROM (Bug INNER JOIN Area ON Bug.ixArea = Area.ixArea)
WHERE ixBugEventLatest  &lt;= N
       AND ixBugEventLatest &gt;= N AND Bug.ixBug IN
          (SELECT ix FROM IndexDelta WHERE sType = 'S'
           AND fDeleted = N)
       AND -N =  -N
ORDER BY ixBugEventLatest  DESC  
LIMIT N</code></pre>
<p>Query listed above appears to take around 10 minutes to execute. Now check the tables type in the MySQL<br />
<code>mysql&gt; show table status;</code><br />
In our scenario I found that all tables are MyISAM. That means, that while query is executed (10 minutes) tables used in it will be locked for writing. So, if someone tries to update bug, they have to wait up to 10 minutes.</p>
<p>Check what MySQL engines you have:</p>
<pre><code>mysql&amp;gt; show engines;

+---------+----------+---------------------------
| Engine  | Support  | Comment                  
+---------+----------+---------------------------
| MyISAM  | DEFAULT  | Default engine as of MySQL
| MEMORY  | YES      | Hash based, stored in memory
| InnoDB  | YES      | Supports transactions, row-
...</code></pre>
<p>If InnoDB is supported, then all what has to be done to speed up application is switching to InnoDB in this situation. This will not make query above run any faster, but, that will not lock the whole table for the time query is running. There are some benefits of MyISAM table type (well, it&#8217;s faster!), so you may don&#8217;t want to convert all tables to InnoDB at this point. But large tables with concurrent updates and reads will benefit.</p>
<p>If InnoDB is not supported, it can be turned on in MySQL configuration file, just comment out skip-innodb line.</p>
<p>In case of FogBugz I found the following tables to be worst offenders:<br />
Bug, BugEvent, BugRelation, SorterToken, TokenAssociation.</p>
<p>To convert those, use:<br />
<code>mysql&gt; alter table Bug engine=InnoDB;</code><br />
After conversion performance of the application increased immediately, as there are no more locks on popular tables.</p>
<p>There are additional benefits of InnoDB engine, such as foreign keys. Read more on InnoDB:</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/innodb.html">http://dev.mysql.com/doc/refman/5.0/en/innodb.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/04/02/fogbugz-speed-issue-an-example-of-mysql-slow-queries-troubleshooting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

