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

<channel>
	<title>Solution Hacker &#187; architecture</title>
	<atom:link href="http://www.solutionhacker.com/tag/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solutionhacker.com</link>
	<description>This blog provides solutions for enterpreneurs!</description>
	<lastBuildDate>Fri, 10 Sep 2010 04:05:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tomcat Performance Tuning</title>
		<link>http://www.solutionhacker.com/implement-your-idea/scale-your-website/tomcat-performance-tuning/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/scale-your-website/tomcat-performance-tuning/#comments</comments>
		<pubDate>Thu, 29 May 2008 20:15:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[2.4. Scale Your Site]]></category>
		<category><![CDATA[2.6. Unleash Your System]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[connection pool]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[HotSpot]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=147</guid>
		<description><![CDATA[Most companies I have worked for use Tomcat as Servlet Container. It is de facto standard just like how Apache been used as Web Server. However, most of us just drag our war file to the webapp folder and use Tomcat with all the settings as default out of the box. It works fine in [...]]]></description>
			<content:encoded><![CDATA[<p>Most companies I have worked for use Tomcat as Servlet Container. It is de facto standard just like how Apache been used as Web Server. However, most of us just drag our war file to the webapp folder and use Tomcat with all the settings as default out of the box. It works fine in development environment but may not in production. This article will give you advice in several areas:</p>
<ol>
<li>Production Tomcat Architecture</li>
<li>Tuning tomcat for performance</li>
<li>Resolving problems which affect availability</li>
</ol>
<p><span id="more-147"></span></p>
<h2>&#160;<!--more-->Production Tomcat Architecture</h2>
<p>In production Tomcat relies on a number of resources which can impact its overall performance. Understanding the overall system architecture is key to tuning performance and troubleshooting problems.</p>
<p style="text-align: left;"><img height="220" width="471" alt="" src="http://www.solutionhacker.com/wp-content/uploads/tomcatSystemArch(1).jpg" /></p>
<ol>
<li>Hardware: CPU(s), memory, network IO and file IO</li>
<li>OS: SMP (symmetric multiprocessing) and thread support</li>
<li>JVM: version, tuning memory usage, and tuning GC</li>
<li>Tomcat: version (example, Tomcat 6 supports NIO)</li>
<li>Application: Application design can have the largest impact on overall performance</li>
<li>Database: concurrent db connection is allowed (pooling and object caching)</li>
<li>Web Server: Apache can sit in front of Tomcat and serves the static content. It also can do load balancing across multiple Tomcat instances.</li>
<li>Network: Network delays.</li>
<li>Remote Client: How fast is the communication protocol? Content can be compressed.&#160;</li>
</ol>
<h2>Performance Tuning</h2>
<p><u>How to measure and test performance</u></p>
<ul>
<li><strong>Request latency</strong> is key b/c it reflects the responsiveness of your site for visitors.</li>
<li>Test environment should match production as closely as possible.</li>
<li>The <strong>data volume </strong>is important to simulate in database side.</li>
<li>Test HTTP requests with different request parameters (test corner cases)</li>
<li>Use <strong>load test</strong> to simulate the traffics (ex. JMeter)</li>
<li>Final tests should be <strong>over longer periods like days</strong> because JVM performance changes over time and can actually improve if using HotSpot. Memory leaks, db temporary unavailable, etc can only be found when running longer tests.</li>
</ul>
<p><u>JVM version, memory usage and GC</u></p>
<ul>
<li>Sun Java 1.3 and later releases inlcude <strong>HotSpot </strong>profiling optimizer customized for long running server application.</li>
<li><img src="file:///C:/WINDOWS/TEMP/moz-screenshot-1.jpg" alt="" />Tomcat will freeze processing of all requests while the JVM is performing <a target="_blank" href="http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html">GC</a>. On a poorly tuned JVM this can last 10&#8242;s of seconds. Most GC&#8217;s should take &lt; 1 second and never exceed 10 seconds</li>
<li>Tune the -Xms (min) and -Xmx (max) java<strong> stack memory </strong>(set them to the same value can improve GC performance)</li>
<li>Make sure the java process always keeps the memory it uses resident in physical memory and not swapped out to virtual memory.</li>
<li>Use -Xincgc to enable<strong> incremental garbage collection</strong></li>
<li>Try reducing -Xss thread stack memory usage</li>
</ul>
<p><u>Tomcat version and configuration</u></p>
<ul>
<li>Tomcat 6 supports NIO.</li>
<li>Set &#8220;reloadable&#8221; false &#8211; remove unnecessary detection overhead</li>
<li>Set &#8220;liveDeploy&#8221; to false &#8211; liveDeploy controls whether your webapps directory is periodically checked for new war files. This is done using background thread.</li>
<li>Set &#8220;debug&#8221; to 0</li>
<li>Set &#8220;swallowOutput&#8221; to true &#8211; This makes sure all output to stdout or stderr for a web application gets directed to the web application log rather than the console or catalina.out. This make it easier to troubleshoot problems.</li>
<li>Connector configuration &#8211; minProcessor, maxProcessor, acceptCount, enableLookups. Don&#8217;t set the acceptCount too high b/c this sets the number of pending requests awaiting processing. It is better deny few requests than overload Tomcat and cause problems for all requests. Set &#8220;enableLookups&#8221; to false b/c DNS lookups can add significant delays.</li>
</ul>
<p><u>Database connection pool</u></p>
<ul>
<li>We use connection pool provided by Spring instead</li>
<li>Using middleware to persist and cache objects from your database can significantly improve performance b/c of fewer db calls, less thrashing of the JVM for creation and subsequent GC of object craeted for resultset.</li>
</ul>
<p><u>Application design and profiling</u></p>
<ul>
<li>If the data used to generate a dynamic page rarely changes, modify it to a static page which you regenerate periodically.</li>
<li>Cache dynamic page</li>
<li>Use tool like JProble to profle your web applications during development phase</li>
<li>Look for possible thread synchronization bottlenecks</li>
<li>Date and Time thread synchronization bottleneck&#160;</li>
</ul>
<h2>Troubleshooting</h2>
<p><u>Collecting and analyzing log data</u></p>
<p><u>Common problems</u></p>
<ul>
<li><strong>Broken pipe</strong> &#8211; For HTTP Connector indicates that the remote client aborted the request. For web server JK Connector indicates that the web server process or thread was terminated. These are normal and rarely due to a problem with Tomcat. However, if you have long request, the connectionTimeout may close the connection before you send your response back.</li>
<li><strong>Tomcat freezes or pauses </strong>with no request being processed &#8211; usually due to a long pause of JVM GC. A long pause can cause a cascading effect and high load once Tomcat starts handling requests again. Don&#8217;t set the &#8220;acceptCount&#8221; too high and use java -verbose:gc startup argument to collect GC data.</li>
<li><strong>Out of Memory Exception</strong> &#8211; look into application code to fix the leak (profile tool can help). Increase available memory on the system via -Xmx. Restart tomcat!</li>
<li>Database connection failure &#8211; connection used up when traffic is spike.</li>
<li><strong>Random connection close exception </strong>- when you close your connection twice. First close(), the connection returns to the pool. It may be picked up by another thread. Now, second close() may close a connection that is being used by other thread. Don&#8217;t close connection twice, use JDBC Template from Spring to avoid this problem.&#160;</li>
</ul>
<h2>Reference</h2>
<ol>
<li><a target="_blank" href="http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html">JavaWorld GC Article</a></li>
<li><a target="_blank" href="http://java.sun.com/docs/hotspot/index.html">Sun HotSpot Performance Document</a></li>
<li><a target="_blank" href="http://uuu.teetzen.net/uniweb/tomcat_performance.pdf">Tomcat Performance Slides</a></li>
</ol>
<p>&#160;&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/scale-your-website/tomcat-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Architecture &#8211; MVCS</title>
		<link>http://www.solutionhacker.com/data-intelligence/data-visualization/flex-architecture-mvcs/</link>
		<comments>http://www.solutionhacker.com/data-intelligence/data-visualization/flex-architecture-mvcs/#comments</comments>
		<pubDate>Fri, 25 May 2007 00:01:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[4.2. Visualize Your Data]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mvcs]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/2007/05/24/flex-architecture-mvcs/</guid>
		<description><![CDATA[I have come across an excellent article from Joe Berkovitz that talks about a &#8220;right&#8221; way to architect your application. I like this article a lot. It gives me a good refresh of what I have learnt in these years. I decide to spend a little time to go over some of the key points [...]]]></description>
			<content:encoded><![CDATA[<p>I have come across an excellent <a href="http://www.adobe.com/devnet/flex/articles/blueprint.html" target="_blank">article</a> from Joe Berkovitz that talks about a &#8220;right&#8221; way to architect your application. I like this article a lot. It gives me a good refresh of what I have learnt in these years. I decide to spend a little time to go over some of the key points from this article.</p>
<blockquote><p>Isolation and encapsulation are the keys. Isolating concerns opens the door to accommodating change, because it puts boundaries on the ripple effects of changes within the code. Isolation makes modular development and testing easy. Isolation makes it easy to have different people work on different pieces. Finally, isolation makes it easier to envision ways of improving the user experience that are generalized and powerful.</p></blockquote>
<p>The first rule I learntÂ in component design isÂ &#8220;Reduce coupling and increase cohesion&#8221;. The goal of this is to reduce the amount of interactions among components and in turn promote reusability and reduce complexity. This concept proven to be useful in my career life. The tricky part of it is to draw a line around a component and provide a clear responsibilities (ie. via interface) and interactions of it (ie. communication). A good architect can make it very clean and simple whereas a novice designer cannot make a component reusable without associated with different dependencies. In this article, the author focuses on the design in UI, but the rules apply to all aspects of design. A term &#8220;MVCS&#8221; is mentioned that adds &#8220;Services&#8221; to the common known MVC pattern. Service is responsible to encapsulate the communication with the external world. Here is the diagram of the MVCS:</p>
<p><a title="MVCS" href="http://www.solutionhacker.com/wp-content/uploads/2007/05/fig_01.gif"><img alt="MVCS" src="http://www.solutionhacker.com/wp-content/uploads/2007/05/fig_01.gif" /></a>  </p>
<p>In MVCS, <strong>Model</strong> captures the state of the application. It doesn&#8217;t know any of the non-Model classes and it carries no intelligence (ie. no function but read/write for properties). According to the author:</p>
<blockquote><p>In general, avoid functions, since they introduce more complexity, and stray interactions with non-Model objects can creep in. Complex logic for model objects usually belongs in the Controller.</p></blockquote>
<p>However, from what I have learnt, there are certainly logics belongs to the model classes. A domain model without anyÂ behavior is termed as &#8220;Anemic Domain Model&#8221; by Martin Fowler. <em>&#8220;&#8230;this is an anti-pattern because it&#8217;s so contrary to the basic idea of object-oriented design; which is to combine data and process together.&#8221; </em>When I look closer, this is the model that supports the UI but not the domain model in the server side. Is the same rule applied in this area as well? On the other hand, how the model notifies the View if its state is changed? In Flex, you can define your properties as &#8220;Bindable&#8221;. Whenever the state of the model is change, an event will be fired to notify the associated View.  </p>
<p><strong>View</strong> references objects in Model via data binding. Bindings are used to move data from sources that change into destinations that need to be change-aware.Â Besides,<strong>View </strong>captures users interaction (via event handler registration) and hands off action to Controller (via calling Controller&#8217;s function in event handler). Controller, like Session, is application-wide object that should be obtained through a static instance variable to avoid having to pass all such objects all over the application.  </p>
<p><strong>Controller</strong> is the center of the application. It is the place where application logic and behavior are implemented. It is the only part of the architecture that communicates with all the other parts, thus relieving the View, Model, and Service packages from needing to know too much about each other.  </p>
<p><strong>Service</strong> objects make up a layer of objects that handle all communication with the outside world like Web Service and Http calls. Besides, Services act as <em>factories</em> for <strong>Operation</strong> objects; it is actually these Operations that do the work of communication by initiating requests, handling responses, and dispatching status and completion events. Why not just do it internally rather than generate the Operation for controller to call? According to the author, it gives more flexibility. However, I don&#8217;t see such much usage of this flexibility. So, I still prefer doing simple Service&#8217;s method call&#8230; <img src='http://www.solutionhacker.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#160;</p>
<p><a title="fig_09.gif" href="http://www.solutionhacker.com/wp-content/uploads/2007/05/fig_09.gif"><img alt="fig_09.gif" src="http://www.solutionhacker.com/wp-content/uploads/2007/05/fig_09.gif" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/data-intelligence/data-visualization/flex-architecture-mvcs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
