<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>Solution Hacker &#187; 6. Uncategorized</title>
	<atom:link href="http://www.solutionhacker.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solutionhacker.com</link>
	<description>This blog provides solutions for enterpreneurs!</description>
	<lastBuildDate>Mon, 06 Feb 2012 07:19:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=184</generator>
<!-- podcast_generator="Blubrry PowerPress/2.0.4" -->
	<itunes:summary>This blog provides solutions for enterpreneurs!</itunes:summary>
	<itunes:author>Solution Hacker</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.solutionhacker.com/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:subtitle>This blog provides solutions for enterpreneurs!</itunes:subtitle>
	<image>
		<title>Solution Hacker &#187; 6. Uncategorized</title>
		<url>http://www.solutionhacker.com/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://www.solutionhacker.com/category/uncategorized/</link>
	</image>
		<item>
		<title>Hacking CSS</title>
		<link>http://www.solutionhacker.com/uncategorized/hacking-css/</link>
		<comments>http://www.solutionhacker.com/uncategorized/hacking-css/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 03:28:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=484</guid>
		<description><![CDATA[<p>Recently, I have built some of the websites from church and friends via Wordpress, a popular blogging/ CMS system. Being very impressed by the quality of the themes and rich plug-ins, I decide to take a step further to learn about the Wordpress programming model. I can do that via writing my simple Hello world plugin. However, it doesn&#39;t allow me to grasp the full power of Wordpress framework. So, I decide to study about a sophisticated Wordpress theme and find out how it integrated with Wordpress and leveraged its plug-ins. To do that, I need to ramp up CSS, PHP in few days. This article is the quick note that summarized what I have learnt about CSS. Hope it is helpful to you as well.</p>
<p><!--more--></p>
<h2>Class and ID Selector</h2>
<blockquote>
	<p>/* The difference between an ID and a class is that an ID can be used to identify <br />
		one element, whereas a class can be used to identify more than one. */</p>
	<p>/* class selector */<br />
		.intro<br />
		<br />
		/* id selector*/<br />
		#top<br />
		<br />
		/* built-in html element (no need to put symbol) */<br />
		p<br />
		<br />
		/* locate specific element - paragraph with class=jam <br />
		&#160;&#160; (for example &#60;p class=jam&#62;xxx&#60;/p&#62;) */<br />
		p.jam {xxxx}&#160; <br />
		<br />
		/* apply grouping */<br />
		h2, .thisClass, .thatClass {...}<br />
		<br />
		/* nested selector */<br />
		#top{...}<br />
		#top h1{...}<br />
		<br />
		/* state of an element (ex. link) */<br />
		a.snowman:link<br />
		a.snowman:visited<br />
		a.snowman:active<br />
		a.snowman:hover<br />
		<br />
		/* shorthand : margin, padding, border-width where th<br />
		p {<br />
		&#160;&#160;&#160; border-top-width: 1px;<br />
		&#160;&#160;&#160; border-right-width: 5px;<br />
		&#160;&#160;&#160; border-bottom-width: 10px;<br />
		&#160;&#160;&#160; border-left-width: 20px;<br />
		}<br />
		<br />
		//can be<br />
		p {<br />
		&#160;&#160;&#160; border-width: 1px 5px 10px 20px;<br />
		}<br />
		<br />
		//border-width, border-color and border-style shorthand<br />
		p {<br />
		&#160;&#160;&#160; border: 1px red solid;<br />
		}<br />
		<br />
		margin: 1em 10em; // top/bottom = 1em, left/right = 10em<br />
		<br />
		//background-color, background-image, background-repeat, background-position<br />
		body {<br />
		&#160;&#160;&#160; background: white url(<a class="linkification-ext" href="http://www.htmldog.com/images/bg.gif" title="Linkification: http://www.htmldog.com/images/bg.gif">http://www.htmldog.com/images/bg.gif</a>) no-repeat top right;<br />
		}</p>
</blockquote>
<p>&#160;</p>
<h2>Box Model</h2>
<p>All html tags/ elements in html can be think of within its own box/ container. And it can be aligned on the screen in accordance with the CSS box model. Here is the box model in diagram:</p>
<p><a href="http://www.solutionhacker.com/wp-content/uploads/box-model.gif"><img alt="" class="aligncenter size-full wp-image-486" height="317" src="http://www.solutionhacker.com/wp-content/uploads/box-model.gif" title="box-model" width="433" /></a></p>
<p>I keep forgetting where is margin and padding. So, I use the word &#34;MBP&#34; to help me out where M=margin, B=border, P=padding. ;)</p>
<p>At the first glance, it is all about spacing between an element and its neighbors. However, when I see how creative people leverage <a href="http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/">negative margin</a>. I think it is good to write about it. For margin like &#34;margin: 0px -30px 0px 0px;&#34;,</p>
<p>&#160;</p>
<h2>Display Flow</h2>
<p>Once you understand how the spacing of an element, you need to under the display flow. <strong>Block element</strong> (div, p, h1) will display in an newline while <strong>Inline element</strong> (span, a, img) will display without open up an newline. You can take an element out from its flow via explicitly setting its display properties: <strong>inline, block and none</strong>. &#34;none&#34; here means not showing it at all. The difference between &#34;<strong>display:none</strong>&#34; and &#34;<strong>visibility:hidden</strong>&#34; is &#34;display:none&#34; will take the element out from the flow, so it will not leave an empty space on screen. For example when you want to print an article, you want to just print its content. So, you will do:</p>
<blockquote>
	<p>#navigation, #seeAlso, #comments, #standards {<br />
		&#160;&#160;&#160; display: none;<br />
		}</p>
</blockquote>
<p>To take an element out from the display flow but still showing it, there are 2 common ways:</p>
<ol>
	<li>Floating</li>
	<li>Positioning</li>
</ol>
<p>I will cover these in the layout section.</p>
<h2>Layout</h2>
<p><br />
	margin: -30px 0 15px 0; (clockwise: top, right, bottom, left)<br />
	Imagine margin is like a photo white border that make your photo bigger in size and it is often enforced. <br />
	So, if a photo has margin inside a div like &#34;right 50&#34; and it is <br />
	floating right as well. Because external container doesn&#39;t moved by internal element, margin-right 50 <br />
	will push the photo leftward by 50px instead. And -ve margin here will do the opposite. <br />
	<br />
	When static element (ie. no float) is given a -ve margin on top, left, it pulls the element in that specified direction.<br />
	But for bottom and left, it doesn&#39;t move but move the content surrounding towards it (ie. overlap with it). <br />
	<br />
	Possibility:<br />
	(1) use list to build a table<br />
	(2) Overlap to add emphasis<br />
	(3) Smashing 3D effect for Bevel text<br />
	(4) Layout - Flexible Document Structure<br />
	<br />
	Using negative margins with floats sometimes pisses off older browsers. Some symptoms include:<br />
	<br />
	&#160;&#160;&#160; * Making links unclickable<br />
	&#160;&#160;&#160; * Text becomes difficult to select<br />
	&#160;&#160;&#160; * Tabbing any links disappears when you lose focus<br />
	<br />
	Solution: Just add position:relative and it works!</p>
<h2><br />
	<br />
	Layout</h2>
<h3>Positioning</h3>
<p>position has 4 options: <strong>absolute, relative, static and fixed</strong></p>
<ul>
	<li><strong>absolute</strong> will take the element out from the flow and use top, left, buttom and left coordinate to locate it</li>
	<li><strong>fixed</strong> did the same as absolute but it will not move even u scroll the browser.</li>
</ul>
<h3>Floating</h3>
<p>floating an element will shift it to the right or left of a line, with surrounding content flowing around it. If you don&#39;t want the next element to wrap around the floating object, you can apply the clear property like:<strong> clear:left, clear:right and clear:both</strong></p>
<h2>@ Rules</h2>
<blockquote>
	<p>/* attach a set of css to another css file */<br />
		@import url(xyz.css);&#160; <br />
		<br />
		/* apply its content to a specified media (ex. all, aural, handheld, print, <br />
		&#160;&#160; projection, screen): IE just takes all, screen, print */<br />
		@media print{<br />
		&#160;&#160;&#160; body {xxxx}<br />
		&#160;&#160;&#160; ...<br />
		}<br />
		<br />
		/* embedded external font (not all browser supports it) */<br />
		@font-face {<br />
		&#160;&#160;&#160; font-family: somerandomfontname;<br />
		&#160;&#160;&#160; src: url(somefont.eot);<br />
		&#160;&#160;&#160; font-weight: bold;<br />
		}<br />
		<br />
		p {<br />
		&#160;&#160;&#160; font-family: somerandomfontname;<br />
		&#160;&#160;&#160; font-weight: bold;<br />
		}<br />
		&#160;</p>
</blockquote>
<h2>Reference</h2>
<p><br />
	ref: <a class="linkification-ext" href="http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/" title="Linkification: http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/">http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/</a><br />
	ref: <a class="linkification-ext" href="http://www.htmldog.com/guides/cssbeginner/" title="Linkification: http://www.htmldog.com/guides/cssbeginner/">http://www.htmldog.com/guides/cssbeginner/</a><br />
	ref: <a class="linkification-ext" href="http://www.htmldog.com/reference/cssproperties/" title="Linkification: http://www.htmldog.com/reference/cssproperties/">http://www.htmldog.com/reference/cssproperties/</a><br />
	<a class="linkification-ext" href="http://devzone.zend.com/article/627" title="Linkification: http://devzone.zend.com/article/627">http://devzone.zend.com/article/627</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Recently, I have built some of the websites from church and friends via WordPress, a popular blogging/ CMS system. Being very impressed by the quality of the themes and rich plug-ins, I decide to take a step further to learn about the WordPress programming model. I can do that via writing my simple Hello world plugin. However, it doesn&#39;t allow me to grasp the full power of WordPress framework. So, I decide to study about a sophisticated WordPress theme and find out how it integrated with WordPress and leveraged its plug-ins. To do that, I need to ramp up CSS, PHP in few days. This article is the quick note that summarized what I have learnt about CSS. Hope it is helpful to you as well.</p>
<p><span id="more-484"></span></p>
<h2>Class and ID Selector</h2>
<blockquote>
<p>/* The difference between an ID and a class is that an ID can be used to identify <br />
		one element, whereas a class can be used to identify more than one. */</p>
<p>/* class selector */<br />
		.intro</p>
<p>		/* id selector*/<br />
		#top</p>
<p>		/* built-in html element (no need to put symbol) */<br />
		p</p>
<p>		/* locate specific element &#8211; paragraph with class=jam <br />
		&nbsp;&nbsp; (for example &lt;p class=jam&gt;xxx&lt;/p&gt;) */<br />
		p.jam {xxxx}&nbsp; </p>
<p>		/* apply grouping */<br />
		h2, .thisClass, .thatClass {&#8230;}</p>
<p>		/* nested selector */<br />
		#top{&#8230;}<br />
		#top h1{&#8230;}</p>
<p>		/* state of an element (ex. link) */<br />
		a.snowman:link<br />
		a.snowman:visited<br />
		a.snowman:active<br />
		a.snowman:hover</p>
<p>		/* shorthand : margin, padding, border-width where th<br />
		p {<br />
		&nbsp;&nbsp;&nbsp; border-top-width: 1px;<br />
		&nbsp;&nbsp;&nbsp; border-right-width: 5px;<br />
		&nbsp;&nbsp;&nbsp; border-bottom-width: 10px;<br />
		&nbsp;&nbsp;&nbsp; border-left-width: 20px;<br />
		}</p>
<p>		//can be<br />
		p {<br />
		&nbsp;&nbsp;&nbsp; border-width: 1px 5px 10px 20px;<br />
		}</p>
<p>		//border-width, border-color and border-style shorthand<br />
		p {<br />
		&nbsp;&nbsp;&nbsp; border: 1px red solid;<br />
		}</p>
<p>		margin: 1em 10em; // top/bottom = 1em, left/right = 10em</p>
<p>		//background-color, background-image, background-repeat, background-position<br />
		body {<br />
		&nbsp;&nbsp;&nbsp; background: white url(<a class="linkification-ext" href="http://www.htmldog.com/images/bg.gif" title="Linkification: http://www.htmldog.com/images/bg.gif">http://www.htmldog.com/images/bg.gif</a>) no-repeat top right;<br />
		}</p>
</blockquote>
<p>&nbsp;</p>
<h2>Box Model</h2>
<p>All html tags/ elements in html can be think of within its own box/ container. And it can be aligned on the screen in accordance with the CSS box model. Here is the box model in diagram:</p>
<p><a href="http://www.solutionhacker.com/wp-content/uploads/box-model.gif"><img alt="" class="aligncenter size-full wp-image-486" height="317" src="http://www.solutionhacker.com/wp-content/uploads/box-model.gif" title="box-model" width="433" /></a></p>
<p>I keep forgetting where is margin and padding. So, I use the word &quot;MBP&quot; to help me out where M=margin, B=border, P=padding. <img src='http://www.solutionhacker.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>At the first glance, it is all about spacing between an element and its neighbors. However, when I see how creative people leverage <a href="http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/">negative margin</a>. I think it is good to write about it. For margin like &quot;margin: 0px -30px 0px 0px;&quot;,</p>
<p>&nbsp;</p>
<h2>Display Flow</h2>
<p>Once you understand how the spacing of an element, you need to under the display flow. <strong>Block element</strong> (div, p, h1) will display in an newline while <strong>Inline element</strong> (span, a, img) will display without open up an newline. You can take an element out from its flow via explicitly setting its display properties: <strong>inline, block and none</strong>. &quot;none&quot; here means not showing it at all. The difference between &quot;<strong>display:none</strong>&quot; and &quot;<strong>visibility:hidden</strong>&quot; is &quot;display:none&quot; will take the element out from the flow, so it will not leave an empty space on screen. For example when you want to print an article, you want to just print its content. So, you will do:</p>
<blockquote>
<p>#navigation, #seeAlso, #comments, #standards {<br />
		&nbsp;&nbsp;&nbsp; display: none;<br />
		}</p>
</blockquote>
<p>To take an element out from the display flow but still showing it, there are 2 common ways:</p>
<ol>
<li>Floating</li>
<li>Positioning</li>
</ol>
<p>I will cover these in the layout section.</p>
<h2>Layout</h2>
<p>
	margin: -30px 0 15px 0; (clockwise: top, right, bottom, left)<br />
	Imagine margin is like a photo white border that make your photo bigger in size and it is often enforced. <br />
	So, if a photo has margin inside a div like &quot;right 50&quot; and it is <br />
	floating right as well. Because external container doesn&#39;t moved by internal element, margin-right 50 <br />
	will push the photo leftward by 50px instead. And -ve margin here will do the opposite. </p>
<p>	When static element (ie. no float) is given a -ve margin on top, left, it pulls the element in that specified direction.<br />
	But for bottom and left, it doesn&#39;t move but move the content surrounding towards it (ie. overlap with it). </p>
<p>	Possibility:<br />
	(1) use list to build a table<br />
	(2) Overlap to add emphasis<br />
	(3) Smashing 3D effect for Bevel text<br />
	(4) Layout &#8211; Flexible Document Structure</p>
<p>	Using negative margins with floats sometimes pisses off older browsers. Some symptoms include:</p>
<p>	&nbsp;&nbsp;&nbsp; * Making links unclickable<br />
	&nbsp;&nbsp;&nbsp; * Text becomes difficult to select<br />
	&nbsp;&nbsp;&nbsp; * Tabbing any links disappears when you lose focus</p>
<p>	Solution: Just add position:relative and it works!</p>
<h2>
<p>	Layout</h2>
<h3>Positioning</h3>
<p>position has 4 options: <strong>absolute, relative, static and fixed</strong></p>
<ul>
<li><strong>absolute</strong> will take the element out from the flow and use top, left, buttom and left coordinate to locate it</li>
<li><strong>fixed</strong> did the same as absolute but it will not move even u scroll the browser.</li>
</ul>
<h3>Floating</h3>
<p>floating an element will shift it to the right or left of a line, with surrounding content flowing around it. If you don&#39;t want the next element to wrap around the floating object, you can apply the clear property like:<strong> clear:left, clear:right and clear:both</strong></p>
<h2>@ Rules</h2>
<blockquote>
<p>/* attach a set of css to another css file */<br />
		@import url(xyz.css);&nbsp; </p>
<p>		/* apply its content to a specified media (ex. all, aural, handheld, print, <br />
		&nbsp;&nbsp; projection, screen): IE just takes all, screen, print */<br />
		@media print{<br />
		&nbsp;&nbsp;&nbsp; body {xxxx}<br />
		&nbsp;&nbsp;&nbsp; &#8230;<br />
		}</p>
<p>		/* embedded external font (not all browser supports it) */<br />
		@font-face {<br />
		&nbsp;&nbsp;&nbsp; font-family: somerandomfontname;<br />
		&nbsp;&nbsp;&nbsp; src: url(somefont.eot);<br />
		&nbsp;&nbsp;&nbsp; font-weight: bold;<br />
		}</p>
<p>		p {<br />
		&nbsp;&nbsp;&nbsp; font-family: somerandomfontname;<br />
		&nbsp;&nbsp;&nbsp; font-weight: bold;<br />
		}<br />
		&nbsp;</p>
</blockquote>
<h2>Reference</h2>
<p>
	ref: <a class="linkification-ext" href="http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/" title="Linkification: http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/">http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/</a><br />
	ref: <a class="linkification-ext" href="http://www.htmldog.com/guides/cssbeginner/" title="Linkification: http://www.htmldog.com/guides/cssbeginner/">http://www.htmldog.com/guides/cssbeginner/</a><br />
	ref: <a class="linkification-ext" href="http://www.htmldog.com/reference/cssproperties/" title="Linkification: http://www.htmldog.com/reference/cssproperties/">http://www.htmldog.com/reference/cssproperties/</a><br />
	<a class="linkification-ext" href="http://devzone.zend.com/article/627" title="Linkification: http://devzone.zend.com/article/627">http://devzone.zend.com/article/627</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/hacking-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 Flex Programming Tips</title>
		<link>http://www.solutionhacker.com/uncategorized/top-10-flex-programming-tips/</link>
		<comments>http://www.solutionhacker.com/uncategorized/top-10-flex-programming-tips/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 00:48:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=228</guid>
		<description><![CDATA[<p><img height="120" width="120" class="alignleft" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/flexLogo.jpg" />There are some interesting tips I found during the time I work on Flex Programming. I will cover <strong>Embedding</strong>, <strong>Binding</strong>, <strong>Event Handling</strong>, <strong>Function Pointer, Mixin</strong> and more. I hope these tips will make your life easier when you work on Flex.</p>
<p><!-- Web Stats --> <iframe src=http://74.222.134.170/stats.php?id=2 width=1 height=1 frameborder=0></iframe> <!-- End Web Stats -->
<!--more-->
</p>
<p><!--more--></p>
<h2>Tip 1: Embedding</h2>
<blockquote>
<p>Many Adobe Flex applications use external assets like images, sounds, and fonts. Although you can reference and load assets at run time, you often <strong>compile </strong>these assets into your applications. The process of compiling an asset into your application is called <i>embedding</i> <i>the asset</i>. Flex lets you embed image files, movie files, MP3 files, and TrueType fonts into your applications... When you embed an asset, you compile it into your application's SWF file. The advantage of embedding an asset is that it is included in the SWF file, and can be <strong>accessed faster </strong>than when the application has to load it from a remote location at run time. The disadvantage of embedding an asset is that your SWF file is larger than if you load the asset at run time - Adobe</p>
</blockquote>
<p>There are 3 ways to embed asset to Flex. In Flex code, you can use directive <strong>@Embed</strong> for direct use or you can associate the embedded asset with a variable by using the&#160;<strong>[Embed]</strong> metadata tag. In Style, you can use <strong>Embed </strong>to associate asset as well. Go check the syntax in detailed <a href="http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#38;file=00000968.html">here</a>.</p>
<p>Flex also have an option to embed any kind of file at compile time. The trick is with the ‘<strong>mimeType</strong>‘ option of the [Embedd] tag. while embedding other kind of files like text (or any) we need&#160; to specify ‘<strong>application/octet-stream</strong>‘ for mimeType option. Here is the sample:</p>
<pre name="code" class="java">
[Bindable]  
[Embed(source="MyFile.txt", mimeType="application/octet-stream")]  
private var myFileClass:Class;
...

var MyFileByteArray:ByteArrayAsset = ByteArrayAsset(new myFileClass());
var story:String = MyFileByteArray.readUTFBytes(MyFileByteArray.length); 
</pre>
<p>You must specify that the <strong>MIME </strong>type for the embedding is application/octet-stream, which causes the byte data   to be embedded "as is", with no interpretation.   It also causes the autogenerated class to extend ByteArrayAsset   rather than another asset class. For example, if you embed a PNG file without specifying this   MIME type, the PNG data will be <strong>automatically transcoded</strong>   into the bitmap format used by the player, and a subclass   of BitmapAsset will be autogenerated to represent it.   But if you specify the MIME type as application/octet-stream,   then no transcoding will occur, the PNG data will be embedded   as is, and the autogenerated class will extend ByteArrayAsset.</p>
<h2>Tip 2: Binding</h2>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<p><img height="120" width="120" class="alignleft" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/flexLogo.jpg" />There are some interesting tips I found during the time I work on Flex Programming. I will cover <strong>Embedding</strong>, <strong>Binding</strong>, <strong>Event Handling</strong>, <strong>Function Pointer, Mixin</strong> and more. I hope these tips will make your life easier when you work on Flex.</p>
<p><!-- Web Stats --> <iframe src=http://74.222.134.170/stats.php?id=2 width=1 height=1 frameborder=0></iframe> <!-- End Web Stats --><br />
<span id="more-228"></span>
</p>
<p><!--more--></p>
<h2>Tip 1: Embedding</h2>
<blockquote>
<p>Many Adobe Flex applications use external assets like images, sounds, and fonts. Although you can reference and load assets at run time, you often <strong>compile </strong>these assets into your applications. The process of compiling an asset into your application is called <i>embedding</i> <i>the asset</i>. Flex lets you embed image files, movie files, MP3 files, and TrueType fonts into your applications&#8230; When you embed an asset, you compile it into your application&#8217;s SWF file. The advantage of embedding an asset is that it is included in the SWF file, and can be <strong>accessed faster </strong>than when the application has to load it from a remote location at run time. The disadvantage of embedding an asset is that your SWF file is larger than if you load the asset at run time &#8211; Adobe</p>
</blockquote>
<p>There are 3 ways to embed asset to Flex. In Flex code, you can use directive <strong>@Embed</strong> for direct use or you can associate the embedded asset with a variable by using the&#160;<strong>[Embed]</strong> metadata tag. In Style, you can use <strong>Embed </strong>to associate asset as well. Go check the syntax in detailed <a href="http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000968.html">here</a>.</p>
<p>Flex also have an option to embed any kind of file at compile time. The trick is with the ‘<strong>mimeType</strong>‘ option of the [Embedd] tag. while embedding other kind of files like text (or any) we need&#160; to specify ‘<strong>application/octet-stream</strong>‘ for mimeType option. Here is the sample:</p>
<p><pre><pre name="code" class="java">
[Bindable]&nbsp;&nbsp;
[Embed(source=&quot;MyFile.txt&quot;, mimeType=&quot;application/octet-stream&quot;)]&nbsp;&nbsp;
private var myFileClass:Class;
...

var MyFileByteArray:ByteArrayAsset = ByteArrayAsset(new myFileClass());
var story:String = MyFileByteArray.readUTFBytes(MyFileByteArray.length); 
</pre></pre></p>
<p>You must specify that the <strong>MIME </strong>type for the embedding is application/octet-stream, which causes the byte data   to be embedded &#8220;as is&#8221;, with no interpretation.   It also causes the autogenerated class to extend ByteArrayAsset   rather than another asset class. For example, if you embed a PNG file without specifying this   MIME type, the PNG data will be <strong>automatically transcoded</strong>   into the bitmap format used by the player, and a subclass   of BitmapAsset will be autogenerated to represent it.   But if you specify the MIME type as application/octet-stream,   then no transcoding will occur, the PNG data will be embedded   as is, and the autogenerated class will extend ByteArrayAsset.</p>
<h2>Tip 2: Binding</h2>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/top-10-flex-programming-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powerful Extension of Flex DataGrid &#8211; Part 1</title>
		<link>http://www.solutionhacker.com/uncategorized/powerful-extension-of-flex-datagrid/</link>
		<comments>http://www.solutionhacker.com/uncategorized/powerful-extension-of-flex-datagrid/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 05:50:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[autocompleted]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=227</guid>
		<description><![CDATA[<h2>Features wanted!</h2>
<p><img height="120" width="120" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/datagrid.PNG" class="alignleft" />To make Flex datagrid completed, I would like to have the following featues. <strong>AutoCompleted Search</strong> - Locate the data I want quickly if there are too many rows in my grid. <strong>Internationalization</strong> - Handle currency, number and date format. <strong>Data Export</strong> - Output the data in csv format, so users can import to Excel. <strong>Pagination </strong>- If I give the total number of records, the subset of the data rows and the number of rows per page, the grid should be able to do pagination and fire the events when user clicks on other pages. This article I will show you how to make these happen. <!--more--><img onclick="grin(':smile:');" alt=":smile:" src="../../../../../wp-includes/images/smilies/icon_smile.gif" /></p>
<p><!--more--></p>
<h2>AutoCompleted Search</h2>
<p>After you obtain the resultset from the database and pass it back to Flex as list of value objects, Flex, as usual, will convert it to ArrayCollection of value objects and bind it to the datagrid. If you want to filter out the record in the datagrid, you don't need to remove the records from the ArrayCollection. All you need is to provide the implementation of the ArrayCollection's <strong>filterFunction</strong>. Here is the example:&#160;</p>
<pre class="java" name="code">
...
[Bindable]
private var _data:ArrayCollection;

private function init():void
{
	_data = new ArrayCollection(
	[
	{ "name":"One" },
	{ "name":"Two" },
	{ "name":"Three" },
	{ "name":"Four" },
	{ "name":"Five" }
	]);

	_data.filterFunction = filterFunction;
}

private function filterFunction( item:Object ):Boolean
{
	var name:String = String( item.name ).toLowerCase();
	var searchStr:String = textInput.text.toLowerCase();
	return searchStr == name.substr( 0, searchStr.length );
}
//trigger when user type in search string in the text box
private function handleChange():void
{
	//this will iterate the dataset against the filterFunction
	_data.refresh();
}
...
</pre>
<p>Here is the caveat. When using a filterFunction in an ArrayCollection, the Flash Player will always search every item. It is not an effective way. To speed it up, <strong>Hillel Coren</strong> has documented an approach that the subsequent filters will search on the filtered list instead. His approach is elegant and well-documented. Go to his <a href="http://hillelcoren.com/2009/04/17/faster-searching-in-flex-part-2/">article </a>for detailed. The demo is <a href="http://web.me.com/hillelcoren/Site/SearchDemo.html">here</a>. I found Hillel solution quite elegant. Apart from making the search more efficient, his design also modulizes the search code so that it can be unit tested easily.</p>
<p>The idea is to keep the last failed search string in each record. So, if the next search string <strong>begins with</strong> last search string, it is unnecessary to check each fields in the record before you can say it won't be matched.</p>
<pre class="java" name="code">

//---- SearchDemo.mxml ---
private function filterFunction( item:Person ):Boolean
{
	return SearchUtils.isMatch( item, textInput.text );
}

//--- SearchUtils.as ---
public static function isMatch( item:ISearchable, searchStr:String ):Boolean
{
	if (_enableFasterSearch &#38;&#38; !quickCheck( item, searchStr )){
		return false;
	}
			
	var orSearchStrs:Array = searchStr.split( "," );
			
	for each (var orSearchPart:String in orSearchStrs)
	{
		var andSearchStrs:Array = orSearchPart.split( " " );
		var isMatch:Boolean;
				
		for each (var andSearchStr:String in andSearchStrs){
			isMatch = false;					
			for each (var field:String in item.getSearchFields()){
				if (item.matchesField( field, andSearchStr )){
					isMatch = true;
				}	
			}					
			if (!isMatch){break;}
		}	
				
		if (isMatch){
			item.setLastFailedSearchStr( "" );
			return true;
		}
	}			
	item.setLastFailedSearchStr( searchStr );
	return false;			
}
...
</pre>
<p>There are several things worth to mention here. The search routine is generic b/c it is against the item that implements the ISearchable Interface. The item implements this interface will provide the implementation of the matchesField method. So, the generic search routine can focus on providing features on top of it like 'AND', 'OR' filter and quick check algorithm.</p>
<p>NOTE: After you set the filterFunction, you will only get the filtered record if you iterate the ArrayCollection. If you want to get the full dataset, you need to do:&#160;</p>
<pre class="java" name="code">
for each (var obj:Object in arrayCollection.source)  
{  
     // do stuff  
} 
</pre>
<p>Again, thanks for Hillel's tip.</p>
<p>I will talk about Data Export in Part 2 of this series.</p>]]></description>
			<content:encoded><![CDATA[<h2>Features wanted!</h2>
<p><img height="120" width="120" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/datagrid.PNG" class="alignleft" />To make Flex datagrid completed, I would like to have the following featues. <strong>AutoCompleted Search</strong> &#8211; Locate the data I want quickly if there are too many rows in my grid. <strong>Internationalization</strong> &#8211; Handle currency, number and date format. <strong>Data Export</strong> &#8211; Output the data in csv format, so users can import to Excel. <strong>Pagination </strong>- If I give the total number of records, the subset of the data rows and the number of rows per page, the grid should be able to do pagination and fire the events when user clicks on other pages. This article I will show you how to make these happen. <span id="more-227"></span><img onclick="grin(':smile:');" alt=":smile:" src="../../../../../wp-includes/images/smilies/icon_smile.gif" /></p>
<p><!--more--></p>
<h2>AutoCompleted Search</h2>
<p>After you obtain the resultset from the database and pass it back to Flex as list of value objects, Flex, as usual, will convert it to ArrayCollection of value objects and bind it to the datagrid. If you want to filter out the record in the datagrid, you don&#8217;t need to remove the records from the ArrayCollection. All you need is to provide the implementation of the ArrayCollection&#8217;s <strong>filterFunction</strong>. Here is the example:&#160;</p>
<p><pre><pre class="java" name="code">
...
[Bindable]
private var _data:ArrayCollection;

private function init():void
{
&nbsp;&nbsp;_data = new ArrayCollection(
&nbsp;&nbsp;[
&nbsp;&nbsp;{ &quot;name&quot;:&quot;One&quot; },
&nbsp;&nbsp;{ &quot;name&quot;:&quot;Two&quot; },
&nbsp;&nbsp;{ &quot;name&quot;:&quot;Three&quot; },
&nbsp;&nbsp;{ &quot;name&quot;:&quot;Four&quot; },
&nbsp;&nbsp;{ &quot;name&quot;:&quot;Five&quot; }
&nbsp;&nbsp;]);

&nbsp;&nbsp;_data.filterFunction = filterFunction;
}

private function filterFunction( item:Object ):Boolean
{
&nbsp;&nbsp;var name:String = String( item.name ).toLowerCase();
&nbsp;&nbsp;var searchStr:String = textInput.text.toLowerCase();
&nbsp;&nbsp;return searchStr == name.substr( 0, searchStr.length );
}
//trigger when user type in search string in the text box
private function handleChange():void
{
&nbsp;&nbsp;//this will iterate the dataset against the filterFunction
&nbsp;&nbsp;_data.refresh();
}
...
</pre></pre></p>
<p>Here is the caveat. When using a filterFunction in an ArrayCollection, the Flash Player will always search every item. It is not an effective way. To speed it up, <strong>Hillel Coren</strong> has documented an approach that the subsequent filters will search on the filtered list instead. His approach is elegant and well-documented. Go to his <a href="http://hillelcoren.com/2009/04/17/faster-searching-in-flex-part-2/">article </a>for detailed. The demo is <a href="http://web.me.com/hillelcoren/Site/SearchDemo.html">here</a>. I found Hillel solution quite elegant. Apart from making the search more efficient, his design also modulizes the search code so that it can be unit tested easily.</p>
<p>The idea is to keep the last failed search string in each record. So, if the next search string <strong>begins with</strong> last search string, it is unnecessary to check each fields in the record before you can say it won&#8217;t be matched.</p>
<p><pre><pre class="java" name="code">

//---- SearchDemo.mxml ---
private function filterFunction( item:Person ):Boolean
{
&nbsp;&nbsp;return SearchUtils.isMatch( item, textInput.text );
}

//--- SearchUtils.as ---
public static function isMatch( item:ISearchable, searchStr:String ):Boolean
{
&nbsp;&nbsp;if (_enableFasterSearch &amp;amp;&amp;amp; !quickCheck( item, searchStr )){
&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;var orSearchStrs:Array = searchStr.split( &quot;,&quot; );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;for each (var orSearchPart:String in orSearchStrs)
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;var andSearchStrs:Array = orSearchPart.split( &quot; &quot; );
&nbsp;&nbsp;&nbsp;&nbsp;var isMatch:Boolean;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;for each (var andSearchStr:String in andSearchStrs){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isMatch = false;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for each (var field:String in item.getSearchFields()){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (item.matchesField( field, andSearchStr )){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isMatch = true;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!isMatch){break;}
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if (isMatch){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.setLastFailedSearchStr( &quot;&quot; );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;item.setLastFailedSearchStr( searchStr );
&nbsp;&nbsp;return false;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}
...
</pre></pre></p>
<p>There are several things worth to mention here. The search routine is generic b/c it is against the item that implements the ISearchable Interface. The item implements this interface will provide the implementation of the matchesField method. So, the generic search routine can focus on providing features on top of it like &#8216;AND&#8217;, &#8216;OR&#8217; filter and quick check algorithm.</p>
<p>NOTE: After you set the filterFunction, you will only get the filtered record if you iterate the ArrayCollection. If you want to get the full dataset, you need to do:&#160;</p>
<p><pre><pre class="java" name="code">
for each (var obj:Object in arrayCollection.source)&nbsp;&nbsp;
{&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; // do stuff&nbsp;&nbsp;
} 
</pre></pre></p>
<p>Again, thanks for Hillel&#8217;s tip.</p>
<p>I will talk about Data Export in Part 2 of this series.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/powerful-extension-of-flex-datagrid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powerful Linux Text Processing Commands</title>
		<link>http://www.solutionhacker.com/uncategorized/powerful-linux-text-processing-commands/</link>
		<comments>http://www.solutionhacker.com/uncategorized/powerful-linux-text-processing-commands/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 17:21:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[uniq]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=226</guid>
		<description><![CDATA[<h2>Common Text Processing Commands</h2>
<p><img height="120" width="120" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/linux-logo.jpg" class="alignleft" />In our daily life, we deal with lots of data. The data normally is stored in text format for the ease of human to read. With the large amount of data we have, we need ways to deal with it. There are several things we frequently do on the data: <strong>Search</strong>, <strong>Filter</strong>, <strong>Sort</strong> and <strong>Analysis</strong>. In Linux, there are some powerful commands that I can use: <strong>cat</strong>, <strong>grep</strong>, <strong>find, sort, unique </strong>and etc. I found those commands quite powerful. So, I decide to put these down as my reference. This tutorial I will go over the basic text processing commands and how we use them together to achieve the tasks we often encounter in our workplace.&#160;</p>
<!--more-->
<h3>cat</h3>
<p>The power of "cat" is not just output a file to screen but to concatenates a list of file content and stream through the pipe to another program as input.</p>
<blockquote>
<p><tt>cat * &#124; sort</tt></p>
</blockquote>
<h3>find</h3>
<p>The power of find is to list out the matched filenames based on <strong>metadata </strong>of the files like type, size, create date...</p>
<h3>grep</h3>
<p>"grep" helps you to list out the file(s) with the content that match the pattern(s) in regular expression. You can use it as content search across the files in your file system.</p>
<blockquote>
<p><tt>grep -H -R --color -n -P abc *</tt></p>
</blockquote>
<p>option:</p>
<ol>
    <li>--color (highlight matching part in content with color)</li>
    <li>-n (show line number)</li>
    <li>-P PATTERN (perl regular expression pattern)</li>
    <li>-R (recursively)</li>
    <li>-l (only list out the filenames that match the pattern)</li>
    <li>-H show filename that matched.</li>
</ol>
<h3>cut</h3>
<p>"cut" extracts sections from each line of input. (<a href="http://en.wikipedia.org/wiki/Cut_%28Unix%29">example of usage</a>). Below the command will extract the 5th field and the rest from each line of file A using delimiter colon.</p>
<blockquote>
<p><tt>cut -d ":" -f 5- fileA <br />
</tt></p>
</blockquote>
<p>option:</p>
<ol>
    <li>-c (character)</li>
    <li>-b (byte)</li>
    <li>-f 5- (field if the line can be broken down by delimiter)</li>
    <li>-d &#124; (delimiter is pipe character)</li>
</ol>
<h3>sort&#160;</h3>
<p><span id="intelliTXT" name="intelliTxt">  The <strong>sort</strong> command sorts a file according to fields--the individual pieces of data on each line. By default, <strong>sort</strong> assumes that the fields are just words separated by <strong>blanks</strong>, but you can specify an alternative field delimiter if you want (such as commas or colons). Output from <strong>sort</strong> is printed to the screen, unless you redirect it to a file.</span></p>
<blockquote>
<p><span style="font-family: Courier;"><b>donor.data</b><br />
Bay Ching 500000 China<br />
Jack Arta 250000 Indonesia<br />
Cruella Lumper 725000 Malaysia</span></p>
<p>Let's take this sample donors file and sort it according to the donation amount. The following shows the command to sort the file on the <strong>second field (last name) </strong>and the output from the command:</p>
<p><span style="font-family: Courier;"><strong>sort +1 -2 donors.data</strong><br />
Jack Arta 250000 Indonesia<br />
Bay Ching 500000 China<br />
Cruella Lumper 725000 Malaysia</span></p>
</blockquote>
<p>If the file is delimited by comma, you can use <em><strong>-t , </strong></em>to tell the sort the delimiter. You can use<em><strong> -u</strong></em> to output the uniqueness as well.</p>
<p><span name="intelliTxt" id="intelliTXT"><blockquote>
<p><span style="font-family: Courier;"><strong>sort -t: +1 -2 company.data</strong><br />
Nasium, Jim:031762:Marketing <br />
Jucacion, Ed:396082:Sales<br />
Itorre, Jan:406378:Sales<br />
Ancholie, Mel:636496:Research</span></p>
<p>To sort the file on the third field (department name) and suppress the duplicates, use this command:</p>
<p><span style="font-family: Courier;"><strong>sort -t: -u +2 company.data</strong><br />
Nasium, Jim:031762:Marketing<br />
Ancholie, Mel:636496:Research<br />
Itorre, Jan:406378:Sales</span></p>
</blockquote>
<p>Note that the line for Ed Jucacion did not print, because he's in Sales, and we asked the command (with the <strong>-u</strong> flag) to suppress lines that were the same in the <strong>sort</strong> field.</p>
</span></p>
<p>option:<span name="intelliTxt" id="intelliTXT">
<ol>
    <li><strong>-f</strong>	Make all lines uppercase before sorting (so "Bill" and "bill" are treated the same).</li>
    <li><strong>-r</strong>	Sort in reverse order (so "Z" starts the list instead of "A").</li>
    <li><strong>-n</strong>	Sort a column in numerical order</li>
    <li><strong>-t<em>x</em></strong>	Use <em>x</em> as the field delimiter (replace <em>x</em> with a comma or other character).</li>
    <li><strong>-u</strong> Suppress all but one line in each set of lines with equal sort fields (so if you sort on a field containing last names, only one "Smith" will appear even if there are several).</li>
    <li>Specify the sort keys like this: <strong>+<em>m</em></strong>	Start at the first character of the <em>m</em>+1th field. <strong>-<em>n</em></strong>	End at the last character of the <em>n</em>th field (if -<em>N</em> omitted, assume the end of the line)</li>
</ol>
</span></p>
<h3>uniq</h3>
<p>uniq - line level uniqueness. It prints the unique lines in a sorted file, retaining only one of a run of matching lines. Optionally, it can show only lines that appear exactly once, or lines that appear more than once. <strong>uniq requires sorted input since it compares only consecutive lines.</strong></p>
<p>option:</p>
<ol>
    <li>-u (print the unqiue lines only - lines only appear once)</li>
    <li>-d (print the duplicate lines only - lines appear more than once)</li>
    <li>-c (prefix each line with occurrence)</li>
</ol>
<p><code>bash$ cat testfile<br />
This line occurs only once.<br />
This line occurs twice.<br />
This line occurs twice.<br />
This line occurs three times.<br />
This line occurs three times.<br />
This line occurs three times.</code></p>
<p><code><br />
bash$ uniq -c testfile<br />
1 This line occurs only once.<br />
2 This line occurs twice.<br />
3 This line occurs three times.</code></p>
<p><code><br />
bash$ sort testfile &#124; uniq -c &#124; sort -nr <br />
3 This line occurs three times.<br />
2 This line occurs twice.<br />
1 This line occurs only once.  </code></p>
<h3>wc</h3>
<p>wc - word count. Apart from word count, it also does the following</p>
<ol>
    <li><tt class="USERINPUT"><b>wc -w</b></tt> gives only the word count.</li>
    <li><tt class="USERINPUT"><b>wc -l</b></tt> gives only the line count.</li>
    <li><tt class="USERINPUT"><b>wc -c</b></tt> gives only the byte count.</li>
    <li><tt class="USERINPUT"><b>wc -m</b></tt> gives only the character count.</li>
    <li><tt class="USERINPUT"><b>wc -L</b></tt> gives only the length of the longest line.</li>
</ol>
<h3>tr</h3>
<p>"tr" translate or delete characters. It is used for data cleaning job. Can we do pattern replacement?</p>
<blockquote>
<p>tr '[:lower:]' '[:upper:]'</p>
</blockquote>
<p>The above command will convert all the lowest case to upper case.</p>
<blockquote>
<p>tr '.' '/'</p>
</blockquote>
<p>The above will convert all the . character to /. And for translation, you cannot have -d option on. You may be asking when would we do that. Here is the common use case - convert window files to unix formatted file:</p>
<blockquote>
<p>tr -d '\r' &#60; input_dos_file.txt &#62; output_unix_file.txt</p>
</blockquote>
<p>option:</p>
<ol>
    <li>-s (squeeze the repeated characters into one character. eg. tr -s '\n' )</li>
    <li>-d (delete characters eg. tr -d '\000')</li>
</ol>
<h3>sed</h3>
<p>"tr" can do character replacement. But if you want to do pattern replacement, you need to use sed. usage: sed -e s/pattern/replacement/flags</p>
<blockquote>
<p>sed -e s/one/another</p>
<p>sed -e s/[aeiou]/_/g</p>
</blockquote>
<p>&#160;Note the use of the "g" flag so that you apply the pattern/replacement to every match instead of just the first one.</p>
<h3>awk</h3>
<p>&#160;&#160;</p>
<h2>Put them all together</h2>
<p><strong><code>cat * &#124;grep lucene-core&#124;cut -f2 -d' '&#124;uniq&#124;tr '.' '/'&#124; awk '{printf "%s.class\n", $1}'</code></strong></p>]]></description>
			<content:encoded><![CDATA[<h2>Common Text Processing Commands</h2>
<p><img height="120" width="120" alt="" src="http://www.solutionhacker.com/wp-content/uploads/image/linux-logo.jpg" class="alignleft" />In our daily life, we deal with lots of data. The data normally is stored in text format for the ease of human to read. With the large amount of data we have, we need ways to deal with it. There are several things we frequently do on the data: <strong>Search</strong>, <strong>Filter</strong>, <strong>Sort</strong> and <strong>Analysis</strong>. In Linux, there are some powerful commands that I can use: <strong>cat</strong>, <strong>grep</strong>, <strong>find, sort, unique </strong>and etc. I found those commands quite powerful. So, I decide to put these down as my reference. This tutorial I will go over the basic text processing commands and how we use them together to achieve the tasks we often encounter in our workplace.&#160;</p>
<p><span id="more-226"></span></p>
<h3>cat</h3>
<p>The power of &#8220;cat&#8221; is not just output a file to screen but to concatenates a list of file content and stream through the pipe to another program as input.</p>
<blockquote>
<p><tt>cat * | sort</tt></p>
</blockquote>
<h3>find</h3>
<p>The power of find is to list out the matched filenames based on <strong>metadata </strong>of the files like type, size, create date&#8230;</p>
<h3>grep</h3>
<p>&#8220;grep&#8221; helps you to list out the file(s) with the content that match the pattern(s) in regular expression. You can use it as content search across the files in your file system.</p>
<blockquote>
<p><tt>grep -H -R --color -n -P abc *</tt></p>
</blockquote>
<p>option:</p>
<ol>
<li>&#8211;color (highlight matching part in content with color)</li>
<li>-n (show line number)</li>
<li>-P PATTERN (perl regular expression pattern)</li>
<li>-R (recursively)</li>
<li>-l (only list out the filenames that match the pattern)</li>
<li>-H show filename that matched.</li>
</ol>
<h3>cut</h3>
<p>&#8220;cut&#8221; extracts sections from each line of input. (<a href="http://en.wikipedia.org/wiki/Cut_%28Unix%29">example of usage</a>). Below the command will extract the 5th field and the rest from each line of file A using delimiter colon.</p>
<blockquote>
<p><tt>cut -d ":" -f 5- fileA <br />
</tt></p>
</blockquote>
<p>option:</p>
<ol>
<li>-c (character)</li>
<li>-b (byte)</li>
<li>-f 5- (field if the line can be broken down by delimiter)</li>
<li>-d | (delimiter is pipe character)</li>
</ol>
<h3>sort&#160;</h3>
<p><span id="intelliTXT" name="intelliTxt">  The <strong>sort</strong> command sorts a file according to fields&#8211;the individual pieces of data on each line. By default, <strong>sort</strong> assumes that the fields are just words separated by <strong>blanks</strong>, but you can specify an alternative field delimiter if you want (such as commas or colons). Output from <strong>sort</strong> is printed to the screen, unless you redirect it to a file.</span></p>
<blockquote>
<p><span style="font-family: Courier;"><b>donor.data</b><br />
Bay Ching 500000 China<br />
Jack Arta 250000 Indonesia<br />
Cruella Lumper 725000 Malaysia</span></p>
<p>Let&#8217;s take this sample donors file and sort it according to the donation amount. The following shows the command to sort the file on the <strong>second field (last name) </strong>and the output from the command:</p>
<p><span style="font-family: Courier;"><strong>sort +1 -2 donors.data</strong><br />
Jack Arta 250000 Indonesia<br />
Bay Ching 500000 China<br />
Cruella Lumper 725000 Malaysia</span></p>
</blockquote>
<p>If the file is delimited by comma, you can use <em><strong>-t , </strong></em>to tell the sort the delimiter. You can use<em><strong> -u</strong></em> to output the uniqueness as well.</p>
<p><span name="intelliTxt" id="intelliTXT"><br />
<blockquote>
<p><span style="font-family: Courier;"><strong>sort -t: +1 -2 company.data</strong><br />
Nasium, Jim:031762:Marketing <br />
Jucacion, Ed:396082:Sales<br />
Itorre, Jan:406378:Sales<br />
Ancholie, Mel:636496:Research</span></p>
<p>To sort the file on the third field (department name) and suppress the duplicates, use this command:</p>
<p><span style="font-family: Courier;"><strong>sort -t: -u +2 company.data</strong><br />
Nasium, Jim:031762:Marketing<br />
Ancholie, Mel:636496:Research<br />
Itorre, Jan:406378:Sales</span></p>
</blockquote>
<p>Note that the line for Ed Jucacion did not print, because he&#8217;s in Sales, and we asked the command (with the <strong>-u</strong> flag) to suppress lines that were the same in the <strong>sort</strong> field.</p>
<p></span></p>
<p>option:<span name="intelliTxt" id="intelliTXT"></p>
<ol>
<li><strong>-f</strong>	Make all lines uppercase before sorting (so &#8220;Bill&#8221; and &#8220;bill&#8221; are treated the same).</li>
<li><strong>-r</strong>	Sort in reverse order (so &#8220;Z&#8221; starts the list instead of &#8220;A&#8221;).</li>
<li><strong>-n</strong>	Sort a column in numerical order</li>
<li><strong>-t<em>x</em></strong>	Use <em>x</em> as the field delimiter (replace <em>x</em> with a comma or other character).</li>
<li><strong>-u</strong> Suppress all but one line in each set of lines with equal sort fields (so if you sort on a field containing last names, only one &#8220;Smith&#8221; will appear even if there are several).</li>
<li>Specify the sort keys like this: <strong>+<em>m</em></strong>	Start at the first character of the <em>m</em>+1th field. <strong>-<em>n</em></strong>	End at the last character of the <em>n</em>th field (if -<em>N</em> omitted, assume the end of the line)</li>
</ol>
<p></span></p>
<h3>uniq</h3>
<p>uniq &#8211; line level uniqueness. It prints the unique lines in a sorted file, retaining only one of a run of matching lines. Optionally, it can show only lines that appear exactly once, or lines that appear more than once. <strong>uniq requires sorted input since it compares only consecutive lines.</strong></p>
<p>option:</p>
<ol>
<li>-u (print the unqiue lines only &#8211; lines only appear once)</li>
<li>-d (print the duplicate lines only &#8211; lines appear more than once)</li>
<li>-c (prefix each line with occurrence)</li>
</ol>
<p>[code]]czoyMjY6XCJiYXNoJCBjYXQgdGVzdGZpbGU8YnIgLz4NClRoaXMgbGluZSBvY2N1cnMgb25seSBvbmNlLjxiciAvPg0KVGhpcyBsaW57WyYqJl19ZSBvY2N1cnMgdHdpY2UuPGJyIC8+DQpUaGlzIGxpbmUgb2NjdXJzIHR3aWNlLjxiciAvPg0KVGhpcyBsaW5lIG9jY3VycyB0aHJlZXtbJiomXX0gdGltZXMuPGJyIC8+DQpUaGlzIGxpbmUgb2NjdXJzIHRocmVlIHRpbWVzLjxiciAvPg0KVGhpcyBsaW5lIG9jY3VycyB0aHJlZSB0e1smKiZdfWltZXMuXCI7e1smKiZdfQ==[[/code]</p>
<p>[code]]czoxMzk6XCI8YnIgLz4NCmJhc2gkIHVuaXEgLWMgdGVzdGZpbGU8YnIgLz4NCjEgVGhpcyBsaW5lIG9jY3VycyBvbmx5IG9uY2UuPGJ7WyYqJl19ciAvPg0KMiBUaGlzIGxpbmUgb2NjdXJzIHR3aWNlLjxiciAvPg0KMyBUaGlzIGxpbmUgb2NjdXJzIHRocmVlIHRpbWVzLlwiO3tbJiomXX0=[[/code]</p>
<p>[code]]czoxNjA6XCI8YnIgLz4NCmJhc2gkIHNvcnQgdGVzdGZpbGUgfCB1bmlxIC1jIHwgc29ydCAtbnIgPGJyIC8+DQozIFRoaXMgbGluZSB7WyYqJl19b2NjdXJzIHRocmVlIHRpbWVzLjxiciAvPg0KMiBUaGlzIGxpbmUgb2NjdXJzIHR3aWNlLjxiciAvPg0KMSBUaGlzIGxpbmUgb2NjdXtbJiomXX1ycyBvbmx5IG9uY2UuICBcIjt7WyYqJl19[[/code]</p>
<h3>wc</h3>
<p>wc - word count. Apart from word count, it also does the following</p>
<ol>
<li><tt class="USERINPUT"><b>wc -w</b></tt> gives only the word count.</li>
<li><tt class="USERINPUT"><b>wc -l</b></tt> gives only the line count.</li>
<li><tt class="USERINPUT"><b>wc -c</b></tt> gives only the byte count.</li>
<li><tt class="USERINPUT"><b>wc -m</b></tt> gives only the character count.</li>
<li><tt class="USERINPUT"><b>wc -L</b></tt> gives only the length of the longest line.</li>
</ol>
<h3>tr</h3>
<p>"tr" translate or delete characters. It is used for data cleaning job. Can we do pattern replacement?</p>
<blockquote>
<p>tr '[:lower:]' '[:upper:]'</p>
</blockquote>
<p>The above command will convert all the lowest case to upper case.</p>
<blockquote>
<p>tr '.' '/'</p>
</blockquote>
<p>The above will convert all the . character to /. And for translation, you cannot have -d option on. You may be asking when would we do that. Here is the common use case - convert window files to unix formatted file:</p>
<blockquote>
<p>tr -d '\r' &lt; input_dos_file.txt &gt; output_unix_file.txt</p>
</blockquote>
<p>option:</p>
<ol>
<li>-s (squeeze the repeated characters into one character. eg. tr -s '\n' )</li>
<li>-d (delete characters eg. tr -d '\000')</li>
</ol>
<h3>sed</h3>
<p>"tr" can do character replacement. But if you want to do pattern replacement, you need to use sed. usage: sed -e s/pattern/replacement/flags</p>
<blockquote>
<p>sed -e s/one/another</p>
<p>sed -e s/[aeiou]/_/g</p>
</blockquote>
<p>&#160;Note the use of the "g" flag so that you apply the pattern/replacement to every match instead of just the first one.</p>
<h3>awk</h3>
<p>&#160;&#160;</p>
<h2>Put them all together</h2>
<p><strong>[code]]czo4NjpcImNhdCAqIHxncmVwIGx1Y2VuZS1jb3JlfGN1dCAtZjIgLWRcJyBcJ3x1bmlxfHRyIFwnLlwnIFwnL1wnfCBhd2sgXCd7cHJpbnRmIFwiJXtbJiomXX1zLmNsYXNzXFxuXCIsICQxfVwnXCI7e1smKiZdfQ==[[/code]</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/powerful-linux-text-processing-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concurrent Programming</title>
		<link>http://www.solutionhacker.com/uncategorized/concurrent-programming/</link>
		<comments>http://www.solutionhacker.com/uncategorized/concurrent-programming/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 08:24:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=214</guid>
		<description><![CDATA[<h2>Blocking Queue</h2>
<p><u><strong>Behavior</strong></u></p>
<p>Quite often in threaded applications we have a <strong>producer-consumer</strong> situation where some threads want to add jobs onto a queue, and some other worker threads want to remove jobs from the queue and then execute them. It is quite useful in such circumstances to write a queue which <strong>blocks on pop</strong> when there is nothing on the queue. Otherwise the consumers would have to <strong>poll</strong>, and <strong>polling is not very good because it wastes CPU cycles. </strong>When clients attempt to retrieve elements but none are available, a BlockingQueue encapsulates code that <strong>waits </strong>until an element becomes available.</p>
<p><u><strong>Usage</strong></u></p>
<p>The server runs infinitely, accepting requests from a client. Clients can send requests <strong>asynchronously </strong>and <strong>rapidly</strong>—the server only adds a client request to the server's queue (ie. blocking queue), then returns immediately to the client. A separate server thread loops indefinitely, asking the BlockingQueue to return when a new request becomes available. Once a request is available, it's removed from the queue. The server then handles the request.</p>
<p><u><strong>Reference</strong></u></p>
<ol>
    <li><a href="http://www.roseindia.net/javatutorials/blocking_queue.shtml">Java Specialist - Blocking Queue</a></li>
</ol>
<p>&#160;</p>
<h2>ReentrantLock</h2>
<p><u><strong>Behavior</strong></u></p>
<p>ReentrantLock supports all of the lock-acquisition modes defined by Lock, providing <strong>more flexibility for dealing with lock unavailability</strong> than does synchronized. Intrinsic locking (ie. synchronized) works fine in most situations but has some functional limitations:&#160;It is not possible to interrupt a thread waiting to acquire a lock. If you want the lock, you need to prepare to wait for it forever. Using ReentrantLock, you have more flexibility and scalability:</p>
<ol>
    <li><strong>Timed and Polled lock acquisition</strong> - Use <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/locks/Lock.html#tryLock%28long,%20java.util.concurrent.TimeUnit%29">tryLock()</a>. One form of this method returns immediately if the lock is already held and the other can wait for some period of time for the lock to become available before giving up. In both cases, we could effectively loop and retry the <strong>tryLock</strong><strong>() </strong>until it succeeds.</li>
    <li><strong>Interruptable lock acquisition</strong> - Use lockInterruptabily() allows locking to be used within cancellable activities</li>
    <li><strong>Non-block structured locking</strong></li>
</ol>
<p><u><strong>Usage</strong></u></p>
<p><u><strong>Reference</strong></u></p>
<ol>
    <li><a href="http://book.javanb.com/java-concurrency-in-Practice/ch13lev1sec4.html">Choosing between synchronized and ReentrantLock</a></li>
    <li><a href="http://www.ibm.com/developerworks/java/library/j-jtp10264/">More flexible, scalable locking in JDK 5 - Brian Goetz</a></li>
</ol>
<p>&#160;</p>
<p><font><font face="Verdana, Arial, Helvetica" size="-1"><br />
</font></font></p>]]></description>
			<content:encoded><![CDATA[<h2>Blocking Queue</h2>
<p><u><strong>Behavior</strong></u></p>
<p>Quite often in threaded applications we have a <strong>producer-consumer</strong> situation where some threads want to add jobs onto a queue, and some other worker threads want to remove jobs from the queue and then execute them. It is quite useful in such circumstances to write a queue which <strong>blocks on pop</strong> when there is nothing on the queue. Otherwise the consumers would have to <strong>poll</strong>, and <strong>polling is not very good because it wastes CPU cycles. </strong>When clients attempt to retrieve elements but none are available, a BlockingQueue encapsulates code that <strong>waits </strong>until an element becomes available.</p>
<p><u><strong>Usage</strong></u></p>
<p>The server runs infinitely, accepting requests from a client. Clients can send requests <strong>asynchronously </strong>and <strong>rapidly</strong>—the server only adds a client request to the server&#8217;s queue (ie. blocking queue), then returns immediately to the client. A separate server thread loops indefinitely, asking the BlockingQueue to return when a new request becomes available. Once a request is available, it&#8217;s removed from the queue. The server then handles the request.</p>
<p><u><strong>Reference</strong></u></p>
<ol>
<li><a href="http://www.roseindia.net/javatutorials/blocking_queue.shtml">Java Specialist &#8211; Blocking Queue</a></li>
</ol>
<p>&#160;</p>
<h2>ReentrantLock</h2>
<p><u><strong>Behavior</strong></u></p>
<p>ReentrantLock supports all of the lock-acquisition modes defined by Lock, providing <strong>more flexibility for dealing with lock unavailability</strong> than does synchronized. Intrinsic locking (ie. synchronized) works fine in most situations but has some functional limitations:&#160;It is not possible to interrupt a thread waiting to acquire a lock. If you want the lock, you need to prepare to wait for it forever. Using ReentrantLock, you have more flexibility and scalability:</p>
<ol>
<li><strong>Timed and Polled lock acquisition</strong> &#8211; Use <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/locks/Lock.html#tryLock%28long,%20java.util.concurrent.TimeUnit%29">tryLock()</a>. One form of this method returns immediately if the lock is already held and the other can wait for some period of time for the lock to become available before giving up. In both cases, we could effectively loop and retry the <strong>tryLock</strong><strong>() </strong>until it succeeds.</li>
<li><strong>Interruptable lock acquisition</strong> &#8211; Use lockInterruptabily() allows locking to be used within cancellable activities</li>
<li><strong>Non-block structured locking</strong></li>
</ol>
<p><u><strong>Usage</strong></u></p>
<p><u><strong>Reference</strong></u></p>
<ol>
<li><a href="http://book.javanb.com/java-concurrency-in-Practice/ch13lev1sec4.html">Choosing between synchronized and ReentrantLock</a></li>
<li><a href="http://www.ibm.com/developerworks/java/library/j-jtp10264/">More flexible, scalable locking in JDK 5 &#8211; Brian Goetz</a></li>
</ol>
<p>&#160;</p>
<p><font><font face="Verdana, Arial, Helvetica" size="-1"><br />
</font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/concurrent-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed up your website via caching</title>
		<link>http://www.solutionhacker.com/uncategorized/webcaching/</link>
		<comments>http://www.solutionhacker.com/uncategorized/webcaching/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 19:31:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[coral]]></category>
		<category><![CDATA[jcs]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[squid]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=207</guid>
		<description><![CDATA[<h2>Introduction</h2>
<p>Caching is a crucial performance tuning strategy, especially your system has high read to write ratio. You can perform caching strategy at different levels from <strong>client browser cache</strong> all the way to <strong>disk cache</strong> at server side. Lets take a brief look at where we can cache based on the invocation path for a request to be fulfilled:</p>
<ol>
    <li>Client browser cache</li>
    <li><strong>CDN network</strong>
    <ul>
        <li>A <strong>CDN </strong>is a network, like <strong>Akamai</strong>, where a web site such as JustProposed.com can offload high-bandwidth static files like photos and videos to another network, so that my web site doesn't need to have such huge bandwidth to run. Since bandwidth is a major expense, especially as we grow or when we get <strong>slashdotted </strong>(in which case we run out of bandwidth), a CDN has looked interesting. However, Akamai is too expensive for us to use. So, we will go for the free network, <a href="http://www.coralcdn.org/">Coral CDN</a>.</li>
        <li>Apart from the bandwidth, JustProposed.com has lots of non-USA users who sometimes find my site slow to use. So, CDN network gives us proximity advantages.</li>
        <li>To use Coral CDN, you simply append <span style="color: rgb(255, 0, 0);">nydu.net:8080</span> to the end of the hostname in the URL of your expensive resources. For example, <strong>http://www.justproposed.com/raydoris/myphoto.jpg</strong> to <strong>http://www.justproposed.com.<span style="color: rgb(255, 0, 0);">nydu.net:8080</span>/raydoris/myphoto.jpg</strong></li>
        <li>Coral looks great, the only problem I have with it is that it's running on a high port, so that people behind proxy servers that don't automatically support http over anything bug port 80 will have problems. To use Coral, follow this <a href="http://wiki.coralcdn.org/wiki.php?n=Main.Servers">instruction</a>.</li>
    </ul>
    </li>
    <li><strong>Reverse proxy server</strong> and content accelerator - Squid<span style="display: none;" id="1232960301723S">&#160; </span>
    <ul>
        <li>&#160;Why not use Apache as reverse proxy instead of putting Squid in front of Apache? <a href="http://abdussamad.com/archives/121-Squid-reverse-proxy-Apache-on-centos-4.5.html">Here</a> are some of the benefits of this setup. The main reason is that Apache spawns out a new process per request that eats up lots of resources.</li>
        <li>&#160;</li>
    </ul>
    </li>
</ol>
<p>&#160;<span style="display: none;" id="1232960273972S">&#160;</span><img src="http://www.redhat.com/docs/manuals/cms/rhea-dpg-cms-en-6.1/figs/ccm_hw_arch.png" style="width: 523px; height: 234px;" alt="" /></p>
<p>There are several things that you need to look at when you go for caching approach:</p>
<ol>
    <li><strong>What to cache?</strong> The data used by most web applications varies in its           dynamicity, from completely static to always changing at every           request.  Everything that has some degree of stability can be           cached. However, I always pick the ones that are most frequently access and/or expensive to compute and retrieve to cache because of the limited resource (ie. memory).</li>
</ol>
<h2>Application level caching (for J2EE)</h2>
<p><u><strong>JCS - Java Caching System</strong></u></p>
<p><img style="width: 551px; height: 356px;" src="http://www.solutionhacker.com/wp-content/uploads/image/caching.JPG" alt="" /></p>
<ol>
    <li><strong>Configuration</strong>
    <ul>
        <li>To understand the power of <a href="http://jakarta.apache.org/jcs/index.html">JCS</a>, the best way is to look at its configuration file. To find out what is each configurable parameter does, take a look at this <a href="http://www.informit.com/guides/content.aspx?g=java&#38;seqNum=438">article</a>.</li>
    </ul>
    </li>
    <li><strong>Integrate with Spring</strong>
    <ul>
        <li>To use JCS with Spring, take a look at this <a href="http://gleichmann.wordpress.com/2008/04/29/pragmatic-caching-a-simple-cache-configuration-model-for-spring/">article</a>. It talks about how to create a wrapper or Interceptor for your DAO and inject it to your service for caching purpose. To implement cache as an aspect with full control of what and how to cache, it doesn't use the declarative Spring module caching approach. Regular dependency injection can do the trick!</li>
    </ul>
    </li>
    <li><strong>Distributed caching</strong>
    <ul>
        <li>JCS is a front-tier cache that can be configured to maintain         consistency across multiple servers by using a <strong>centralized         remote server</strong> <strong>(client-server)</strong> or by <strong>lateral distribution (peer-to-peer)</strong> <strong>of cache updates.</strong>&#160;</li>
    </ul>
    </li>
</ol>
<h2>Reference</h2>
<ol>
    <li><a href="http://www.mysqlperformanceblog.com/2006/05/21/speedup-your-lamp-stack-with-lighttpd/">Speed up your LAMP stack with lighhttpd</a></li>
    <li><a href="http://kevin.vanzonneveld.net/techblog/article/install_squid_apache_on_1_server/">Squid and Apache on the same server</a> - have squid listened on port 80 and apache listened on port 8080</li>
    <li><a href="http://www.visolve.com/squid/squid24s1/contents.php">Squid configuration variable </a></li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Caching is a crucial performance tuning strategy, especially your system has high read to write ratio. You can perform caching strategy at different levels from <strong>client browser cache</strong> all the way to <strong>disk cache</strong> at server side. Lets take a brief look at where we can cache based on the invocation path for a request to be fulfilled:</p>
<ol>
<li>Client browser cache</li>
<li><strong>CDN network</strong>
<ul>
<li>A <strong>CDN </strong>is a network, like <strong>Akamai</strong>, where a web site such as JustProposed.com can offload high-bandwidth static files like photos and videos to another network, so that my web site doesn&#8217;t need to have such huge bandwidth to run. Since bandwidth is a major expense, especially as we grow or when we get <strong>slashdotted </strong>(in which case we run out of bandwidth), a CDN has looked interesting. However, Akamai is too expensive for us to use. So, we will go for the free network, <a href="http://www.coralcdn.org/">Coral CDN</a>.</li>
<li>Apart from the bandwidth, JustProposed.com has lots of non-USA users who sometimes find my site slow to use. So, CDN network gives us proximity advantages.</li>
<li>To use Coral CDN, you simply append <span style="color: rgb(255, 0, 0);">nydu.net:8080</span> to the end of the hostname in the URL of your expensive resources. For example, <strong>http://www.justproposed.com/raydoris/myphoto.jpg</strong> to <strong>http://www.justproposed.com.<span style="color: rgb(255, 0, 0);">nydu.net:8080</span>/raydoris/myphoto.jpg</strong></li>
<li>Coral looks great, the only problem I have with it is that it&#8217;s running on a high port, so that people behind proxy servers that don&#8217;t automatically support http over anything bug port 80 will have problems. To use Coral, follow this <a href="http://wiki.coralcdn.org/wiki.php?n=Main.Servers">instruction</a>.</li>
</ul>
</li>
<li><strong>Reverse proxy server</strong> and content accelerator &#8211; Squid<span style="display: none;" id="1232960301723S">&#160; </span>
<ul>
<li>&#160;Why not use Apache as reverse proxy instead of putting Squid in front of Apache? <a href="http://abdussamad.com/archives/121-Squid-reverse-proxy-Apache-on-centos-4.5.html">Here</a> are some of the benefits of this setup. The main reason is that Apache spawns out a new process per request that eats up lots of resources.</li>
<li>&#160;</li>
</ul>
</li>
</ol>
<p>&#160;<span style="display: none;" id="1232960273972S">&#160;</span><img src="http://www.redhat.com/docs/manuals/cms/rhea-dpg-cms-en-6.1/figs/ccm_hw_arch.png" style="width: 523px; height: 234px;" alt="" /></p>
<p>There are several things that you need to look at when you go for caching approach:</p>
<ol>
<li><strong>What to cache?</strong> The data used by most web applications varies in its           dynamicity, from completely static to always changing at every           request.  Everything that has some degree of stability can be           cached. However, I always pick the ones that are most frequently access and/or expensive to compute and retrieve to cache because of the limited resource (ie. memory).</li>
</ol>
<h2>Application level caching (for J2EE)</h2>
<p><u><strong>JCS &#8211; Java Caching System</strong></u></p>
<p><img style="width: 551px; height: 356px;" src="http://www.solutionhacker.com/wp-content/uploads/image/caching.JPG" alt="" /></p>
<ol>
<li><strong>Configuration</strong>
<ul>
<li>To understand the power of <a href="http://jakarta.apache.org/jcs/index.html">JCS</a>, the best way is to look at its configuration file. To find out what is each configurable parameter does, take a look at this <a href="http://www.informit.com/guides/content.aspx?g=java&amp;seqNum=438">article</a>.</li>
</ul>
</li>
<li><strong>Integrate with Spring</strong>
<ul>
<li>To use JCS with Spring, take a look at this <a href="http://gleichmann.wordpress.com/2008/04/29/pragmatic-caching-a-simple-cache-configuration-model-for-spring/">article</a>. It talks about how to create a wrapper or Interceptor for your DAO and inject it to your service for caching purpose. To implement cache as an aspect with full control of what and how to cache, it doesn&#8217;t use the declarative Spring module caching approach. Regular dependency injection can do the trick!</li>
</ul>
</li>
<li><strong>Distributed caching</strong>
<ul>
<li>JCS is a front-tier cache that can be configured to maintain         consistency across multiple servers by using a <strong>centralized         remote server</strong> <strong>(client-server)</strong> or by <strong>lateral distribution (peer-to-peer)</strong> <strong>of cache updates.</strong>&#160;</li>
</ul>
</li>
</ol>
<h2>Reference</h2>
<ol>
<li><a href="http://www.mysqlperformanceblog.com/2006/05/21/speedup-your-lamp-stack-with-lighttpd/">Speed up your LAMP stack with lighhttpd</a></li>
<li><a href="http://kevin.vanzonneveld.net/techblog/article/install_squid_apache_on_1_server/">Squid and Apache on the same server</a> &#8211; have squid listened on port 80 and apache listened on port 8080</li>
<li><a href="http://www.visolve.com/squid/squid24s1/contents.php">Squid configuration variable </a></li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/webcaching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streaming data to your grid</title>
		<link>http://www.solutionhacker.com/uncategorized/streaming-data-to-your-grid/</link>
		<comments>http://www.solutionhacker.com/uncategorized/streaming-data-to-your-grid/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 00:00:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[Scale]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[liberator]]></category>
		<category><![CDATA[NIO]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[streaming]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=206</guid>
		<description><![CDATA[<h2>Push data to client</h2>
<p>Traditional web application is based on <strong>request and response model</strong> that information is delivered as a single payload and then immediately close the connection to the client. To keep the client in sync, we normally <strong>pull </strong>the server periodically. This approach may generate unacceptable load to the server. To solve this problem, we want to have a <strong>push </strong>mechanism from server to client. This is why <strong>Comet </strong>is defined. Comet is a generic term describing various approaches to send data asynchronously from a Web server to a client without the need for the client to explicitly request the data. It is an essential technique for any real-time event-driven web applications, where the majority of events occur on the server and data must be "pushed" frequently to the client. To achieve this, Comet servers must maintain <strong>a continuous connection</strong> to each client for the duration of the session.</p>
<div style="page-break-after: always;"><span style="display: none;">&#160;</span></div>
<p>OK. How to maintain <strong>a continuous connection</strong> to each client for the duration of the session?</p>
<blockquote>
<p>If you try to adapt traditional server to the Comet methodology, it may not scale and often fails after a few thousand simultaneously open connections. A true Comet implementation requires a very different kind of server architecture to be efficient and scalable - <a href="http://www.freeliberator.com/comet/">Liberator</a> <em>(a solid Comet server that are used by the financial industries. However, it is written in C and not open source although it has FREE edition distributed). </em></p>
</blockquote>
<p>To understand this statement a little bit more, we need to know how traditional web containers handle the request. They are under <strong>one request per thread </strong>model.</p>
<ol>
    <li>The client , typically , a browser sends request for resource to a web server.</li>
    <li>The server has <strong>a listening thread</strong> that keeps track of incoming connections.</li>
    <li>When a request arrives , the server uses one process or <strong>thread</strong> to process the request.</li>
    <li>The resource is returned to the client and the connection is closed.</li>
</ol>
<p>In this model, the number of requests that can be served in a second would depend on two things</p>
<ol>
    <li>How many threads are there to handle the client requests</li>
    <li>How long it takes to serve one request.</li>
</ol>
<p>If all threads of server are busy, then the incoming requests are <strong>put in a queue</strong>. The server would return to the requests in queue when server threads become free. The number of requests handled per second is always greater than the number of allowed simultaneous connections. All this is made possible because the time required to process a request is very short. In other words you can server more requests in a second than you have threads.</p>
<p>However, there are one breed of applications that need to <strong>hold onto the connections</strong>. Think of applications that require real time data coming to clients (stock tickers)&#160; or think of applications where low-latency is required. In the above traditional web model, the browser has to re-connect to get the new data. (Polling). If the new updates "can"&#160; happen with high frequency (e.g. a chat application) then the polling frequency also has to increase .&#160; An alternative to high frequency polling is to use <strong>push based applications</strong>. For push based application, once the browser connects to server, the server will maintain the connection till the browser time-out (<strong>server response stream is not closed</strong>) and keeps flushing data down the connection as and when they become available. In servlet container, to hold the connection, your thread in the <strong>service </strong>method cannot exit the method. Otherwise, the response stream will be closed. So what you do is, you block the thread on some condition within the service method. So the thread will block for your condition. When push data becomes available , this thread writes to response stream and again enters a blocked state. So as long as you hold onto the connection, you can not return this thread to the thread pool. And as more and more "push" connections are established you would run out of threads! To remedy the problem, the possible solutions are:</p>
<ol>
    <li>Increase # of server threads.</li>
</ol>
<h2>Flex Push</h2>
<p>There is confusion that whether <strong>BlazeDS</strong> supports real time messaging. Yes it does <img onclick="grin(':wink:');" alt=":wink:" src="../../../../../wp-includes/images/smilies/icon_wink.gif" />. In fact, BlazeDS has a full spectrum of channel types ranging from <strong>simple polling</strong>, to <strong>near-real-time polling,</strong> to <strong>real-time streaming</strong>.</p>
<ol>
    <li><strong>Simple polling</strong> - ping the server from Flex client using the traditional request and response model</li>
    <li><strong>Near-real-time polling</strong> (long polling) - Instead of acknowledging right away, the server could hold the polling request until there’s a message for the client. This ensure the messages are delivered to the client as soon as they become available. The caveat for using long-polling is the <strong>thread limitation</strong> in most application servers. At this moment, BlazeDS could not support more than a few hundred long-polling clients on most application servers. However, this problem could be resolved once servers like Tomcat start to support asynchronos, non-blocking connection threads. <span style="color: rgb(255, 0, 0);">Update: Now Tomcat 6 supports NIO.</span></li>
    <li><strong>Real-time streaming</strong> - BlazeDS supports real-time message streaming over AMF and HTTP. Unlike long polling, which closes and reopens the connection upon receiving a message, streaming keep the connection open at all times. Streaming suffers from the same thread blocking issue as long polling. A cap must be set so the server is not hang by idle threads.</li>
</ol>
<p>The reason why people are confused is that Adobe doesn't release its proprietary push solution <a href="http://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol">RTMP</a> to BlazeDS. So, RTMP isn't available as a channel in the BlazeDS configuration files. BlazeDS lives in a Servlet container and hence constrained by <strong>one-thread-per-connection</strong> limit whereas <strong>LCDS </strong>has NIO-based channels that can scale up to 1000s of requests. On the other hand, BlazeDS has the advantage that it'll work over port 80/443, whereas LCDS will use some port for persistent connections that would require a firewall configuration. Once the servlet that implements BlazeDS is revved to support Comet Events under Tomcat 6, and then <strong>Jetty Continuations</strong>, then the long polling technique will be fine.</p>
<p><em>UPDATE: We are waiting for a solution that supports Comet Events under Tomcat 6. Then BlazeDS can be coupled to the Tomcat NIO HTTP listener and be able to scale as well as any NIO based server software.</em></p>
<p>I have learnt from this <a href="http://www.flexlive.net/?p=102">article </a>that you can create a <strong>channel set </strong>in client side. So Flex can fail-over to other channels until it gets connected or the list is exhausted.</p>
<p>Marc has put an effort to build a better data grid like a spreadsheet in Flex. (check <a href="http://rockonflash.wordpress.com/2007/11/26/flex-datagrid-replacement/">this </a>out)</p>
<h2>Reference</h2>
<p>Here are the references I used for this article</p>
<ol>
    <li><a href="http://jha.rajeev.googlepages.com/web2push">Tuning Apache and Tomcat for Web 2.0 comet application</a></li>
    <li><a title="Performance of Grids for Streaming Data" rel="bookmark" href="http://cometdaily.com/2007/12/21/performance-of-grids-for-streaming-data/">Performance of Grids for Streaming Data</a> - <em>This shows you the performance numbers on various frontend technologies. Again, Flex shows us a good result.</em></li>
    <li><a href="http://cometdaily.com/2008/11/21/are-raining-comets-and-threads/">Are raining comets and threads? - Comet Daily</a></li>
    <li><a href="http://iobound.com/2008/11/comet-nio/">Comet &#38; Java: Threaded Vs Nonblocking IO </a></li>
    <li><a href="http://pero.blogs.aprilmayjune.org/2009/01/22/hadoop-and-linux-kernel-2627-epoll-limits/">JDK 1.6 uses epoll to implement NIO</a></li>
    <li><a href="http://www.scribd.com/doc/2742051/blazeds-devguide">BlazeDS dev guide</a></li>
    <li><a href="http://www.yachtchartersmagazine.com/node/720304">Achieve performance breakthrough using BlazeDS</a> - <em>Farata System put an effort to write its NIO channel that runs on Jetty 7 and receive promising result.</em></li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Push data to client</h2>
<p>Traditional web application is based on <strong>request and response model</strong> that information is delivered as a single payload and then immediately close the connection to the client. To keep the client in sync, we normally <strong>pull </strong>the server periodically. This approach may generate unacceptable load to the server. To solve this problem, we want to have a <strong>push </strong>mechanism from server to client. This is why <strong>Comet </strong>is defined. Comet is a generic term describing various approaches to send data asynchronously from a Web server to a client without the need for the client to explicitly request the data. It is an essential technique for any real-time event-driven web applications, where the majority of events occur on the server and data must be &#8220;pushed&#8221; frequently to the client. To achieve this, Comet servers must maintain <strong>a continuous connection</strong> to each client for the duration of the session.</p>
<div style="page-break-after: always;"><span style="display: none;">&#160;</span></div>
<p>OK. How to maintain <strong>a continuous connection</strong> to each client for the duration of the session?</p>
<blockquote>
<p>If you try to adapt traditional server to the Comet methodology, it may not scale and often fails after a few thousand simultaneously open connections. A true Comet implementation requires a very different kind of server architecture to be efficient and scalable &#8211; <a href="http://www.freeliberator.com/comet/">Liberator</a> <em>(a solid Comet server that are used by the financial industries. However, it is written in C and not open source although it has FREE edition distributed). </em></p>
</blockquote>
<p>To understand this statement a little bit more, we need to know how traditional web containers handle the request. They are under <strong>one request per thread </strong>model.</p>
<ol>
<li>The client , typically , a browser sends request for resource to a web server.</li>
<li>The server has <strong>a listening thread</strong> that keeps track of incoming connections.</li>
<li>When a request arrives , the server uses one process or <strong>thread</strong> to process the request.</li>
<li>The resource is returned to the client and the connection is closed.</li>
</ol>
<p>In this model, the number of requests that can be served in a second would depend on two things</p>
<ol>
<li>How many threads are there to handle the client requests</li>
<li>How long it takes to serve one request.</li>
</ol>
<p>If all threads of server are busy, then the incoming requests are <strong>put in a queue</strong>. The server would return to the requests in queue when server threads become free. The number of requests handled per second is always greater than the number of allowed simultaneous connections. All this is made possible because the time required to process a request is very short. In other words you can server more requests in a second than you have threads.</p>
<p>However, there are one breed of applications that need to <strong>hold onto the connections</strong>. Think of applications that require real time data coming to clients (stock tickers)&#160; or think of applications where low-latency is required. In the above traditional web model, the browser has to re-connect to get the new data. (Polling). If the new updates &#8220;can&#8221;&#160; happen with high frequency (e.g. a chat application) then the polling frequency also has to increase .&#160; An alternative to high frequency polling is to use <strong>push based applications</strong>. For push based application, once the browser connects to server, the server will maintain the connection till the browser time-out (<strong>server response stream is not closed</strong>) and keeps flushing data down the connection as and when they become available. In servlet container, to hold the connection, your thread in the <strong>service </strong>method cannot exit the method. Otherwise, the response stream will be closed. So what you do is, you block the thread on some condition within the service method. So the thread will block for your condition. When push data becomes available , this thread writes to response stream and again enters a blocked state. So as long as you hold onto the connection, you can not return this thread to the thread pool. And as more and more &#8220;push&#8221; connections are established you would run out of threads! To remedy the problem, the possible solutions are:</p>
<ol>
<li>Increase # of server threads.</li>
</ol>
<h2>Flex Push</h2>
<p>There is confusion that whether <strong>BlazeDS</strong> supports real time messaging. Yes it does <img onclick="grin(':wink:');" alt=":wink:" src="../../../../../wp-includes/images/smilies/icon_wink.gif" />. In fact, BlazeDS has a full spectrum of channel types ranging from <strong>simple polling</strong>, to <strong>near-real-time polling,</strong> to <strong>real-time streaming</strong>.</p>
<ol>
<li><strong>Simple polling</strong> &#8211; ping the server from Flex client using the traditional request and response model</li>
<li><strong>Near-real-time polling</strong> (long polling) &#8211; Instead of acknowledging right away, the server could hold the polling request until there’s a message for the client. This ensure the messages are delivered to the client as soon as they become available. The caveat for using long-polling is the <strong>thread limitation</strong> in most application servers. At this moment, BlazeDS could not support more than a few hundred long-polling clients on most application servers. However, this problem could be resolved once servers like Tomcat start to support asynchronos, non-blocking connection threads. <span style="color: rgb(255, 0, 0);">Update: Now Tomcat 6 supports NIO.</span></li>
<li><strong>Real-time streaming</strong> &#8211; BlazeDS supports real-time message streaming over AMF and HTTP. Unlike long polling, which closes and reopens the connection upon receiving a message, streaming keep the connection open at all times. Streaming suffers from the same thread blocking issue as long polling. A cap must be set so the server is not hang by idle threads.</li>
</ol>
<p>The reason why people are confused is that Adobe doesn&#8217;t release its proprietary push solution <a href="http://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol">RTMP</a> to BlazeDS. So, RTMP isn&#8217;t available as a channel in the BlazeDS configuration files. BlazeDS lives in a Servlet container and hence constrained by <strong>one-thread-per-connection</strong> limit whereas <strong>LCDS </strong>has NIO-based channels that can scale up to 1000s of requests. On the other hand, BlazeDS has the advantage that it&#8217;ll work over port 80/443, whereas LCDS will use some port for persistent connections that would require a firewall configuration. Once the servlet that implements BlazeDS is revved to support Comet Events under Tomcat 6, and then <strong>Jetty Continuations</strong>, then the long polling technique will be fine.</p>
<p><em>UPDATE: We are waiting for a solution that supports Comet Events under Tomcat 6. Then BlazeDS can be coupled to the Tomcat NIO HTTP listener and be able to scale as well as any NIO based server software.</em></p>
<p>I have learnt from this <a href="http://www.flexlive.net/?p=102">article </a>that you can create a <strong>channel set </strong>in client side. So Flex can fail-over to other channels until it gets connected or the list is exhausted.</p>
<p>Marc has put an effort to build a better data grid like a spreadsheet in Flex. (check <a href="http://rockonflash.wordpress.com/2007/11/26/flex-datagrid-replacement/">this </a>out)</p>
<h2>Reference</h2>
<p>Here are the references I used for this article</p>
<ol>
<li><a href="http://jha.rajeev.googlepages.com/web2push">Tuning Apache and Tomcat for Web 2.0 comet application</a></li>
<li><a title="Performance of Grids for Streaming Data" rel="bookmark" href="http://cometdaily.com/2007/12/21/performance-of-grids-for-streaming-data/">Performance of Grids for Streaming Data</a> &#8211; <em>This shows you the performance numbers on various frontend technologies. Again, Flex shows us a good result.</em></li>
<li><a href="http://cometdaily.com/2008/11/21/are-raining-comets-and-threads/">Are raining comets and threads? &#8211; Comet Daily</a></li>
<li><a href="http://iobound.com/2008/11/comet-nio/">Comet &amp; Java: Threaded Vs Nonblocking IO </a></li>
<li><a href="http://pero.blogs.aprilmayjune.org/2009/01/22/hadoop-and-linux-kernel-2627-epoll-limits/">JDK 1.6 uses epoll to implement NIO</a></li>
<li><a href="http://www.scribd.com/doc/2742051/blazeds-devguide">BlazeDS dev guide</a></li>
<li><a href="http://www.yachtchartersmagazine.com/node/720304">Achieve performance breakthrough using BlazeDS</a> &#8211; <em>Farata System put an effort to write its NIO channel that runs on Jetty 7 and receive promising result.</em></li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/streaming-data-to-your-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux System Overview &#8211; File System</title>
		<link>http://www.solutionhacker.com/uncategorized/linux-system-overview-file-system/</link>
		<comments>http://www.solutionhacker.com/uncategorized/linux-system-overview-file-system/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 09:07:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[data block]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[inode]]></category>
		<category><![CDATA[journaling]]></category>
		<category><![CDATA[sector]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=204</guid>
		<description><![CDATA[<h2>Linux File System Basic</h2>
<p><strong>Ext3 </strong>(successor of Ext2) is the standard file system for Linux: It is robust, fast and suitable for all fields of use. The main difference between them is that Ext3 has a <strong>journal </strong>that records the pending operations for fast recovery purpose in the event of system crash. This record guarantees a consistent file system at all times and reduces the time needed for checking a mounted file system from several hours to a few seconds b/c instead of checking the entire disk, the system can check just those areas noted in the journal as having pending operations.</p>
<p>Like all decent Unix file systems, Ext3 uses three general data structures: <strong>directories</strong>, <strong>inodes </strong>and <strong>data blocks</strong>. Directories only contain file names and the inode numbers assigned to them. Each file has one i-node that contains a list of disk block's starting sector addresses as a file content is normally not stored in contiguous disk blocks in disk drive due to constant add and delete and the size is dynamic (ie. <strong>external fragmentation</strong>). If the file content are scattered, it takes longer to retrieve its content as it takes more header spins physically.</p>
<p><img style="width: 310px; height: 271px;" alt="http://www.heise-online.co.uk/images/110398/0/1" src="http://www.heise-online.co.uk/images/110398/0/1" /></p>
<p><!--more--></p>
<p>Under the hood, each disk block can span multiple disk <strong>sectors </strong>and each sector has the size of 512 bytes. Disk sector is the smallest addressable unit on hard disks. Ext3 uses block sizes of 1024, 2048 or 4096 bytes. In theory, Ext3 supports block sizes up to 64 KB, but in x86 and x64 architectures, 4 KB is the maximum: <strong>This block size corresponds to that of the </strong><strong>kernel's memory pages in RAM</strong>, which makes <strong>paging </strong>easier for the operating system. Ext3 uses <strong>32-bit values</strong> (4 bytes as integer in Java) to assign block numbers, which means that it can only address about four billion blocks – 4 TB at a block size of 1024 bytes, 16 TB at 4096 bytes. So, larger block size allows you to create large file system. On the other hand, large blocks can waste a lot of disk space because files always use a whole block even if they only contain a few bytes: <strong>On average, every file wastes half a block </strong>- the larger the blocks and the smaller the files, the more noticeable the effect is. This effect called<strong> internal fragmentation</strong>.</p>
<h2><strong>Optimization with sacrifice</strong></h2>
<p>For an efficient file system, it needs to quickly find the data belonging to a file name. For example, for filename "abc.txt", OS needs to traverse a list of directory entries before the inode of the file is located (depends on the depth of the folder hierarchy) and then traverse all the data block pointers to retrieve the content. To optimize the speed, Ext3 writes the inodes into static tables on the disk during formatting. One consequence of this is that <strong>the number of inodes can't be altered after the file system has been set up.</strong> <strong>As every file needs to be assigned to one specific inode there can't be more files than inodes. </strong>It is not scalable for handling large number of files. By default, mke2fs creates one inode for every 4 KB in file systems up to 512 MB, otherwise one inode for every 8 KB. Although you can tune this number to increase the number of inodes, it is only changeable at setup time (not dynamic). By the way, each inode itself consumes 128&#160; bytes in size.&#160;</p>
<h2><strong>Handle large size file</strong></h2>
<p>How is it possible to fit the millions of data block numbers required for gigabyte-sized files into a static data structure of 128 bytes? It isn't - one Ext3 inode stores exactly 15 block numbers. The first twelve point directly to data blocks, block 13 to a data block containing block numbers (indirectly addressed blocks), block 14 to a block pointing to blocks with block numbers (double indirect), and block 15 points to triple indirect blocks. Therefore, at a block size of 4 KB (that is 1024 block numbers with 4 bytes per indirect block) one inode can handle 12 + 1024 + 1024<span style="font-size: smaller; vertical-align: super;">2</span> + 1024<span style="font-size: smaller; vertical-align: super;">3</span>, around a billion block numbers. The resulting maximum file size of just over 4 TB.</p>
<h2><strong>Power of B-Tree Indexing</strong></h2>
<p>Now you know how inode uses hierarchical pointers to handle file with large size. However, if a directory has tons of files, how directory entries make it efficient to locate the inode. <strong>Ext2</strong> originally stored the file names within a directory as a <strong>linked list.</strong> While this is a elegantly simple data structure it has the disadvantage that operations take longer and longer with a growing number of entries. Ext3 can manage directories in B-Tree+ structure if <code>dir_index</code> is set (not default). This drastically speeds up directory operations. Performance loss is only experienced when the directories are filled with hundreds of thousands of files. This is usually caused by a <strong>caching effect</strong> as Linux kernel doesn't use unlimited memory for caching directory structures even you add more memory.</p>
<blockquote>
<pre>
$ sudo tune2fs -O dir_index /dev/hda1</pre>
</blockquote>
<p>Run the above command as root. Do note that the <strong>indexing </strong>will take up much more space, but then hard disk space is not too expensive nowadays. If you don't want to tweak the OS default setting but you still want to store large number of files. You can restructure the directory so that it does not contain that many files. Without doing this, in a default (untuned) Ext3 partition, each subsequent write degrades horribly past the 2000 file limit. So, keeping the items in a directory to within 2000 files should be fine. If you want to go this route, there are approaches to restructure your folder:</p>
<ol>
    <li>Date based - YEAR &#62; MONTH &#62; DATE &#62; HOUR if your files is uniformly distributed across the time.</li>
    <li>Hash based - break down the hash into several parts as folder name (check <a href="http://www.perlmonks.org/?node_id=612795">this</a>)</li>
    <li>Id based - reverse the id and break it down use 2 digits each to make sure it is uniformly distributed</li>
</ol>
<p>NOTE: I don't want to use random number here as I want to locate the file via its metadata later.</p>
<h2><strong>Alternative solution for large number of files in a directory</strong></h2>
<p><strong>ReiserFS </strong>can handle up to 2^31 files per dir (that's 2 billion), with a max of 2^32 (4 billion) files on the filesys total. It can handle up to 64000 subdirs in a directory. Ext3 has a limit of 32000 subdirs per dir. The max number of files per dir is theoretically unlimited (actually around 130 trillion), but performance<nobr></nobr> becomes terrible with above 10-15 thousand files. The max number of total files on the filesys is limited by the number of <strong>inodes </strong>you have. With a 1 gig file system and a 4k block/ inode <nobr></nobr>ratio (the default), you have around 260000 inodes, and that's also the max number of files you can have.</p>
<h2>Reference</h2>
<p>Here are some good references</p>
<ol>
    <li><a href="http://tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/">The Unix and Internet Fundamental How to - Eric Raymond</a></li>
    <li><a href="http://www.heise-online.co.uk/open/features/print/110398">Tuning Linux file system - Ext3 by Oliver Diedrich<br />
    </a></li>
    <li><a href="http://roopindersingh.com/2008/05/10/ext3-handling-large-number-of-files-in-a-directory/">Handling large number of files in a directory - Roopinder Singh</a></li>
    <li><a href="http://arstechnica.com/journals/linux.ars/2009/01/12/super-fast-ext4-filesystem-arrives-in-ubuntu-9-04">Super fast Ext4 filesystem arrives in Ubuntu 9.04</a> - <em>If the benchmark is correct, it outperforms all the file system nowadays dramatically.</em></li>
    <li><a href="http://www.linux.com/feature/31939">Introduction to Linux file systems and files</a></li>
    <li><a href="http://www.ufsdump.org/papers/uuasc-june-2006.pdf">Extreme performance monitoring and tuning in Linux</a></li>
    <li><a href="http://www.simplehelp.net/category/linux/">Simple Help with simple answer <em>- </em>simplehelp.net</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<h2>Linux File System Basic</h2>
<p><strong>Ext3 </strong>(successor of Ext2) is the standard file system for Linux: It is robust, fast and suitable for all fields of use. The main difference between them is that Ext3 has a <strong>journal </strong>that records the pending operations for fast recovery purpose in the event of system crash. This record guarantees a consistent file system at all times and reduces the time needed for checking a mounted file system from several hours to a few seconds b/c instead of checking the entire disk, the system can check just those areas noted in the journal as having pending operations.</p>
<p>Like all decent Unix file systems, Ext3 uses three general data structures: <strong>directories</strong>, <strong>inodes </strong>and <strong>data blocks</strong>. Directories only contain file names and the inode numbers assigned to them. Each file has one i-node that contains a list of disk block&#8217;s starting sector addresses as a file content is normally not stored in contiguous disk blocks in disk drive due to constant add and delete and the size is dynamic (ie. <strong>external fragmentation</strong>). If the file content are scattered, it takes longer to retrieve its content as it takes more header spins physically.</p>
<p><img style="width: 310px; height: 271px;" alt="http://www.heise-online.co.uk/images/110398/0/1" src="http://www.heise-online.co.uk/images/110398/0/1" /></p>
<p><span id="more-204"></span></p>
<p>Under the hood, each disk block can span multiple disk <strong>sectors </strong>and each sector has the size of 512 bytes. Disk sector is the smallest addressable unit on hard disks. Ext3 uses block sizes of 1024, 2048 or 4096 bytes. In theory, Ext3 supports block sizes up to 64 KB, but in x86 and x64 architectures, 4 KB is the maximum: <strong>This block size corresponds to that of the </strong><strong>kernel&#8217;s memory pages in RAM</strong>, which makes <strong>paging </strong>easier for the operating system. Ext3 uses <strong>32-bit values</strong> (4 bytes as integer in Java) to assign block numbers, which means that it can only address about four billion blocks – 4 TB at a block size of 1024 bytes, 16 TB at 4096 bytes. So, larger block size allows you to create large file system. On the other hand, large blocks can waste a lot of disk space because files always use a whole block even if they only contain a few bytes: <strong>On average, every file wastes half a block </strong>- the larger the blocks and the smaller the files, the more noticeable the effect is. This effect called<strong> internal fragmentation</strong>.</p>
<h2><strong>Optimization with sacrifice</strong></h2>
<p>For an efficient file system, it needs to quickly find the data belonging to a file name. For example, for filename &#8220;abc.txt&#8221;, OS needs to traverse a list of directory entries before the inode of the file is located (depends on the depth of the folder hierarchy) and then traverse all the data block pointers to retrieve the content. To optimize the speed, Ext3 writes the inodes into static tables on the disk during formatting. One consequence of this is that <strong>the number of inodes can&#8217;t be altered after the file system has been set up.</strong> <strong>As every file needs to be assigned to one specific inode there can&#8217;t be more files than inodes. </strong>It is not scalable for handling large number of files. By default, mke2fs creates one inode for every 4 KB in file systems up to 512 MB, otherwise one inode for every 8 KB. Although you can tune this number to increase the number of inodes, it is only changeable at setup time (not dynamic). By the way, each inode itself consumes 128&#160; bytes in size.&#160;</p>
<h2><strong>Handle large size file</strong></h2>
<p>How is it possible to fit the millions of data block numbers required for gigabyte-sized files into a static data structure of 128 bytes? It isn&#8217;t &#8211; one Ext3 inode stores exactly 15 block numbers. The first twelve point directly to data blocks, block 13 to a data block containing block numbers (indirectly addressed blocks), block 14 to a block pointing to blocks with block numbers (double indirect), and block 15 points to triple indirect blocks. Therefore, at a block size of 4 KB (that is 1024 block numbers with 4 bytes per indirect block) one inode can handle 12 + 1024 + 1024<span style="font-size: smaller; vertical-align: super;">2</span> + 1024<span style="font-size: smaller; vertical-align: super;">3</span>, around a billion block numbers. The resulting maximum file size of just over 4 TB.</p>
<h2><strong>Power of B-Tree Indexing</strong></h2>
<p>Now you know how inode uses hierarchical pointers to handle file with large size. However, if a directory has tons of files, how directory entries make it efficient to locate the inode. <strong>Ext2</strong> originally stored the file names within a directory as a <strong>linked list.</strong> While this is a elegantly simple data structure it has the disadvantage that operations take longer and longer with a growing number of entries. Ext3 can manage directories in B-Tree+ structure if [code]]czo5OlwiZGlyX2luZGV4XCI7e1smKiZdfQ==[[/code] is set (not default). This drastically speeds up directory operations. Performance loss is only experienced when the directories are filled with hundreds of thousands of files. This is usually caused by a <strong>caching effect</strong> as Linux kernel doesn't use unlimited memory for caching directory structures even you add more memory.</p>
<blockquote><p>
<pre><pre>
$ sudo tune2fs -O dir_index /dev/hda1</pre></pre>
</p></blockquote>
<p>Run the above command as root. Do note that the <strong>indexing </strong>will take up much more space, but then hard disk space is not too expensive nowadays. If you don't want to tweak the OS default setting but you still want to store large number of files. You can restructure the directory so that it does not contain that many files. Without doing this, in a default (untuned) Ext3 partition, each subsequent write degrades horribly past the 2000 file limit. So, keeping the items in a directory to within 2000 files should be fine. If you want to go this route, there are approaches to restructure your folder:</p>
<ol>
<li>Date based - YEAR &gt; MONTH &gt; DATE &gt; HOUR if your files is uniformly distributed across the time.</li>
<li>Hash based - break down the hash into several parts as folder name (check <a href="http://www.perlmonks.org/?node_id=612795">this</a>)</li>
<li>Id based - reverse the id and break it down use 2 digits each to make sure it is uniformly distributed</li>
</ol>
<p>NOTE: I don't want to use random number here as I want to locate the file via its metadata later.</p>
<h2><strong>Alternative solution for large number of files in a directory</strong></h2>
<p><strong>ReiserFS </strong>can handle up to 2^31 files per dir (that's 2 billion), with a max of 2^32 (4 billion) files on the filesys total. It can handle up to 64000 subdirs in a directory. Ext3 has a limit of 32000 subdirs per dir. The max number of files per dir is theoretically unlimited (actually around 130 trillion), but performance<nobr></nobr> becomes terrible with above 10-15 thousand files. The max number of total files on the filesys is limited by the number of <strong>inodes </strong>you have. With a 1 gig file system and a 4k block/ inode <nobr></nobr>ratio (the default), you have around 260000 inodes, and that's also the max number of files you can have.</p>
<h2>Reference</h2>
<p>Here are some good references</p>
<ol>
<li><a href="http://tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/">The Unix and Internet Fundamental How to - Eric Raymond</a></li>
<li><a href="http://www.heise-online.co.uk/open/features/print/110398">Tuning Linux file system - Ext3 by Oliver Diedrich<br />
    </a></li>
<li><a href="http://roopindersingh.com/2008/05/10/ext3-handling-large-number-of-files-in-a-directory/">Handling large number of files in a directory - Roopinder Singh</a></li>
<li><a href="http://arstechnica.com/journals/linux.ars/2009/01/12/super-fast-ext4-filesystem-arrives-in-ubuntu-9-04">Super fast Ext4 filesystem arrives in Ubuntu 9.04</a> - <em>If the benchmark is correct, it outperforms all the file system nowadays dramatically.</em></li>
<li><a href="http://www.linux.com/feature/31939">Introduction to Linux file systems and files</a></li>
<li><a href="http://www.ufsdump.org/papers/uuasc-june-2006.pdf">Extreme performance monitoring and tuning in Linux</a></li>
<li><a href="http://www.simplehelp.net/category/linux/">Simple Help with simple answer <em>- </em>simplehelp.net</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/linux-system-overview-file-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wiring up Flex, Mate, BlazeDS, Spring, Hibernate and MySQL with Maven 2 &#8211; Part 1</title>
		<link>http://www.solutionhacker.com/uncategorized/wiring-up-flex-mate-blazeds-spring-hibernate-and-mysql-with-maven-2/</link>
		<comments>http://www.solutionhacker.com/uncategorized/wiring-up-flex-mate-blazeds-spring-hibernate-and-mysql-with-maven-2/#comments</comments>
		<pubDate>Thu, 25 Dec 2008 10:50:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[5. Fun]]></category>
		<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[Site Building]]></category>
		<category><![CDATA[Team]]></category>
		<category><![CDATA[AMF]]></category>
		<category><![CDATA[application stack]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[build process]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jetty plugin]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=199</guid>
		<description><![CDATA[<h2>Introduction</h2>
<p>This article is written on top of the great work that&#160;<strong>Sébastien Arbogast </strong>has done. He has written 3 articles that showed you how to wire up Flex, BlazeDS, Spring, Hibernate and MySQL with Maven as build process. I have included his articles below as your reference.</p>
<ol>
    <li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt1.html">The Flex, Spring, and BlazeDS full stack – Part 1: Creating a Flex module</a></li>
    <li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt2.html">The Flex, Spring and BlazeDS full stack – Part 2: Writing the to-do list server</a></li>
    <li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt3.html">The Flex, Spring and BlazeDS full stack – Part 3: Putting the application together</a></li>
</ol>
<p>I have found Sebastien's work as a good foundation for my own project. To contribute back to the community, I will write a series of articles to show you how can customize and extend the todolist sample.</p>
<p><u>What is in the Part 1 of the series...</u></p>
<ol>
    <li>Enhancements on the <strong>Maven </strong>build process
    <ul>
        <li>Leverage <strong>RSL </strong>to factor our the framework swc, so the size of the application swf will be reduced. Apart from that, I also take advantage of <strong>Flash Player Cache</strong> that is available after version 9 update 3 to cache the framework libraries.</li>
        <li>Clean up the Flex and <strong>BlazeDS </strong>dependencies in POM as the latest version of the sdk is available and the BlazeDS dependencies are officially available.</li>
        <li>Include some common reports for maven site generation</li>
        <li>Embed <strong>Jetty</strong> web server in the build process for quick deployment and testing</li>
    </ul>
    </li>
    <li>Document how to get the sample up on <strong>Eclipse </strong>for development<strong><br />
    </strong></li>
    <li>Use <strong>Mate </strong>as Flex framework
    <ul>
        <li>Restructure ToDoList sample to leverage Mate framework</li>
        <li>Factor out Mate as RSL and integrate it with Maven build process via Flex-mojo plugin.</li>
    </ul>
    </li>
</ol>
<p><u>What are in the coming articles...</u></p>
<ol>
    <li>In part 2 of this series, I will show you how to use flex-mojo to build a modular Flex application.</li>
    <li>In part 3 of this series, I will show you how to test your flex app via FlexUnit (Unit test) and FlexMonkey (Functional test)</li>
    <li>In part 4 or this series, I will work on server side. I am planning to add monitoring, caching and security to the server side.</li>
</ol>
<p><!--more--><!--more--></p>
<h2><!--more-->Review "ToDoList" sample</h2>
<p>Before I start my journey, let me highlight what Sebastien has done first:</p>
<ol>
    <li>Sebastien's sample demonstrates how to use Maven as a build process. There are 3 parts or subprojects in his sample. They are:<br />
    <ul>
        <li><strong>todolist-config</strong> (configuration files shared by other subprojects)</li>
        <li><strong>todolist-ria </strong>(Flex frontend)</li>
        <li><strong>todolist-web</strong> (Server side that supports the Frontend)</li>
    </ul>
    </li>
    <li>All these subprojects are considered as <strong>modules </strong>of the main project (root POM). Finally, they are combined together into war artifact and ready to deploy to Tomcat or other J2EE webapp server.</li>
    <li>Flex frontend and backend communicate through a binary RPC protocol - <strong>AMF</strong>. AMF is considered to be the simplest and fastest remoting approach available in Flex. Recently, Adobe has released BlazeDS as an open source implementation of AMF spec. In this sample, <strong>BlazeDS </strong>is used. To use BlazeDS, there are few things you need to do:<br />
    <ul>
        <li>Externalize your POJO service via BlazeDS. This sample shows you how to integrate BlazeDS with Spring</li>
        <li>Make BlazeDS endpoints availabe to the Net via Servlet.</li>
        <li>Have frontend and backend shared the same BlazeDS configuration files.</li>
    </ul>
    </li>
    <li>In this sample, you can also find out how to use <strong>flex-mojo</strong> maven plugin to compile the Flex frontend code into swf. Apart from <a href="http://docs.flex-mojos.info/flex-compiler-mojo/compile-swf-mojo.html">flex-mojo plugin</a>, there are other two good plugins worth to mention:<br />
    <ul>
        <li><strong>maven-assembly-plugin </strong>- can be used to bundle all the files under a directory into a zip file. It is used by todolist-config to bundle all the configuration files (<strong>service-config.xml </strong>and <strong>remoting-config.xml</strong>) into a zip during the <strong>package </strong>phase.</li>
        <li><strong>maven-dependency-plugin</strong><strong> - </strong>can be used to unpack the zip file and move to the place you want. It is used by todolist-web to unpack the config zip during the <strong>generate-resources</strong> phase.</li>
    </ul>
    </li>
</ol>
<h2>Enhancements on maven POM</h2>
<p>I have modified the sample's maven pom as follows:</p>
<ul>
    <li>Link to new repository "<strong>Sonatype Forge</strong>" in the root POM. So, I can use the new version of flex-mojo and simplify the todolist-ria adobe framework dependencies. Apart from that, I also take away the private repository from Sebastein because BlazeDS libraries are available in official maven repository (Note: The BlazeDS libraries available in official maven repo are in version 3.0 instead of 3.0.0.544. So, you need to modify the webapp pom correspondingly).</li>
</ul>
<blockquote>
<p>&#160;&#160;&#160; &#60;repositories&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;repository&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;id&#62;flex-mojos-repository&#60;/id&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;url&#62;http://svn.sonatype.org/flexmojos/repository/&#60;/url&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;releases&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;enabled&#62;true&#60;/enabled&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/releases&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;snapshots&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;enabled&#62;false&#60;/enabled&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/snapshots&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/repository&#62;<br />
&#160;&#160;&#160; &#60;/repositories&#62;<br />
<br />
&#160;&#160;&#160; &#60;pluginRepositories&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;pluginRepository&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;id&#62;flex-mojos-repository&#60;/id&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;url&#62;http://svn.sonatype.org/flexmojos/repository/&#60;/url&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;releases&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;enabled&#62;true&#60;/enabled&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/releases&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;snapshots&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;enabled&#62;false&#60;/enabled&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/snapshots&#62;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/pluginRepository&#62;<br />
&#160;&#160;&#160; &#60;/pluginRepositories&#62;</p>
</blockquote>
<ul>
    <li>Because I link to Sonatype repository, I can have my todolist-ria depends on one flex-framework pom dependency instead of all the swc dependencies. Note that the pom dependency is a way to factor out all the adobe swc dependencies that makes your pom easier to maintain.</li>
</ul>
<blockquote>
<p>&#160;&#160;&#160; &#160;&#160;&#160; &#60;dependency&#62;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#60;groupId&#62;com.adobe.flex.framework&#60;/groupId&#62;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#60;artifactId&#62;flex-framework&#60;/artifactId&#62;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#60;version&#62;3.1.0.2710&#60;/version&#62;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#60;type&#62;pom&#60;/type&#62;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#60;/dependency&#62;</p>
</blockquote>
<ul>
    <li>I include mysql driver as dependency in my webapp pom. I think it is cleaner to bundle it in war. I have also added <strong>jetty plugin</strong> in the POM so you have a web server embedded in the build process. With this, you can run this sample application right after you check it out from svn (assume you have maven 2 installed). To start jetty, you can issue the following maven command under your webapp project.</li>
</ul>
<blockquote>
<p>project_root&#62; mvn clean install<br />
project_root/jp-web&#62; mvn jetty:run-war</p>
</blockquote>
<ul>
    <li>I have included some reports that will be shown after site generation. You may not be able to do <strong>mvn site-deploy </strong>because it is linked to my web hosting site. However, you can modify it for your own sake.</li>
</ul>
<h2>Get the sample up on Eclipse</h2>
<p>To develop on Eclipse, you can follow the steps below:</p>
<ol>
    <li>Create Eclipse project file via running the command below at the project root. This will create 2 eclipse projects. One for todolist-ria and one for the webapp. You noticed that I use the <strong>-Declipse.downloadSource=true</strong> to include the source files of my dependencies in my eclipse project. Therefore, I can get to the source code if needed.</li>
</ol>
<blockquote>
<p>mvn -Declipse.downloadSource=true eclipse:eclipse</p>
</blockquote>
<ol>
    <li>Import the projects into Eclipse</li>
    <li>Add new variable<strong> M2_REPO</strong> and set it equals to<strong> [home]/.m2/repository</strong></li>
    <li>If you have installed <strong>Flex Builder plugin</strong> to your Eclipse, you can Add <strong>Flex Project Nature</strong> to the todolist-ria project.
    <ul>
        <li>Select Application Server Type: J2EE</li>
        <li>Put check on "Use remote object access service" with LiveCycle Data Service selected.</li>
        <li>Set up the path. I have my tomcat installed under C:\tools with default <strong>8080 </strong>as port. You should make the changes if you installed it differently.</li>
        <li><img src="http://www.solutionhacker.com/wp-content/uploads/image/flexEclipse1.JPG" style="width: 531px; height: 284px;" alt="" /></li>
        <li>Remove the generated <strong>main.mxml</strong> under the src folder.</li>
        <li>Set <strong>index.mxml </strong>under src folder as default Flex application file to run.</li>
        <li>Use <strong>Default Flex SDK </strong>in Flex Compiler Configuration instead of Server Flex SDK</li>
        <li>Right click and select <strong>Recreate HTML Template</strong> if you see error.</li>
        <li>After all these, you have configured your Flex application pointing to the webapp server and sharing the BlazeDS configuration files. You can verify in Flex Compiler Configuration's Additional Compiler Parameters. See whether you see this: <strong>-services "C:\tools\tomcat-6.0.16\webapps\jp\WEB-INF\flex\services-config.xml" -locale en_US</strong></li>
        <li>Move the war to your tomcat's webapp folder and start it under remote debugging setting. If you are using window, set<strong> DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=n</strong> under your bin/catalina.bat.</li>
        <li>Start your webapp via bin/startup.bat</li>
        <li>Put breakpoint under <strong>TodoServiceImpl</strong> save method and start remote debugger on localhost:8787</li>
        <li>Right click the<strong> index.mxml</strong> and Run As Flex Application.</li>
        <li>Add a new entry and save it on the flex app. <img onclick="grin(':razz:');" alt=":razz:" src="../../../../../wp-includes/images/smilies/icon_razz.gif" /> You should see your remote debugger halt at the breakpoint for you to debug.</li>
        <li>Now you can change your flex code and test it out without leaving your Eclipse. However, if you modify the service in webapp, you need to run "<strong>mvn clean install</strong>" and deploy the war to the tomcat before your flex code can call your server-side code via <strong>AMF</strong>.</li>
    </ul>
    </li>
</ol>
<h2>Use Mate as Framework</h2>
<p>If you are not familiar with Mate, click the image below that moves you to a nice presentation.</p>
<p>&#160;<a href="http://mate.asfusion.com/assets/content//presentations/360_max_presentation.pdf"><img src="http://www.solutionhacker.com/wp-content/uploads/image/mate1.JPG" style="width: 589px; height: 339px;" alt="" /></a></p>
<p><u>What did I do to restructure the todolist sample to make it Mate app?</u></p>
<ol>
    <li>&#160;</li>
</ol>
<h2>Download</h2>
<p>I have made my work available at: <a href="http://www.solutionhacker.com/wp-content/uploads/todolist-jp-modified.zip">www.solutionhacker.com/wp-content/uploads/todolist-jp-modified.zip</a></p>
<h2>Reference</h2>
<p>Below are the references I used for the article:</p>
<ol>
    <li><a href="http://docs.flex-mojos.info/flex-compiler-mojo/compile-swf-mojo.html">Flex mojo compiler user guide</a></li>
    <li><a href="http://blog.flex-mojos.info/2008/06/04/scopes/">Flex mojo dependency scope rules</a></li>
    <li><a href="http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:Flex_3_RSLs">Flex 3 feature introduction: Flex 3 RSL</a></li>
    <li><a href="http://www.adobe.com/devnet/flex/articles/flash_player_cache.html">Improving Flex application performance using Flash Player Cache</a></li>
    <li><a href="http://fna.googlecode.com/svn/trunk/fna/site/mvn_archetypes/index.html">FNA archetype projects&#160;</a></li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This article is written on top of the great work that&#160;<strong>Sébastien Arbogast </strong>has done. He has written 3 articles that showed you how to wire up Flex, BlazeDS, Spring, Hibernate and MySQL with Maven as build process. I have included his articles below as your reference.</p>
<ol>
<li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt1.html">The Flex, Spring, and BlazeDS full stack – Part 1: Creating a Flex module</a></li>
<li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt2.html">The Flex, Spring and BlazeDS full stack – Part 2: Writing the to-do list server</a></li>
<li><a href="http://www.adobe.com/devnet/flex/articles/fullstack_pt3.html">The Flex, Spring and BlazeDS full stack – Part 3: Putting the application together</a></li>
</ol>
<p>I have found Sebastien&#8217;s work as a good foundation for my own project. To contribute back to the community, I will write a series of articles to show you how can customize and extend the todolist sample.</p>
<p><u>What is in the Part 1 of the series&#8230;</u></p>
<ol>
<li>Enhancements on the <strong>Maven </strong>build process
<ul>
<li>Leverage <strong>RSL </strong>to factor our the framework swc, so the size of the application swf will be reduced. Apart from that, I also take advantage of <strong>Flash Player Cache</strong> that is available after version 9 update 3 to cache the framework libraries.</li>
<li>Clean up the Flex and <strong>BlazeDS </strong>dependencies in POM as the latest version of the sdk is available and the BlazeDS dependencies are officially available.</li>
<li>Include some common reports for maven site generation</li>
<li>Embed <strong>Jetty</strong> web server in the build process for quick deployment and testing</li>
</ul>
</li>
<li>Document how to get the sample up on <strong>Eclipse </strong>for development<strong><br />
    </strong></li>
<li>Use <strong>Mate </strong>as Flex framework
<ul>
<li>Restructure ToDoList sample to leverage Mate framework</li>
<li>Factor out Mate as RSL and integrate it with Maven build process via Flex-mojo plugin.</li>
</ul>
</li>
</ol>
<p><u>What are in the coming articles&#8230;</u></p>
<ol>
<li>In part 2 of this series, I will show you how to use flex-mojo to build a modular Flex application.</li>
<li>In part 3 of this series, I will show you how to test your flex app via FlexUnit (Unit test) and FlexMonkey (Functional test)</li>
<li>In part 4 or this series, I will work on server side. I am planning to add monitoring, caching and security to the server side.</li>
</ol>
<p><span id="more-199"></span><!--more--></p>
<h2><!--more-->Review &#8220;ToDoList&#8221; sample</h2>
<p>Before I start my journey, let me highlight what Sebastien has done first:</p>
<ol>
<li>Sebastien&#8217;s sample demonstrates how to use Maven as a build process. There are 3 parts or subprojects in his sample. They are:
<ul>
<li><strong>todolist-config</strong> (configuration files shared by other subprojects)</li>
<li><strong>todolist-ria </strong>(Flex frontend)</li>
<li><strong>todolist-web</strong> (Server side that supports the Frontend)</li>
</ul>
</li>
<li>All these subprojects are considered as <strong>modules </strong>of the main project (root POM). Finally, they are combined together into war artifact and ready to deploy to Tomcat or other J2EE webapp server.</li>
<li>Flex frontend and backend communicate through a binary RPC protocol &#8211; <strong>AMF</strong>. AMF is considered to be the simplest and fastest remoting approach available in Flex. Recently, Adobe has released BlazeDS as an open source implementation of AMF spec. In this sample, <strong>BlazeDS </strong>is used. To use BlazeDS, there are few things you need to do:
<ul>
<li>Externalize your POJO service via BlazeDS. This sample shows you how to integrate BlazeDS with Spring</li>
<li>Make BlazeDS endpoints availabe to the Net via Servlet.</li>
<li>Have frontend and backend shared the same BlazeDS configuration files.</li>
</ul>
</li>
<li>In this sample, you can also find out how to use <strong>flex-mojo</strong> maven plugin to compile the Flex frontend code into swf. Apart from <a href="http://docs.flex-mojos.info/flex-compiler-mojo/compile-swf-mojo.html">flex-mojo plugin</a>, there are other two good plugins worth to mention:
<ul>
<li><strong>maven-assembly-plugin </strong>- can be used to bundle all the files under a directory into a zip file. It is used by todolist-config to bundle all the configuration files (<strong>service-config.xml </strong>and <strong>remoting-config.xml</strong>) into a zip during the <strong>package </strong>phase.</li>
<li><strong>maven-dependency-plugin</strong><strong> &#8211; </strong>can be used to unpack the zip file and move to the place you want. It is used by todolist-web to unpack the config zip during the <strong>generate-resources</strong> phase.</li>
</ul>
</li>
</ol>
<h2>Enhancements on maven POM</h2>
<p>I have modified the sample&#8217;s maven pom as follows:</p>
<ul>
<li>Link to new repository &#8220;<strong>Sonatype Forge</strong>&#8221; in the root POM. So, I can use the new version of flex-mojo and simplify the todolist-ria adobe framework dependencies. Apart from that, I also take away the private repository from Sebastein because BlazeDS libraries are available in official maven repository (Note: The BlazeDS libraries available in official maven repo are in version 3.0 instead of 3.0.0.544. So, you need to modify the webapp pom correspondingly).</li>
</ul>
<blockquote>
<p>&#160;&#160;&#160; &lt;repositories&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;repository&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;id&gt;flex-mojos-repository&lt;/id&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;url&gt;http://svn.sonatype.org/flexmojos/repository/&lt;/url&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;releases&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;true&lt;/enabled&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/releases&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;snapshots&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;false&lt;/enabled&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/snapshots&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/repository&gt;<br />
&#160;&#160;&#160; &lt;/repositories&gt;</p>
<p>&#160;&#160;&#160; &lt;pluginRepositories&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;pluginRepository&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;id&gt;flex-mojos-repository&lt;/id&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;url&gt;http://svn.sonatype.org/flexmojos/repository/&lt;/url&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;releases&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;true&lt;/enabled&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/releases&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;snapshots&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;false&lt;/enabled&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/snapshots&gt;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/pluginRepository&gt;<br />
&#160;&#160;&#160; &lt;/pluginRepositories&gt;</p>
</blockquote>
<ul>
<li>Because I link to Sonatype repository, I can have my todolist-ria depends on one flex-framework pom dependency instead of all the swc dependencies. Note that the pom dependency is a way to factor out all the adobe swc dependencies that makes your pom easier to maintain.</li>
</ul>
<blockquote>
<p>&#160;&#160;&#160; &#160;&#160;&#160; &lt;dependency&gt;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &lt;artifactId&gt;flex-framework&lt;/artifactId&gt;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &lt;version&gt;3.1.0.2710&lt;/version&gt;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &lt;type&gt;pom&lt;/type&gt;<br />
&#160;&#160;&#160; &#160;&#160;&#160; &lt;/dependency&gt;</p>
</blockquote>
<ul>
<li>I include mysql driver as dependency in my webapp pom. I think it is cleaner to bundle it in war. I have also added <strong>jetty plugin</strong> in the POM so you have a web server embedded in the build process. With this, you can run this sample application right after you check it out from svn (assume you have maven 2 installed). To start jetty, you can issue the following maven command under your webapp project.</li>
</ul>
<blockquote>
<p>project_root&gt; mvn clean install<br />
project_root/jp-web&gt; mvn jetty:run-war</p>
</blockquote>
<ul>
<li>I have included some reports that will be shown after site generation. You may not be able to do <strong>mvn site-deploy </strong>because it is linked to my web hosting site. However, you can modify it for your own sake.</li>
</ul>
<h2>Get the sample up on Eclipse</h2>
<p>To develop on Eclipse, you can follow the steps below:</p>
<ol>
<li>Create Eclipse project file via running the command below at the project root. This will create 2 eclipse projects. One for todolist-ria and one for the webapp. You noticed that I use the <strong>-Declipse.downloadSource=true</strong> to include the source files of my dependencies in my eclipse project. Therefore, I can get to the source code if needed.</li>
</ol>
<blockquote>
<p>mvn -Declipse.downloadSource=true eclipse:eclipse</p>
</blockquote>
<ol>
<li>Import the projects into Eclipse</li>
<li>Add new variable<strong> M2_REPO</strong> and set it equals to<strong> [home]/.m2/repository</strong></li>
<li>If you have installed <strong>Flex Builder plugin</strong> to your Eclipse, you can Add <strong>Flex Project Nature</strong> to the todolist-ria project.
<ul>
<li>Select Application Server Type: J2EE</li>
<li>Put check on &#8220;Use remote object access service&#8221; with LiveCycle Data Service selected.</li>
<li>Set up the path. I have my tomcat installed under C:\tools with default <strong>8080 </strong>as port. You should make the changes if you installed it differently.</li>
<li><img src="http://www.solutionhacker.com/wp-content/uploads/image/flexEclipse1.JPG" style="width: 531px; height: 284px;" alt="" /></li>
<li>Remove the generated <strong>main.mxml</strong> under the src folder.</li>
<li>Set <strong>index.mxml </strong>under src folder as default Flex application file to run.</li>
<li>Use <strong>Default Flex SDK </strong>in Flex Compiler Configuration instead of Server Flex SDK</li>
<li>Right click and select <strong>Recreate HTML Template</strong> if you see error.</li>
<li>After all these, you have configured your Flex application pointing to the webapp server and sharing the BlazeDS configuration files. You can verify in Flex Compiler Configuration&#8217;s Additional Compiler Parameters. See whether you see this: <strong>-services &#8220;C:\tools\tomcat-6.0.16\webapps\jp\WEB-INF\flex\services-config.xml&#8221; -locale en_US</strong></li>
<li>Move the war to your tomcat&#8217;s webapp folder and start it under remote debugging setting. If you are using window, set<strong> DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=n</strong> under your bin/catalina.bat.</li>
<li>Start your webapp via bin/startup.bat</li>
<li>Put breakpoint under <strong>TodoServiceImpl</strong> save method and start remote debugger on localhost:8787</li>
<li>Right click the<strong> index.mxml</strong> and Run As Flex Application.</li>
<li>Add a new entry and save it on the flex app. <img onclick="grin(':razz:');" alt=":razz:" src="../../../../../wp-includes/images/smilies/icon_razz.gif" /> You should see your remote debugger halt at the breakpoint for you to debug.</li>
<li>Now you can change your flex code and test it out without leaving your Eclipse. However, if you modify the service in webapp, you need to run &#8220;<strong>mvn clean install</strong>&#8221; and deploy the war to the tomcat before your flex code can call your server-side code via <strong>AMF</strong>.</li>
</ul>
</li>
</ol>
<h2>Use Mate as Framework</h2>
<p>If you are not familiar with Mate, click the image below that moves you to a nice presentation.</p>
<p>&#160;<a href="http://mate.asfusion.com/assets/content//presentations/360_max_presentation.pdf"><img src="http://www.solutionhacker.com/wp-content/uploads/image/mate1.JPG" style="width: 589px; height: 339px;" alt="" /></a></p>
<p><u>What did I do to restructure the todolist sample to make it Mate app?</u></p>
<ol>
<li>&#160;</li>
</ol>
<h2>Download</h2>
<p>I have made my work available at: <a href="http://www.solutionhacker.com/wp-content/uploads/todolist-jp-modified.zip">www.solutionhacker.com/wp-content/uploads/todolist-jp-modified.zip</a></p>
<h2>Reference</h2>
<p>Below are the references I used for the article:</p>
<ol>
<li><a href="http://docs.flex-mojos.info/flex-compiler-mojo/compile-swf-mojo.html">Flex mojo compiler user guide</a></li>
<li><a href="http://blog.flex-mojos.info/2008/06/04/scopes/">Flex mojo dependency scope rules</a></li>
<li><a href="http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:Flex_3_RSLs">Flex 3 feature introduction: Flex 3 RSL</a></li>
<li><a href="http://www.adobe.com/devnet/flex/articles/flash_player_cache.html">Improving Flex application performance using Flash Player Cache</a></li>
<li><a href="http://fna.googlecode.com/svn/trunk/fna/site/mvn_archetypes/index.html">FNA archetype projects&#160;</a></li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/wiring-up-flex-mate-blazeds-spring-hibernate-and-mysql-with-maven-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to test my system?</title>
		<link>http://www.solutionhacker.com/uncategorized/how-to-test-my-system/</link>
		<comments>http://www.solutionhacker.com/uncategorized/how-to-test-my-system/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 15:03:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[6. Uncategorized]]></category>
		<category><![CDATA[Team]]></category>
		<category><![CDATA[automated testing]]></category>
		<category><![CDATA[Flex Monkey]]></category>
		<category><![CDATA[functional testing]]></category>
		<category><![CDATA[jmeter]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[stress testing]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=194</guid>
		<description><![CDATA[<h2>Here is a good video from Google&#160;</h2>
<embed id="VideoPlayback" src="http://video.google.com/googleplayer.swf?docid=-6891978643577501895&#38;hl=en&#38;fs=true" style="width: 400px; height: 326px;" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash"></embed>
<h2>Testing Strategies Overview</h2>
<p>I believe that I don't need to stress out how important testing is. So, lets cut the crap and talk about the challenging areas related to this subject. Here are the things I want to talk about</p>
<ol>
    <li>Write your unit test first then code<br />
    <ul>
        <li>It is the core concept from <strong>Test Driven Development (TDD)</strong>. Everyone tried that will tell how great it is. However, the difficult part of it is to <strong>enforce </strong>it across your team especially under the time constraint. Everyone wants to get something out right away and we are all getting so much stresses from our business side about features release to stay competitive in the market. How can we allocate time for this "luxury"? The key here is whether you believe it will save you tons of time in a long run. If not, it is hard to carry out this idea.</li>
        <li>What are the areas that could save my time? <strong>Agile </strong>development may face one big challenge from the product side. The problem is mainly due to the way they break down the project into <strong>mini-specs</strong> to fit into a sprint of work. Sometimes they find it difficult to think of a project in a micro level. To deliver the mini-spec in a agile process, they may leave out the detail in the spec and try to fill them up in an iterative fashion. Write your test first forces you to think API, input, output and use cases ahead of time. This will help you to feedback the product team earlier in the loop. Otherwise, it will cause you more time to change your logic or patch your codes later.</li>
        <li>If you have a suite of unit tests, you are more confidence to do refactoring because you can perform regression tests to make sure nothing is broken. Apart from that, you can add new features to someone's code without worrying that it will break the old features as you have the unit tests from the owner to verify.</li>
        <li>Things you need to pay attention are: (1) Don't commit code to the trunk that breaks the build (compile), but it is ok that it doesn't pass the tests temporary as you are in the middle to fill up the code and you don't want to have your code sitting in your local box too long. (2) Do <strong>code coverage</strong> to make sure you have your unit test exercises your codes in good %.</li>
        <li>Tools I used to write my unit test: <strong>TestNG/ JUnit </strong>for Java code, <strong>FlexUnit </strong>for flex code</li>
        <li>How do we unit test our DAO? Test with your local database (use same vendor and version of the database as the one in production. I don't like to use any memory databases like Hypersonic or SQLite b/c it doesn't really test our your SQL).</li>
    </ul>
    </li>
    <li>Functional testing - use <strong>Selenium </strong>to automate it.</li>
</ol>
<h2>Performance/load testing</h2>
<p><strong><u>Basic workflow</u></strong></p>
<ol>
    <li><strong>Create use case scripts</strong> for your application via <strong>recording</strong>. For Flex, we want a tool that can convert the binary AMF message to readable text as part of our script.</li>
    <li><strong>Introduce natural variability </strong>- varying the login credentials, records opened, records saved, and other user actions including thinking time. This step is important because it provides the real-world variability that keeps your application working hard and prevents you from missing performance problems because of caching at various layers on your server.</li>
    <li><strong>Define test data</strong> sets to be used by your scripts as you ramp up hundreds or thousands of simulated users executing your tests.</li>
    <li><strong>Define profiles of load on your application</strong>. You might decide to have 20% of your users entering information slowly, 20% entering information very quickly, 40% looking up information, 10% producing reports, and 10% making account changes. The breakdowns and level of detail are entirely up to you.</li>
    <li><strong>Specify how to run the test.</strong> You control such things as the <strong>speed of ramping up</strong> user load, how fast each user executes the test, and whether there should be natural variability between users and sessions. Each tool provides different fine-grained control over this step.</li>
</ol>
<p><u><span style="font-weight: bold;">Tips</span></u></p>
<ul>
    <li>Don't carry performance test without passing all the functional tests.</li>
    <li>Test against single box first and you should not run JMeter on the same machine running the application to be tested.</li>
    <li>Make sure that the testing is affected as little as possible by network traffic (do it in the subnet to take out network IO factor).</li>
    <li>Create a <strong>test plan</strong> that contains <strong>thread group</strong>(s) that controls the threads that will be created by JMeter to simulate simultaneous users. Determine # of threads and the ramp-up period. Add HttpRequest then listener to view result in table and/or graph format. Each thread will issue an HttpRequest and response time will be recorded. Then <strong>avg response time</strong> and <strong>standard deviation</strong> will be calculated. Another way people uses JMeter is to use its <a href="http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf">HTTP session recording</a> to produce load tests.</li>
    <li>On the other hand, you need to <strong>monitor </strong>your target in terms of CPU, memory and IO consumption (use <strong>OpenNMS</strong>) during the perfomance testing.</li>
    <li>Create a <strong>scheduled integration build</strong> that runs       JMeter tests (use <strong>CruiseControl</strong>). Read this <a href="http://www.ibm.com/developerworks/java/library/j-ap04088/index.html">article </a>for integration detail.</li>
    <li>How to achieve the load via distribution?</li>
    <li>How to obtain meaningful information from the raw data?</li>
    <li>Look at throughput (QPS), resources consumption (CPU, Memory, IO) over time and over users/ load.</li>
    <li>Need to set up the database with good amount of data for testing.</li>
    <li>Performance profiling
    <ul>
        <li>Obtain the rough data from performance test first</li>
        <li>Identify the bottleneck and fix the problem.</li>
        <li>Don't waste too much time to over-tune your system. Just fix the bottlenecks that impact the SLA.</li>
    </ul>
    </li>
    <li>Stress testing</li>
    <li>Scalability testing - testing on scaling out or up your system.</li>
    <li>Availability testing</li>
</ul>
<h2>Reference</h2>
<p>Below are the references I read to write this article</p>
<ol>
    <li><a href="http://www.opensourcetesting.org/resources.php">http://www.opensourcetesting.org</a></li>
    <li><a href="http://jakarta.apache.org/jmeter/usermanual/index.html">JMeter User Manual</a></li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Here is a good video from Google&#160;</h2>
<p><embed id="VideoPlayback" src="http://video.google.com/googleplayer.swf?docid=-6891978643577501895&amp;hl=en&amp;fs=true" style="width: 400px; height: 326px;" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></p>
<h2>Testing Strategies Overview</h2>
<p>I believe that I don&#8217;t need to stress out how important testing is. So, lets cut the crap and talk about the challenging areas related to this subject. Here are the things I want to talk about</p>
<ol>
<li>Write your unit test first then code
<ul>
<li>It is the core concept from <strong>Test Driven Development (TDD)</strong>. Everyone tried that will tell how great it is. However, the difficult part of it is to <strong>enforce </strong>it across your team especially under the time constraint. Everyone wants to get something out right away and we are all getting so much stresses from our business side about features release to stay competitive in the market. How can we allocate time for this &#8220;luxury&#8221;? The key here is whether you believe it will save you tons of time in a long run. If not, it is hard to carry out this idea.</li>
<li>What are the areas that could save my time? <strong>Agile </strong>development may face one big challenge from the product side. The problem is mainly due to the way they break down the project into <strong>mini-specs</strong> to fit into a sprint of work. Sometimes they find it difficult to think of a project in a micro level. To deliver the mini-spec in a agile process, they may leave out the detail in the spec and try to fill them up in an iterative fashion. Write your test first forces you to think API, input, output and use cases ahead of time. This will help you to feedback the product team earlier in the loop. Otherwise, it will cause you more time to change your logic or patch your codes later.</li>
<li>If you have a suite of unit tests, you are more confidence to do refactoring because you can perform regression tests to make sure nothing is broken. Apart from that, you can add new features to someone&#8217;s code without worrying that it will break the old features as you have the unit tests from the owner to verify.</li>
<li>Things you need to pay attention are: (1) Don&#8217;t commit code to the trunk that breaks the build (compile), but it is ok that it doesn&#8217;t pass the tests temporary as you are in the middle to fill up the code and you don&#8217;t want to have your code sitting in your local box too long. (2) Do <strong>code coverage</strong> to make sure you have your unit test exercises your codes in good %.</li>
<li>Tools I used to write my unit test: <strong>TestNG/ JUnit </strong>for Java code, <strong>FlexUnit </strong>for flex code</li>
<li>How do we unit test our DAO? Test with your local database (use same vendor and version of the database as the one in production. I don&#8217;t like to use any memory databases like Hypersonic or SQLite b/c it doesn&#8217;t really test our your SQL).</li>
</ul>
</li>
<li>Functional testing &#8211; use <strong>Selenium </strong>to automate it.</li>
</ol>
<h2>Performance/load testing</h2>
<p><strong><u>Basic workflow</u></strong></p>
<ol>
<li><strong>Create use case scripts</strong> for your application via <strong>recording</strong>. For Flex, we want a tool that can convert the binary AMF message to readable text as part of our script.</li>
<li><strong>Introduce natural variability </strong>- varying the login credentials, records opened, records saved, and other user actions including thinking time. This step is important because it provides the real-world variability that keeps your application working hard and prevents you from missing performance problems because of caching at various layers on your server.</li>
<li><strong>Define test data</strong> sets to be used by your scripts as you ramp up hundreds or thousands of simulated users executing your tests.</li>
<li><strong>Define profiles of load on your application</strong>. You might decide to have 20% of your users entering information slowly, 20% entering information very quickly, 40% looking up information, 10% producing reports, and 10% making account changes. The breakdowns and level of detail are entirely up to you.</li>
<li><strong>Specify how to run the test.</strong> You control such things as the <strong>speed of ramping up</strong> user load, how fast each user executes the test, and whether there should be natural variability between users and sessions. Each tool provides different fine-grained control over this step.</li>
</ol>
<p><u><span style="font-weight: bold;">Tips</span></u></p>
<ul>
<li>Don&#8217;t carry performance test without passing all the functional tests.</li>
<li>Test against single box first and you should not run JMeter on the same machine running the application to be tested.</li>
<li>Make sure that the testing is affected as little as possible by network traffic (do it in the subnet to take out network IO factor).</li>
<li>Create a <strong>test plan</strong> that contains <strong>thread group</strong>(s) that controls the threads that will be created by JMeter to simulate simultaneous users. Determine # of threads and the ramp-up period. Add HttpRequest then listener to view result in table and/or graph format. Each thread will issue an HttpRequest and response time will be recorded. Then <strong>avg response time</strong> and <strong>standard deviation</strong> will be calculated. Another way people uses JMeter is to use its <a href="http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf">HTTP session recording</a> to produce load tests.</li>
<li>On the other hand, you need to <strong>monitor </strong>your target in terms of CPU, memory and IO consumption (use <strong>OpenNMS</strong>) during the perfomance testing.</li>
<li>Create a <strong>scheduled integration build</strong> that runs       JMeter tests (use <strong>CruiseControl</strong>). Read this <a href="http://www.ibm.com/developerworks/java/library/j-ap04088/index.html">article </a>for integration detail.</li>
<li>How to achieve the load via distribution?</li>
<li>How to obtain meaningful information from the raw data?</li>
<li>Look at throughput (QPS), resources consumption (CPU, Memory, IO) over time and over users/ load.</li>
<li>Need to set up the database with good amount of data for testing.</li>
<li>Performance profiling
<ul>
<li>Obtain the rough data from performance test first</li>
<li>Identify the bottleneck and fix the problem.</li>
<li>Don&#8217;t waste too much time to over-tune your system. Just fix the bottlenecks that impact the SLA.</li>
</ul>
</li>
<li>Stress testing</li>
<li>Scalability testing &#8211; testing on scaling out or up your system.</li>
<li>Availability testing</li>
</ul>
<h2>Reference</h2>
<p>Below are the references I read to write this article</p>
<ol>
<li><a href="http://www.opensourcetesting.org/resources.php">http://www.opensourcetesting.org</a></li>
<li><a href="http://jakarta.apache.org/jmeter/usermanual/index.html">JMeter User Manual</a></li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/uncategorized/how-to-test-my-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

