<?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>code.openark.org &#187; Web</title>
	<atom:link href="http://code.openark.org/blog/tag/web/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Thu, 09 Sep 2010 16:15:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>mycheckpoint (rev. 190): HTTP server; interactive charts</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts#comments</comments>
		<pubDate>Tue, 07 Sep 2010 05:53:01 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2866</guid>
		<description><![CDATA[Revision 190 of mycheckpoint, a MySQL monitoring solution, has been released. New and updated in this revision: HTTP server: mycheckpoint can now act as a web server. Point your browser and start browsing through HTML reports. See mock up demo. Interactive charts: HTML line charts are now interactive, presenting with accurate data as you move [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>190</strong> of <a href="../../forge/mycheckpoint">mycheckpoint</a>, a MySQL monitoring solution, has  been released. New and updated in this revision:</p>
<ul>
<li><strong>HTTP server</strong>: <em>mycheckpoint</em> can now act as a web server. Point your browser and start browsing through HTML reports. See mock up <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00/sv_report_html_brief.html"><strong>demo</strong></a>.</li>
<li><strong>Interactive charts</strong>: HTML line charts are now interactive, presenting with accurate data as you move over them. See <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00_samples/sv_report_html_brief.html"><strong>sample</strong></a>.</li>
<li><strong>Enhanced auto-deploy</strong>: now auto-recognizing failed upgrades.</li>
<li><strong>Reduced footprint</strong>: much code taken out of the views, leading to faster loading times.</li>
<li><strong>Better configuration file use</strong>: now supporting all command line options in config file.</li>
<li><strong>Remote host monitoring accessibility</strong>: now supporting complete configurable accessibility details.</li>
<li><strong>Bug fixes</strong>: thanks to the bug reporters!</li>
</ul>
<p><em>mycheckpoint</em> is free, simple, easy to use (now easier with HTTP server) and <strong>useful</strong>. I encourage you to try it out: even compared with other existing and emerging monitoring tools, I believe you will find it a breeze; it&#8217;s low impact and lightness appealing; it&#8217;s alerts mechanism assuring; its geeky SQL-based nature with ability to drill down to fine details &#8212; geeky-kind-of-attractive.</p>
<p>&lt;/encouragement&gt;</p>
<h4>HTTP server</h4>
<p>You can now run <em>mycheckpoint</em> in <em>http</em> mode:</p>
<blockquote>
<pre>bash$ <strong>mycheckpoint http</strong></pre>
</blockquote>
<p><em>mycheckpoint</em> will listen on port <strong>12306</strong>, and will present you with easy browsing through the reports of your <em>mycheckpoint</em> databases.<span id="more-2866"></span></p>
<p>The <em>http</em> server automatically detects those schemata used by mycheckpoint, and utilizes the existing HTML views, integrating them into the greater web framework.</p>
<p>While in <em>http</em> mode, mycheckpoint does nothing besides serving web pages. It does not actively exercise monitoring: you must still use the usual cron jobs or other scheduled tasks by which you invoke <em>mycheckpoint</em> for monitoring.</p>
<p>The http server is directed at a single MySQL server, as with the following example:</p>
<blockquote>
<pre>bash$ <strong>mycheckpoint --host=slave1.localdomain --port=3306 --http-port=12306 http</strong></pre>
</blockquote>
<p>It is assumed that this server has the monitoring schemata.</p>
<p>See mock up <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00/sv_report_html_brief.html"><strong>demo</strong></a>. The demo uses presents with real output from a mycheckpoint HTTP server; I haven&#8217;t got the means to put up a live demo.</p>
<h4>Interactive charts</h4>
<p>The <em>openark line charts</em>, used in the HTML reports, are now interactive. As you scroll over, the legend presents you with series values.</p>
<p>No more <em>&#8220;I have this huge spike once every 4 hours, which reduces all other values to something that looks like zero but is actually NOT&#8221;</em>. Hover, and see the real values.</p>
<p>See <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00_samples/sv_report_html_brief.html"><strong>sample</strong></a>.</p>
<h4>Enhanced auto-deploy</h4>
<p>The idea with mycheckpoint is that it should know how to self upgrade the schema on version upgrade (much like automatic WordPress upgrades). mycheckpoint does bookkeeping of installed versions within the database, and upgrades by simple comparison.</p>
<p>It now, following a couple of reported bugs, also recognizes failure of partial, failed upgrades. This adds to the automation of <em>mycheckpoint</em>&#8216;s installation.</p>
<h4>Reduced footprint</h4>
<p>Some of <em>mycheckpoint</em>&#8216;s views are complicated, and lead to a large amount of code in view declaration. This leads to increased table definition size (large <strong>.frm</strong> files). There has been some work to reduce this size where possible. Work is still ongoing, but some 30% has been taken off already. This leads to faster table (view) load time.</p>
<h4>Better configuration file use</h4>
<p>Any argument supported on the command line is now also supported in the config style. Much like is handled with MySQL. For example, one can issue:</p>
<blockquote>
<pre>mycheckpoint --monitored-host=sql02.mydb.com  --monitored-user=monitor --monitored-password=123456</pre>
</blockquote>
<p>But now also:</p>
<blockquote>
<pre>mycheckpoint</pre>
</blockquote>
<p>With the following in <strong>/etc/mycheckpoint.cnf</strong>:</p>
<blockquote>
<pre>[mycheckpoint]
monitored_host     = sql02.mydb.com
monitored_user     = monitor
monitored_password = 123456
</pre>
</blockquote>
<p>Rules are:</p>
<ul>
<li>If an option is specified on command line, it takes precedence over anything else.</li>
<li>Otherwise, if it&#8217;s specified in the configuration file, value is read from file.</li>
<li>Otherwise use default value is used.</li>
<li>On command line, option format is<strong> xxx-yyy-zzz</strong>: words split with dash/minus character.</li>
<li>On configuration file, option format is <strong>xxx_yyy_zzz</strong>: words split with underscore. Unlike MySQL configuration format, dashes cannot be used.</li>
<li>If an option is specified multiple times on configuration file &#8212; well &#8212; I have the answer, but I won&#8217;t tell. Just don&#8217;t do it. It&#8217;s bad for your health.</li>
</ul>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>A proper <em>man</em> page.</li>
<li>Anything else that interests me &amp; the users.</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It’s a different kind of monitoring   solution. Simple monitoring (charting) is immediate. For more interesting results you will need basic SQL skills, and in return you’ll get a lot   of power under your hands.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project’s <a href="../../forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="../../forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD  License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Static charts vs. interactive charts</title>
		<link>http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts</link>
		<comments>http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts#comments</comments>
		<pubDate>Tue, 02 Mar 2010 13:28:08 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2027</guid>
		<description><![CDATA[I&#8217;m having my usual fun with charts. Working on mycheckpoint, I&#8217;ve generated monitoring charts using the Google Chars API. But I&#8217;ve also had chance to experiment and deploy interactive charts, JavaScript based. In particular, I used and tweaked dygraphs. I&#8217;d like to note some differences in using charts of both kinds. And I think it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m having my usual fun with charts. Working on <a href="http://code.openark.org/forge/mycheckpoint">mycheckpoint</a>, I&#8217;ve generated monitoring charts using the <a href="http://code.google.com/apis/chart/image_charts.html">Google Chars API</a>. But I&#8217;ve also had chance to experiment and deploy interactive charts, JavaScript based. In particular, I used and tweaked <a href="http://www.danvk.org/dygraphs/">dygraphs</a>.</p>
<p>I&#8217;d like to note some differences in using charts of both kinds. And I think it makes a very big difference.</p>
<h4>Static charts</h4>
<p>I&#8217;ll call any image-based chart by &#8220;static chart&#8221;. It&#8217;s just a static image. Example of such charts are those generated by Google Image Charts (they now also have new, interactive charts), or <a href="http://oss.oetiker.ch/rrdtool/index.en.html">RRDtool</a>. Show below is an example of a static chart; in this example, generated by Google:<span id="more-2027"></span></p>
<blockquote>
<pre><img class="alignnone" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chts=808080,12&amp;chtt=Dec+4,+15:00++-++Dec+5,+15:00&amp;chf=c,s,ffffff&amp;chdl=com_select_psec|com_insert_psec|com_delete_psec|com_update_psec|com_replace_psec&amp;chdlp=b&amp;chco=ff8c00,4682b4,9acd32,dc143c,9932cc&amp;chd=s:zpvxszxsxur11p1xt10wyxzuyv6xw4yx3x041x2zz6zvz7y91x23z4niqkkmojllkhknhlgnmimohilkkqgkkmnmhlljinjmnhmo________________imlnpmkukopmnpjsojnrrlrqnpprs,iZagVcgWXaZdjVbgSbhYdXZXZcbcXZbcadabccabbZaaZeabdYbbZXceWUXaXYXSXVXaSSZUUXWYUUXbTYUUVabWWVZZVYaWZZYa________________ZYbVcXWdYWZcXaYaYWXYfZcdaVZaZ,MNNNNNONLKOMPNNMNNOPMNNLMQNOMMMNMNNNNRONNOPMNQMPONPOLMTNKJKMKKJILKILJJJLIIKUMHJJIIHHHKJIIHIIIHJHIIJM________________NOMLMMLOPOPKLKKNPKMMNMOPQNNOL,NIIMHKOIHKIKOHKMGKNJKIJIKMKLJJMKIKJKLLJLLJLLKMLJLJKKKIIVIIJLJKJHJIKLIHMIIKIKIIKLHKIIJLKIJJKKIJKIKKJK________________IIKILJJLKIKKHJJJJIJJMIKLKGJKK,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________AAAAAAAAAAAAAAAAAAAAAAAAAAAAA&amp;chxt=x,y&amp;chxr=1,0,136.620000&amp;chxl=0:||16:00||+||20:00||+||00:00||+||04:00||+||08:00||+||12:00||+||&amp;chxs=0,505050,10,0,lt&amp;chg=4.17,25,1,2,0.00,0&amp;chxp=0,0.00,4.17,8.34,12.51,16.68,20.85,25.02,29.19,33.36,37.53,41.70,45.87,50.04,54.21,58.38,62.55,66.72,70.89,75.06,79.23,83.40,87.57,91.74,95.91,100.08" alt="" width="400" height="200" /></pre>
</blockquote>
<h4>Pros and cons of static charts</h4>
<p>Pros</p>
<ul>
<li>Images can be viewed on any graphical platform. Browsers, email clients, cell phones, whatever.</li>
<li>Self contained: chart image, legend, scales: all in one image.</li>
<li>As such, easy to move around.</li>
<li>Are safe to use.</li>
</ul>
<p>Cons</p>
<ul>
<li>Images are fuzzy. Is the <strong>com_replace_psec</strong> really 0? Maybe it&#8217;s 0.1? A larger value can make lower values hard to tell.</li>
<li>Images are inaccurate: the colors can lie. The red and green lines showing are hard to tell apart. The red is painted above the green. Data gets &#8220;lost&#8221;.</li>
<li>They do not zoom (one needs to regenerate larger image)</li>
<li>Unless encoded with base64, HTML pages which include images need to link outside.</li>
<li>In the particular case of Google Charts, one is limited to 2K length URL. Trust me, it&#8217;s a big limitation! (PS, Google now support POST method to allow for up to 16K. But&#8230; it&#8217;s a POST method&#8230;)</li>
<li>In the particular case of Google Charts, one must have an internet connection.</li>
<li>In the particular case of Google Charts, one must submit data to Google.</li>
</ul>
<h4>Interactive charts</h4>
<p>Interactive charts are those which react to your commands. These are either JavaScript or Flash based, mostly. They allow for really nice features. Take the following chart as an example: try and <strong>move over with your mouse</strong>; or <strong>select sections to zoom in</strong>.</p>
<p><script src="http://code.openark.org/blog/wp-content/uploads/2010/03/dygraph-combined.js" type="text/javascript"></script><br />
<!--[if IE]><script src="http://code.openark.org/blog/wp-content/uploads/2010/03/excanvas-min.js"></script>< ![endif]--></p>
<blockquote>
<pre>
<h4>DML</h4>
<div id="graphDiv_DML" class="graphdiv" style="width: 400px; height: 160px;">[graphDiv]</div>
<div id="labelsDiv_DML" class="legend">[labelsDiv]</div>
</pre>
</blockquote>
<p><script type="text/javascript">// < ![CDATA[
// < ![CDATA[
 g_DML = new Dygraph( document.getElementById("graphDiv_DML"),                         "Date,com_select_psec,com_insert_psec,com_delete_psec,com_update_psec,com_replace_psec\n2009-12-04 15:00:00,113.28,76.54,26.14,29.54,0.00\n2009-12-04 15:10:00,91.51,55.74,30.07,18.13,0.00\n2009-12-04 15:20:00,104.98,57.75,28.26,18.24,0.00\n2009-12-04 15:30:00,110.64,72.17,30.17,27.58,0.00\n2009-12-04 15:40:00,97.79,46.27,29.27,15.91,0.00\n2009-12-04 15:50:00,114.35,61.85,29.55,22.45,0.00\n2009-12-04 16:00:00,110.82,72.38,30.67,30.70,0.00\n2009-12-04 16:10:00,99.05,49.70,29.35,18.56,0.00\n2009-12-04 16:20:00,109.68,50.87,25.74,16.55,0.00\n2009-12-04 16:30:00,103.92,58.70,22.09,22.58,0.00\n2009-12-04 16:40:00,97.24,56.29,31.71,18.78,0.00\n2009-12-04 16:50:00,119.25,65.72,27.80,22.56,0.00\n2009-12-04 17:00:00,118.31,78.34,34.18,30.43,0.00\n2009-12-04 17:10:00,91.06,47.59,29.66,16.60,0.00\n2009-12-04 17:20:00,117.81,59.82,28.94,21.40,0.00\n2009-12-04 17:30:00,109.79,71.37,27.62,27.64,0.00\n2009-12-04 17:40:00,101.07,40.51,29.57,14.18,0.00\n2009-12-04 17:50:00,117.66,61.18,28.31,22.44,0.00\n2009-12-04 18:00:00,115.48,72.82,32.12,28.74,0.00\n2009-12-04 18:10:00,106.51,54.34,32.96,20.37,0.00\n2009-12-04 18:20:00,111.34,65.11,27.60,22.60,0.00\n2009-12-04 18:30:00,109.66,52.25,29.47,18.47,0.00\n2009-12-04 18:40:00,113.63,55.16,28.67,19.98,0.00\n2009-12-04 18:50:00,103.72,51.86,24.67,18.08,0.00\n2009-12-04 19:00:00,111.27,55.78,26.66,22.62,0.00\n2009-12-04 19:10:00,105.73,63.16,35.37,25.88,0.00\n2009-12-04 19:20:00,130.50,60.07,29.82,22.99,0.00\n2009-12-04 19:30:00,110.41,62.64,30.35,24.46,0.00\n2009-12-04 19:40:00,107.05,52.04,27.15,19.22,0.00\n2009-12-04 19:50:00,126.11,57.06,27.12,19.34,0.00\n2009-12-04 20:00:00,111.36,61.40,26.13,25.96,0.00\n2009-12-04 20:10:00,108.82,61.97,29.52,23.49,0.00\n2009-12-04 20:20:00,122.57,59.28,26.03,18.48,0.00\n2009-12-04 20:30:00,109.35,65.42,29.21,23.13,0.00\n2009-12-04 20:40:00,117.19,57.69,28.01,19.24,0.00\n2009-12-04 20:50:00,125.03,61.15,28.95,21.74,0.00\n2009-12-04 21:00:00,118.31,63.11,29.66,23.99,0.00\n2009-12-04 21:10:00,109.98,62.24,38.77,24.02,0.00\n2009-12-04 21:20:00,121.28,57.78,30.48,20.26,0.00\n2009-12-04 21:30:00,113.89,59.62,29.77,23.72,0.00\n2009-12-04 21:40:00,113.93,60.42,29.35,24.71,0.00\n2009-12-04 21:50:00,130.36,55.68,31.94,21.16,0.00\n2009-12-04 22:00:00,114.11,58.93,32.62,24.41,0.00\n2009-12-04 22:10:00,105.52,58.58,26.04,24.47,0.00\n2009-12-04 22:20:00,113.52,57.04,29.26,22.28,0.00\n2009-12-04 22:30:00,132.64,66.22,34.87,26.82,0.00\n2009-12-04 22:40:00,112.08,59.19,27.16,23.73,0.00\n2009-12-04 22:50:00,136.62,59.74,33.41,20.04,0.00\n2009-12-04 23:00:00,119.58,65.67,31.40,24.40,0.00\n2009-12-04 23:10:00,109.12,53.74,28.38,19.60,0.00\n2009-12-04 23:20:00,121.52,60.03,33.16,22.38,0.00\n2009-12-04 23:30:00,123.33,59.59,31.09,22.51,0.00\n2009-12-04 23:40:00,114.75,56.82,25.53,23.43,0.00\n2009-12-04 23:50:00,124.92,51.26,27.86,19.03,0.00\n2009-12-05 00:00:00,88.23,63.21,41.50,18.59,0.00\n2009-12-05 00:10:00,75.10,66.62,29.94,48.01,0.00\n2009-12-05 00:20:00,94.85,49.27,22.05,18.66,0.00\n2009-12-05 00:30:00,80.27,45.21,20.56,17.55,0.00\n2009-12-05 00:40:00,80.96,52.03,21.66,21.14,0.00\n2009-12-05 00:50:00,85.21,57.68,26.57,23.58,0.00\n2009-12-05 01:00:00,88.66,52.56,21.75,20.94,0.00\n2009-12-05 01:10:00,78.66,53.26,22.89,22.36,0.00\n2009-12-05 01:20:00,83.80,50.74,20.65,19.49,0.00\n2009-12-05 01:30:00,82.70,39.99,17.23,15.86,0.00\n2009-12-05 01:40:00,79.66,52.35,23.55,20.94,0.00\n2009-12-05 01:50:00,74.56,47.64,23.05,18.97,0.00\n2009-12-05 02:00:00,81.25,51.35,17.94,21.61,0.00\n2009-12-05 02:10:00,86.83,58.48,25.03,24.95,0.00\n2009-12-05 02:20:00,73.31,41.39,21.09,17.56,0.00\n2009-12-05 02:30:00,82.31,39.70,19.84,16.74,0.00\n2009-12-05 02:40:00,71.19,55.84,19.05,25.97,0.00\n2009-12-05 02:50:00,88.00,44.13,25.32,17.74,0.00\n2009-12-05 03:00:00,84.54,44.78,18.42,18.78,0.00\n2009-12-05 03:10:00,76.92,50.57,17.91,21.81,0.00\n2009-12-05 03:20:00,84.45,49.12,21.54,18.58,0.00\n2009-12-05 03:30:00,89.52,54.20,45.41,22.39,0.00\n2009-12-05 03:40:00,74.15,44.67,26.54,18.04,0.00\n2009-12-05 03:50:00,76.32,44.36,15.02,18.39,0.00\n2009-12-05 04:00:00,83.90,52.30,19.50,22.39,0.00\n2009-12-05 04:10:00,80.26,61.12,20.66,25.68,0.00\n2009-12-05 04:20:00,80.95,42.11,16.95,14.84,0.00\n2009-12-05 04:30:00,93.01,53.36,17.91,21.94,0.00\n2009-12-05 04:40:00,72.70,45.22,16.63,18.16,0.00\n2009-12-05 04:50:00,81.22,44.73,15.41,18.54,0.00\n2009-12-05 05:00:00,80.02,46.60,16.07,21.04,0.00\n2009-12-05 05:10:00,84.33,57.86,21.77,24.71,0.00\n2009-12-05 05:20:00,87.48,60.54,19.66,22.95,0.00\n2009-12-05 05:30:00,86.19,48.62,18.47,17.51,0.00\n2009-12-05 05:40:00,72.92,50.10,18.46,21.00,0.00\n2009-12-05 05:50:00,81.79,48.14,15.75,19.36,0.00\n2009-12-05 06:00:00,83.11,55.70,17.15,23.02,0.00\n2009-12-05 06:10:00,77.98,55.89,18.36,23.16,0.00\n2009-12-05 06:20:00,77.05,45.96,18.06,17.27,0.00\n2009-12-05 06:30:00,87.58,53.76,15.56,20.79,0.00\n2009-12-05 06:40:00,79.33,58.86,21.02,22.84,0.00\n2009-12-05 06:50:00,85.33,49.99,16.23,18.82,0.00\n2009-12-05 07:00:00,87.54,56.70,17.96,23.31,0.00\n2009-12-05 07:10:00,73.33,56.51,17.57,21.74,0.00\n2009-12-05 07:20:00,84.02,52.77,21.21,20.80,0.00\n2009-12-05 07:30:00,88.86,58.34,27.45,23.10,0.00\n2009-12-05 07:40:00,,,,,\n2009-12-05 07:50:00,,,,,\n2009-12-05 08:00:00,,,,,\n2009-12-05 08:10:00,,,,,\n2009-12-05 08:20:00,,,,,\n2009-12-05 08:30:00,,,,,\n2009-12-05 08:40:00,,,,,\n2009-12-05 08:50:00,,,,,\n2009-12-05 09:00:00,,,,,\n2009-12-05 09:10:00,,,,,\n2009-12-05 09:20:00,,,,,\n2009-12-05 09:30:00,,,,,\n2009-12-05 09:40:00,,,,,\n2009-12-05 09:50:00,,,,,\n2009-12-05 10:00:00,,,,,\n2009-12-05 10:10:00,,,,,\n2009-12-05 10:20:00,77.11,55.87,29.31,18.09,0.00\n2009-12-05 10:30:00,85.31,53.70,31.03,18.46,0.00\n2009-12-05 10:40:00,82.72,61.32,26.30,22.98,0.00\n2009-12-05 10:50:00,87.28,46.53,25.04,18.04,0.00\n2009-12-05 11:00:00,92.07,62.62,27.09,25.14,0.00\n2009-12-05 11:10:00,84.59,50.42,25.97,19.96,0.00\n2009-12-05 11:20:00,80.34,49.64,25.75,20.31,0.00\n2009-12-05 11:30:00,103.61,64.36,31.79,24.71,0.00\n2009-12-05 11:40:00,80.03,54.33,33.83,22.37,0.00\n2009-12-05 11:50:00,90.42,48.24,31.26,18.43,0.00\n2009-12-05 12:00:00,92.51,56.34,33.53,22.45,0.00\n2009-12-05 12:10:00,84.34,62.26,22.66,23.31,0.00\n2009-12-05 12:20:00,86.24,51.96,25.69,16.02,0.00\n2009-12-05 12:30:00,92.08,58.61,23.16,19.34,0.00\n2009-12-05 12:40:00,78.48,53.33,22.72,19.51,0.00\n2009-12-05 12:50:00,97.85,57.71,29.80,20.19,0.00\n2009-12-05 13:00:00,89.23,54.84,34.62,20.93,0.00\n2009-12-05 13:10:00,78.92,50.02,22.47,18.19,0.00\n2009-12-05 13:20:00,87.24,50.92,26.37,19.38,0.00\n2009-12-05 13:30:00,96.29,54.78,27.13,20.04,0.00\n2009-12-05 13:40:00,96.39,69.48,30.21,27.19,0.00\n2009-12-05 13:50:00,83.21,55.13,26.48,18.00,0.00\n2009-12-05 14:00:00,97.00,63.61,30.89,22.23,0.00\n2009-12-05 14:10:00,94.65,65.33,33.51,25.04,0.00\n2009-12-05 14:20:00,86.94,58.14,36.10,22.07,0.00\n2009-12-05 14:30:00,91.91,47.25,28.41,14.45,0.00\n2009-12-05 14:40:00,92.55,55.73,29.59,20.69,0.00\n2009-12-05 14:50:00,97.35,58.90,31.63,22.22,0.00\n2009-12-05 15:00:00,97.91,56.09,23.80,21.68,0.00\n",                         { chartDiv:  document.getElementById("chartDiv_DML"), labelsDiv: document.getElementById("labelsDiv_DML") } ); g_DML.resize(400,160);
// ]]&gt;</script></p>
<p>The above chart is generated with <em>dygraphs</em>. Since it is embedded within my WordPress page, the layout is affected by that of my theme. Take a look at this <a href="http://code.openark.org/blog/wp-content/uploads/2010/03/mycheckpoint_interactive_demo.html"><strong>example page</strong></a> to see similar charts outside this blog site (Internet Explorer users: Maxmimize/minimize button will not work well for now. And, may I suggest <a href="http://www.mozilla.com/en-US/firefox">Mozilla Firefox</a>?)<a href="http://code.openark.org/blog/wp-content/uploads/2010/03/mycheckpoint_interactive_demo.html"></a></p>
<h4>Pros and cons of interactive charts</h4>
<p>Pros</p>
<ul>
<li>Can present you with exact values. No more doubt about the <strong>com_replace_psec</strong> values.</li>
<li>Can allow for zoom in, zoom out.</li>
</ul>
<p>Cons</p>
<ul>
<li>Need supporting platform. The above cannot be viewed by non-JavaScript browsers (cell phones, etc.)</li>
<li>Browser support is also an issue with JavaScript.</li>
<li>Emailing such report will result in mail blocking in many companies: mail filters will not allow for JavaScript code to pass.</li>
<li>Charts are not necessarily self-contained, in terms of the chart entity With Flash charts (e.g. Fusion Charts) this works. But in the above, the legend and scales are outside the image. As such, they cannot be just moved around.</li>
<li>HTML pages which include such charts <em>can be</em> self contained. The HTML page can include all the JavaScript dependencies, in addition to the chart generating code. Flash based charts cannot be self contained.</li>
</ul>
<h4>Summary</h4>
<p>Interactive charts are cool!</p>
<p>I&#8217;m now integrating <a href="http://www.danvk.org/dygraphs/">dygraphs</a> into <em>mycheckpoint</em> (How nice it is to work with BSD &amp; MIT licenses!). Though I may later switch to <a href="http://code.google.com/p/flot/">flot</a>, interactive charts will be the next standard charting way in <em>mycheckpoint</em>. I will continue supporting static Google Charts, as follows from the above pros and cons list.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The DB problem inherent to dynamic web pages</title>
		<link>http://code.openark.org/blog/mysql/the-db-problem-inherent-to-dynamic-web-pages</link>
		<comments>http://code.openark.org/blog/mysql/the-db-problem-inherent-to-dynamic-web-pages#comments</comments>
		<pubDate>Mon, 20 Jul 2009 11:48:56 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=955</guid>
		<description><![CDATA[When building web sites, a popular demand is a maximum page load time. For example, many would require &#60; 0.5 seconds (or even less) for major pages loading time. Of course, there are numerous factors for page load time: network, caching, web servers, scripting language/code, database access and more. Naturally I want to discuss the [...]]]></description>
			<content:encoded><![CDATA[<p>When building web sites, a popular demand is a maximum page load time.</p>
<p>For example, many would require &lt; 0.5 seconds (or even less) for major pages loading time. Of course, there are numerous factors for page load time: network, caching, web servers, scripting language/code, database access and more.</p>
<p>Naturally I want to discuss the use of database access when creating web pages. I&#8217;ll be referring to dynamic web pages, such that are created by common languages as PHP, Java/J2EE, Ruby, ASP(.NET) etc.</p>
<p>A very common programming style is &#8211; what&#8217;s called in the Java jargon &#8211; using &#8220;scriptlets&#8221; as in the following JSP page:</p>
<blockquote>
<pre>&lt;html&gt;
&lt;body&gt;
    Time now is &lt;%= new java.util.Date() %&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p>The above replaces the &#8220;<em>&lt;%= new java.util.Date() %&gt;</em>&#8221; part with a text representation of the current time.</p>
<p>If I were to produce a dynamic content site, say, a WordPress blog, like the one you&#8217;re reading, I would need to generate several dynamic contents: the latest posts, the popular tags, the comments for this post, etc. These are generated by calling upon the database and running some queries. I suppose there&#8217;s nothing new in what I&#8217;ve explained so far.</p>
<h4>The problem</h4>
<p>When generating a &#8220;heavyweight&#8221; page, like some online newspaper or bookstore, there may be many queries involved. Are you logged in? Do we have recommendations for you? What are the latest topics? What have you been interested in before? Do you have friends online? What content have you produced on the website?</p>
<p><span id="more-955"></span>I&#8217;ve recently reviewed a site which generated &gt; 500 queries per single page. I personally thought that was a very high number, but that was a necessity. The problem was: the page took 2 seconds to load.</p>
<p>Some tuning, rewriting and indexing later, time dropped to 0.6 seconds to load; but that was not fast enough. It was then that we got to a major conclusion:</p>
<blockquote><p>All database calls are serialized. They need to be parallelized.</p></blockquote>
<p>Remember that MySQL can only utilize a single thread for the computation of a single query (though more threads can handle IO in the meantime). This leads to only one CPU being used on your standard Linux distribution, for a given web page.</p>
<p>Really, that sounds just too obvious! But not so easy to achieve when doing &#8220;scriptlets&#8221;. The templating engine parses the scriptlets one by one, executing them in order. In fact, you assume it does so, so that you can rely on the outcome of the previous scriptlet in the next one. In Java, for example, it goes beyond that: a JSP page is rewritten as a normal Java Servlet class, where the &#8220;scriptlets&#8221; become the main code, and the HTML becomes just printing to standard output. So you get linear executing code.</p>
<p>Even with more sophisticated frameworks, the &#8220;normal&#8221; way of doing things is linear. For example, using the Spring framework, you have Java objects &#8212; controllers &#8212; which are responsible for web pages. You can avoid doing scpriting within your dynamic web pages, and only ask for data provided by those controllers. So, for example, using <a href="http://www.springsource.org/">Spring</a> + <a href="http://velocity.apache.org/">Velocity</a>, a web page could look like this:</p>
<blockquote>
<pre>&lt;html&gt;
&lt;body&gt;
    Login time as recorded in DB is: ${user.loginTime}
&lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p>This (usually) translates to calling the <em>getLoginTime()</em> method on a pre-built <em>user</em> object. But just how does this method work?</p>
<ul>
<li>Does it do lazy initialization, so that it calls upon the DB to get the answer?</li>
<li>Did the controller set up the value during some init() method?</li>
<li>Did the controller set up the value in response to the web page&#8217;s request parameter, parsing them one by one?</li>
</ul>
<p>All the above options lead to linear, or serial execution.</p>
<h4>How to parallelize?</h4>
<p>Parallelization with web pages is not so simple, and requires understanding of multi threading programming. The programmer needs to be aware of race conditions, deadlocks, starvation issues, etc. (though, to be honest, in dynamic web pages context these do not usually become a real issue). Some programming languages provide good support for multi threaded programming. Java is one such language.</p>
<p>Let&#8217;s assume, then, that we need to spawn some 10 queries in response to a page request. With Jjava, we can write something like:</p>
<blockquote>
<pre>CountDownLatch doneSignal = <strong>new</strong> CountDownLatch(10);

Runnable task1 = <strong>new</strong> Runnable() {
    <strong>public</strong> <strong>void</strong> run()
    {
        user.setLoginTime(<strong>this</strong>.jdbcTemplate.queryForInt("SELECT ... FROM ..."));
        doneSignal.countDown();
    }
} ;

Runnable task2 = <strong>new</strong> Runnable() {
    <strong>public</strong> <strong>void</strong> run()
    {
        headlines = getSimpleJdbcTemplate().query("SELECT * FROM headline WHERE...",
            <strong>new</strong> ParameterizedRowMapper&lt;Headline&gt;() {
                <strong>public</strong> Headline mapRow(ResultSet rs, <strong>int</strong> rowNum)
                {
                    Headline headline = <strong>new</strong> Headline();
                    headline.setTitle(rs.getString("title");
                    headline.setUrl(rs.getString("url");
                    ...
                }
            }
        doneSignal.countDown();
    }
} ;

...

Runnable task10 = <strong>new</strong> Runnable() {
    ...
    doneSignal.countDown();
}
Executor executor = Executors.newFixedThreadPool(numberOfAvailableProcessors);
executor.execute(task1);
...
executor.execute(task10);

doneSignal.await();

// Now fill in the Model</pre>
</blockquote>
<p>The above code is simplified and presented in a way which is more readable. What it says is:</p>
<ul>
<li>Let&#8217;s create the 10 tasks, but not execute them: just lay out the commands.</li>
<li>Each task, upon completion, lets the <strong>CountDownLatch</strong> know it has completed (but remeber we have not executed it yet).</li>
<li>We create or use a thread pool, using some <em>n</em> threads; <em>n</em> may relate to the number of processors we have.</li>
<li>We ask the pool to execute all threads. At the discretion of the pool, it will either run them all concurrently, or some sequentially &#8211; depending on how many threads are available.</li>
<li>We ask the <strong>CountDownLatch</strong> &#8212; a one-time <em>barrier</em> &#8212; to block, until all 10 tasks have notified they&#8217;re done.</li>
<li>We can now go on and do our stuff.</li>
</ul>
<p>Spring has a built in <a href="http://static.springsource.org/spring/docs/2.5.x/reference/scheduling.html#scheduling-task-executor">TaskExecutor</a> mechanism to provide solution similar to the thread pool above.</p>
<p>I&#8217;m mostly a C/C++/Java programmer; I have no knowledge on how this can be achieved in PHP, Ruby, ASP.NET or other languages. The above code is certainly not the most straightforward to use. I would like to see frameworks provide wrappers for this kind of solution, so as to support the common web developer with parallelization.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/the-db-problem-inherent-to-dynamic-web-pages/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
