<?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>Always Get Better &#187; Web Programming</title>
	<atom:link href="http://www.alwaysgetbetter.com/blog/category/web-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alwaysgetbetter.com/blog</link>
	<description>Never stop looking for ways to improve</description>
	<lastBuildDate>Mon, 30 Jan 2012 12:00:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting up WordPress with nginx and FastCGI</title>
		<link>http://www.alwaysgetbetter.com/blog/2012/01/30/setting-wordpress-nginx-fastcgi/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2012/01/30/setting-wordpress-nginx-fastcgi/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 12:00:17 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=490</guid>
		<description><![CDATA[All web site owners should feel a burning need to speed. Studies have shown that viewers waiting more than 2 or 3 seconds for content to load online are likely to leave without allowing the page to fully load. This is particularly bad if you&#8217;re trying to run a web site that relies on visitors [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/12/20/fastcgi-nginx-performance-vm/' rel='bookmark' title='Using FastCGI with Nginx for Performance on a VM'>Using FastCGI with Nginx for Performance on a VM</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/' rel='bookmark' title='Memcached as Session Handler'>Memcached as Session Handler</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>All web site owners should feel a burning need to speed. Studies have shown that viewers waiting more than 2 or 3 seconds for content to load online are likely to leave without allowing the page to fully load. This is particularly bad if you&#8217;re trying to run a web site that relies on visitors to generate some kind of income &#8211; content is king but speed keeps the king&#8217;s coffers flowing.</p>
<p>If your website isn&#8217;t the fastest it can be, you can take some comfort in the fact that the majority of the &#8220;top&#8221; web sites also suffer from page load times pushing up into the 10 second range (have you BEEN to Amazon lately?). But do take the time to download YSlow today and use its suggestions to start making radical improvements.</p>
<p>I&#8217;ve been very interested in web server performance because it is the first leg of the web page&#8217;s journey to the end user. The speed of execution at the server level is capable of making or breaking the user&#8217;s experience by controlling the amount of &#8216;lag time&#8217; between the web page request and visible activity in the web browser. We want our server to send page data as immediately as possible so the browser can begin rendering it and downloading supporting files.</p>
<p><a href="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2011/12/agb_new.png"><img class="alignright  wp-image-463" title="agb_new" src="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2011/12/agb_new.png" alt="" width="347" height="347" /></a>Not long ago, I described <a href="http://www.alwaysgetbetter.com/blog/2011/12/20/fastcgi-nginx-performance-vm/">my web stack</a> and explained why I moved away from the &#8220;safe&#8221; Apache server solution in favour of nginx. Since nginx doesn&#8217;t have a PHP module I had to use PHP&#8217;s FastCGI (PHP FPM) server with nginx as a reverse proxy. Additionally, I used memcached to store sessions rather than writing to disk.</p>
<p>Here are the configuration steps I took to realize this stack:</p>
<p><strong>1. Memcached Sessions</strong><br />
Using memcached for sessions gives me slightly better performance on my Rackspace VM because in-memory reading&amp;writing is hugely faster than reading&amp;writing to a virtualized disk. I went into a lot more detail about this last April when I wrote about <a href="http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/">how to use memcached as a session handler in PHP</a>.</p>
<p><strong>2. PHP FPM</strong><br />
The newest Ubuntu distributions have a package <strong>php5-fpm</strong> that installs PHP5 FastCGI and an init.d script for it. Once installed, you can tweak your php.ini settings to suit, depending on your system&#8217;s configuration. (Maybe we can get into this another time.)</p>
<p><strong>3. Nginx</strong><br />
Once PHP FPM was installed, I created a site entry that would pass PHP requests forward to the FastCGI server, while serving other files directly. Since the majority of my static content (css, javascript, images) have already been moved to a content delivery network, nginx has very little actual work to do.</p>
<p><code><br />
server {<br />
listen 80;<br />
server_name sitename.com www.sitename.com;<br />
access_log /var/log/nginx/sitename-access.log;<br />
error_log /var/log/nginx/sitename-error.log;<br />
# serve static files<br />
location / {<br />
root /www/sitename.com/html;<br />
index index.php index.html index.htm;</code></p>
<p># this serves static files that exists without<br />
# running other rewrite tests<br />
if (-f $request_filename) {<br />
expires 30d;<br />
break;<br />
}</p>
<p># this sends all-non-existing file or directory requests to index.php<br />
if (!-e $request_filename) {<br />
rewrite ^(.+)$ /index.php?q=$1 last;<br />
}<br />
}</p>
<p>location ~ \.php$ {<br />
fastcgi_pass 127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
fastcgi_param SCRIPT_FILENAME /www/sitename.com/html$fastcgi_script_name;<br />
include fastcgi_params;<br />
}<br />
}</p>
<p>The <strong>fastcgi_param</strong> setting controls which script is executed, based upon the root path of the site being accessed. All of the requests parameters are passed through to PHP, and once the configuration is started up I didn&#8217;t miss Apache one little bit.</p>
<p><strong>Improvements</strong><br />
My next step will be to put a varnish server in front of nginx. Since the majority of my site traffic comes from search engine results where a user has not yet been registered to the site or needs refreshed content, Varnish can step in and serve a fully cached version of my pages from memory far faster than FastCGI can render the WordPress code. I&#8217;ll experiment with this setup in the coming months and post my results.</p>
<div style="width:468px;margin:0 auto">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0410364841759590";
/* Homepage, 468x60 ads, After posts, created 12/19/08 */
google_ad_slot = "4210204644";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/12/20/fastcgi-nginx-performance-vm/' rel='bookmark' title='Using FastCGI with Nginx for Performance on a VM'>Using FastCGI with Nginx for Performance on a VM</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/' rel='bookmark' title='Memcached as Session Handler'>Memcached as Session Handler</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2012/01/30/setting-wordpress-nginx-fastcgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HP Releases Enyo 2.0</title>
		<link>http://www.alwaysgetbetter.com/blog/2012/01/25/hp-releases-enyo-20/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2012/01/25/hp-releases-enyo-20/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 01:56:27 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebOS]]></category>
		<category><![CDATA[enyo]]></category>
		<category><![CDATA[hp]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[webos]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=485</guid>
		<description><![CDATA[Now that WebOS is being made open source, HP has released a new version of the Enyo JavaScript framework. Whereas the first version of the framework only supported Webkit-based environments (like the HP Touchpad, or Safari or Chrome), the newer version has expanded support for Firefox and IE9 as well. Developers who created apps with [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/28/pintsized-mobile-devices/' rel='bookmark' title='Pint-Sized Mobile Devices'>Pint-Sized Mobile Devices</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="Enyo Logo" src="http://cdn.precentral.net/resources/images/000/106/057/large/enyo-html5-palm-logos.png" alt="" width="330" height="169" />Now that WebOS is being made open source, HP has released a new version of the Enyo JavaScript framework. Whereas the first version of the framework only supported Webkit-based environments (like the HP Touchpad, or Safari or Chrome), the newer version has expanded support for Firefox and IE9 as well. Developers who created apps with the old framework will have to wait a little while longer before all of the widgets and controls from Enyo 1.0 are ported over.</p>
<p>What does this mean for app developers? Now that Enyo is open-source, it means applications built on the platform will run on Android and iOS. But it&#8217;s not a disruptive technology &#8211; both Android and iOS have supported HTML5 applications for quite awhile; HP will be competing against mature frameworks like jQuery Mobile.</p>
<p>As a WebOS enthusiast I am definitely going to put some time into continuing my explorations of Enyo, but it&#8217;s getting harder and harder to justify the investment. My Pre is getting pretty old at this point, and hardware manufacturers have yet to express interest in making new devices to take advantage of WebOS. If I end up switching to Android with my next hardware purchase, it&#8217;s going to shift my priorities away from Enyo and its brethren.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/28/pintsized-mobile-devices/' rel='bookmark' title='Pint-Sized Mobile Devices'>Pint-Sized Mobile Devices</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2012/01/25/hp-releases-enyo-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Humans.txt &#8211; the Anti-Robots.txt</title>
		<link>http://www.alwaysgetbetter.com/blog/2012/01/14/humanstxt-antirobotstxt/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2012/01/14/humanstxt-antirobotstxt/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 01:21:24 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[attribution]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=450</guid>
		<description><![CDATA[photo credit: langfordw If you don&#8217;t want a search engine to read some or all of the files on your site, you can create a robots.txt file. (Looking through the blog archive, I realize I&#8217;ve never gone through the construction and contents of that important file, so this is a promise to one day return [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<div class=alignright><a href="http://www.flickr.com/photos/24375810@N06/6611017007/" title="Mimbo - A Friendly Robot" target="_blank"><img src="http://farm8.static.flickr.com/7019/6611017007_94aec8ded9_m.jpg" alt="Mimbo - A Friendly Robot" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://www.alwaysgetbetter.com/blog/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/24375810@N06/6611017007/" title="langfordw" target="_blank">langfordw</a></small></div>
<p>If you don&#8217;t want a search engine to read some or all of the files on your site, you can create a <em>robots.txt</em> file. (Looking through the blog archive, I realize I&#8217;ve never gone through the construction and contents of that important file, so this is a promise to one day return and fix that!)</p>
<p>When you want the opposite &#8211; accessible pages and author credit, create a <em>humans.txt</em> file. Although not an &#8220;official&#8221; standard, it is a fun way to acknowledge the (sometimes many) hardworking individuals behind the creation of a web site.</p>
<p>An example is:</p>
<pre>
/* TEAM */
Leader: Mike Wilson
Site: http://www.alwaysgetbetter.com
Twitter: HawkWilson
Location: Ottawa, ON

/* THANKS */
Seth Godin: http://www.sethgodin.com
Steve Pavlina: http://www.stevepavlina.com
Phil Haack: http://haacked.com

/* SITE */
Last Update: Jan 14, 2012
Standards: HTML5, CSS3
Software: WordPress
</pre>
<p>In most cases, you would want to include at least a TEAM and SITE section. Clearly the exact fields are left to your imagination, but it&#8217;s a very simple way to acknowledge the people who helps (directly or in spirit) a site to get to fruition.</p>
<p>For more information about humans.txt, check out the initiative&#8217;s home page at <a href="http://humanstxt.org/">http://humanstxt.org/</a>.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2012/01/14/humanstxt-antirobotstxt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node.js 0.6 Released</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/11/07/nodejs-06-released/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/11/07/nodejs-06-released/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 10:00:32 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=457</guid>
		<description><![CDATA[The Node.js team has released version 0.6. Although much of the core was re-written, the most noteworthy change has to be the support for native Windows installation. Whereas previously it was possible to run node.js on Windows using Cygwin, the native compilation means its performance will be comparable to Linux equivalents. Other important improvements include [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The Node.js team has released version 0.6. Although much of the core was re-written, the most noteworthy change has to be the support for native Windows installation. Whereas previously it was possible to run node.js on Windows using Cygwin, the native compilation means its performance will be comparable to Linux equivalents.</p>
<p>Other important improvements include upgrading of the V8 engine and multi-process load balancing. Much more information can be found on the <a href="http://blog.nodejs.org/2011/11/05/node-v0-6-0/">node blog</a>.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/11/07/nodejs-06-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Development Environments</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/11/04/multiple-development-environments/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/11/04/multiple-development-environments/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 01:19:42 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=454</guid>
		<description><![CDATA[Hopefully when you do web work, you&#8217;re not developing code on the same server your users are accessing. Most organizations have at least some kind of separation for their development and production code, but it&#8217;s possible to go far further. Separating environments allows you to achieve multiple threads of continuous integration for all kinds of [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/25/ensure-sla-multiple-web-role-instances-windows-azure/' rel='bookmark' title='Ensure SLA with Multiple Web Role Instances on Windows Azure'>Ensure SLA with Multiple Web Role Instances on Windows Azure</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/22/rely-continuous-integration/' rel='bookmark' title='Rely on Continuous Integration'>Rely on Continuous Integration</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/' rel='bookmark' title='Accessing Configuration Parameters using Play Framework&#8217;s Template Engine'>Accessing Configuration Parameters using Play Framework&#8217;s Template Engine</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Hopefully when you do web work, you&#8217;re not developing code on the same server your users are accessing. Most organizations have at least some kind of separation for their development and production code, but it&#8217;s possible to go far further. Separating environments allows you to achieve <a href="http://www.alwaysgetbetter.com/blog/2011/04/22/rely-continuous-integration/">multiple threads of continuous integration</a> for all kinds of cool.</p>
<p>These normally break down as follows:</p>
<p><strong>Development</strong><br />
Working code copy. Changes made by developers are deployed here so integration and features can be tested. This environment is rapidly updated and contains the most recent version of the application.</p>
<p><strong>Quality Assurance (QA)</strong><br />
Not all companies will have this. Environment for quality assurance; this provides a less frequently changed version of the application which testers can perform checks against. This allows reporting on a common revision so developers know whether particular issues found by testers has already been corrected in the development code.</p>
<p><strong>Staging/Release Candidate</strong><br />
This is the release candidate, and this environment is normally a mirror of the production environment. The staging area contains the &#8220;next&#8221; version of the application and is used for final stress testing and client/manager approvals before going live.</p>
<p><strong>Production</strong><br />
This is the currently released version of the application, accessible to the client/end users. This version preferably does not change except for during scheduled releases. <a href="http://www.alwaysgetbetter.com/blog/2011/03/03/displaying-productiononly-markup-rails/">There may be differences in the production environment</a> but generally it should be the same as the staging environment.</p>
<p>Having separation between the different environments is not tricky, but managing your data environment can be. There are, of course, <a href="http://www.alwaysgetbetter.com/blog/2011/04/20/database-migrations/">all kinds of ways to solve the problem</a>.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/25/ensure-sla-multiple-web-role-instances-windows-azure/' rel='bookmark' title='Ensure SLA with Multiple Web Role Instances on Windows Azure'>Ensure SLA with Multiple Web Role Instances on Windows Azure</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/22/rely-continuous-integration/' rel='bookmark' title='Rely on Continuous Integration'>Rely on Continuous Integration</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/' rel='bookmark' title='Accessing Configuration Parameters using Play Framework&#8217;s Template Engine'>Accessing Configuration Parameters using Play Framework&#8217;s Template Engine</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/11/04/multiple-development-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Configuration Parameters using Play Framework&#8217;s Template Engine</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/#comments</comments>
		<pubDate>Tue, 10 May 2011 02:20:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[play framework]]></category>
		<category><![CDATA[templating]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=430</guid>
		<description><![CDATA[Suppose we are building a Facebook application and have a variable called fb.appId containing our Application&#8217;s ID. We want to use that to initialize an FBJS call, but obviously don&#8217;t want to hard-code it into our page&#8217;s template. Using the template engine in Play! framework, we can make direct calls to the underlying Java framework [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/11/play-framework-saves-world/' rel='bookmark' title='How Play Framework Saves the World'>How Play Framework Saves the World</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/20/database-migrations/' rel='bookmark' title='Database Migrations'>Database Migrations</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Suppose we are building a Facebook application and have a variable called <strong>fb.appId</strong> containing our Application&#8217;s ID. We want to use that to initialize an FBJS call, but obviously don&#8217;t want to hard-code it into our page&#8217;s template.</p>
<p>Using the template engine in Play! framework, we can make direct calls to the underlying Java framework as long as we use the full namespace path. Our Facebook Application Id is accessible like this:</p>
<p><code><br />
${play.Play.configuration.get("fb.appId")}<br />
</code></p>
<p>If we&#8217;re making a lot of configuration calls, we can simplify our lives by aliasing the namespace path:</p>
<p><code><br />
%{<br />
cf =  play.Play.configuration<br />
}%<br />
${cf.get("fb.appId")}<br />
</code></p>
<p><strong>Conditional Statements</strong><br />
Let&#8217;s go a step further. Suppose we have Google Analytics and only want the JavaScript to run when our site has been deployed to production (I covered a similar technique earlier this year <a href="http://www.alwaysgetbetter.com/blog/2011/03/03/displaying-productiononly-markup-rails/">using Ruby on Rails</a>).</p>
<p><code><br />
#{if play.Play.configuration.get("application.mode") == 'PROD'}<br />
GOOGLE ANALYTICS CODE - WILL ONLY DISPLAY IN PRODUCTION<br />
#{/if}<br />
</code></p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/11/play-framework-saves-world/' rel='bookmark' title='How Play Framework Saves the World'>How Play Framework Saves the World</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/20/database-migrations/' rel='bookmark' title='Database Migrations'>Database Migrations</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking Down Website Speed Problems</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 02:43:10 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=401</guid>
		<description><![CDATA[photo credit: Eric Kilby Why is my website loading so slowly?!? There are a few common culprits behind website speed issues. When diagnosing problems, the best bet is to start at the worst performers and move up. Some suggestions, in order from slowest to fastest, are: 1. Internet Traffic If your web page is downloading [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/12/20/fastcgi-nginx-performance-vm/' rel='bookmark' title='Using FastCGI with Nginx for Performance on a VM'>Using FastCGI with Nginx for Performance on a VM</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/21/accelerate-site-content-delivery-network/' rel='bookmark' title='Accelerate Your Site with a Content Delivery Network'>Accelerate Your Site with a Content Delivery Network</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class=alignright><a href="http://www.flickr.com/photos/8749778@N06/5611527033/" title="Tortoise" target="_blank"><img src="http://farm6.static.flickr.com/5149/5611527033_6c1e37ccdc_m.jpg" alt="Tortoise" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" target="_blank"><img src="http://www.alwaysgetbetter.com/blog/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/8749778@N06/5611527033/" title="Eric Kilby" target="_blank">Eric Kilby</a></small></div>
<p>Why is my website loading so slowly?!?</p>
<p>There are a few common culprits behind website speed issues. When diagnosing problems, the best bet is to start at the worst performers and move up. Some suggestions, in order from slowest to fastest, are:</p>
<p><strong>1. Internet Traffic</strong><br />
If your web page is downloading anything over the internet during each page request, stop right now. This is the most expensive operation you can perform. Example: Downloading a photo from Flickr and loading it into memory in order to determine its width and height dimensions.</p>
<p><strong>2. Network Traffic</strong><br />
Local network traffic is generally very fast, but still involves transmitting information outside your computer. In some cases, such as <a href="http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/">web clusters with a shared session cache</a>, the network performance cost is worth it for the overall application.</p>
<p><strong>3. Database</strong><br />
Databases are fast, particularly when the data you need is already stored in a memory cache &#8211; which you generally can&#8217;t control. When paired with a <a href="http://www.alwaysgetbetter.com/blog/2011/04/18/memcache-mysql/">key-value memory store like memcache</a>, the majority of your database calls can come straight from memory.</p>
<p><strong>4. Disk I/O</strong><br />
Even with the incredible access times found in today&#8217;s hard drives, reading and writing from the disk is an expensive operation (and why databases lose points, except for their memory caching abilities). Sometimes reading from disk is the better choice &#8211; YMMV.</p>
<p><strong>5. Script Caching</strong><br />
Implement <a href="http://www.alwaysgetbetter.com/blog/2010/11/20/php-accelerator-speed-website/">a tool like xcache</a> (PHP). This will keep your code in binary bytecode format which is much faster to execute since it doesn&#8217;t have to be re-processed by the web server.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/12/20/fastcgi-nginx-performance-vm/' rel='bookmark' title='Using FastCGI with Nginx for Performance on a VM'>Using FastCGI with Nginx for Performance on a VM</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/21/accelerate-site-content-delivery-network/' rel='bookmark' title='Accelerate Your Site with a Content Delivery Network'>Accelerate Your Site with a Content Delivery Network</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How Play Framework Saves the World</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/04/11/play-framework-saves-world/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/04/11/play-framework-saves-world/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 12:46:05 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[play framework]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=367</guid>
		<description><![CDATA[Play framework must be the best-kept secret in the Java world. If you haven&#8217;t had a chance to see their totally awesome demonstration video where they build a full app before your eyes in a matter of minutes, go &#8211; go now. Then come back. Why do I like this framework so much? Put simply, [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/' rel='bookmark' title='Accessing Configuration Parameters using Play Framework&#8217;s Template Engine'>Accessing Configuration Parameters using Play Framework&#8217;s Template Engine</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/22/rely-continuous-integration/' rel='bookmark' title='Rely on Continuous Integration'>Rely on Continuous Integration</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Play framework must be the best-kept secret in the Java world. If you haven&#8217;t had a chance to see their totally awesome demonstration video where they build a full app before your eyes in a matter of minutes, <a href="http://www.playframework.org/">go &#8211; go now</a>. Then come back.</p>
<p>Why do I like this framework so much? Put simply, it is an elegant solution for nearly every problem I&#8217;ve ever run into in developing websites, both single-server and multi-server applications. Don&#8217;t take my word for it, see for yourself.</p>
<p><strong>The Goodness of Java</strong><br />
To my mind, Java has the edge over more common scripting languages (like PHP) because it is compiled (fast) and statically typed (reliable). In the past, using compiled languages on the web was only possible if you were using ASP.NET or willing to put up with the hassles of existing Java frameworks and servers.</p>
<p>Play&#8217;s first innovation comes from wrapping the Java runtime inside a Python web server; using a Play application is as easy as running a command line script and connecting with your web browser. Play&#8217;s second innovation is its just-in-time compilation and display of error messages; if you make a mistake you will know in the amount of time it takes to hit refresh on your web browser.</p>
<p>Since it IS java, programmers can use libraries they have built for other applications or sourced from other vendors and plug directly into their code. This is one of the advantages Microsoft has had going for it and it is good to see it implemented so nicely in the open source world.</p>
<p><strong>The Ease of Rails</strong><br />
Love it or hate it, Ruby on Rails has had an affect on the entire web world and its reach is definitely felt in the Play framework. Everything from the routing to JPA integration has that minimal-configuration design that is so prevalent in the Ruby world. Play has the edge though, due to Java annotations and the extra control you get as a developer.</p>
<p><strong>Baked-in Unit Testing</strong><br />
Admittedly this is the first thing that drew me to the Play framework. Unit testing has to be one of the most important aspects of good programming; in fact, if your code is <em>not</em> covered by unit tests, I argue it is incomplete. Play has terrific support for unit testing, functional testing and selenium-based web testing. In version 1.1, Play added a headless web testing mode, paving the way to run framework applications in the context of an automated build environment &#8211; smart move!</p>
<p>Although awkward at first, using YAML files for database fixtures makes a lot of sense. Managing database access in unit tests has always been a challenge but thanks to the in-memory database server and fixture files Play offers us database <em>integration testing</em> &#8211; giving us the fresh-start benefits of mock frameworks along with the soundness of mind that comes from knowing you are testing the real database.</p>
<p><strong>Share Nothing Architecture</strong><br />
Call it laziness, call it human error. At some point in the development cycle, the session always seems to end up carrying user data around. Even with data-sharing applications like memcached, that style of development does not scale well. With Play, sessions are stored in user cookies and consist of an encrypted key. The idea is the application takes care of loading any additional information it needs from this seed information, so the web cluster can be expanded to hundreds of nodes or reduced to a single server with no performance penalties on the other servers. Each Play instance operates as if it is the only one in existence, making it far easier to support complex site architectures.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/05/09/accessing-configuration-parameters-play-frameworks-template-engine/' rel='bookmark' title='Accessing Configuration Parameters using Play Framework&#8217;s Template Engine'>Accessing Configuration Parameters using Play Framework&#8217;s Template Engine</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/22/rely-continuous-integration/' rel='bookmark' title='Rely on Continuous Integration'>Rely on Continuous Integration</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/04/11/play-framework-saves-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Memcache as MySQL&#8217;s Hero</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/04/10/memcache-mysqls-hero/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/04/10/memcache-mysqls-hero/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 10:31:18 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=374</guid>
		<description><![CDATA[It&#8217;s hard not to love memcache. As soon as you manage a web site that has more than a few concurrent visitors, the performance benefit of caching becomes immediately obvious. MySQL is a fast database and can outperform a lot of its competitors, but no matter how quickly it can pull results it can never [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/18/memcache-mysql/' rel='bookmark' title='Using Memcache with MySQL'>Using Memcache with MySQL</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/' rel='bookmark' title='Memcached as Session Handler'>Memcached as Session Handler</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/' rel='bookmark' title='Tracking Down Website Speed Problems'>Tracking Down Website Speed Problems</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s hard not to love memcache. As soon as you manage a web site that has more than a few concurrent visitors, the performance benefit of caching becomes immediately obvious. MySQL is a fast database and can outperform a lot of its competitors, but no matter how quickly it can pull results it can never outperform the retrieval speed of the server&#8217;s RAM.</p>
<p>The basic premise is: instead of pulling a model out of the database, see if it has already been loaded into memory by checking a key-value diction (for example: User5677). If the user has not been read from the database yet, the key-value store will be empty and we can fetch the record. Next time we need that data we check the key-value again and avoid querying the database.</p>
<p>This really saves us whenever we have data that changes infrequently. Take, for example, an ecommerce website: since the products and categories on the site will change very rarely, it makes a lot of sense to store them in memory for fast recovery. Even more volatile information (like user data) can be stored in the cache, as long as the application knows to empty that cache key when the data gets changed.</p>
<p>Memcache is an ideal tool for managing these kinds of caches, and provides a lot of flexibility for growth.</p>
<p><strong>History Lesson</strong><br />
Earlier this week <a href="http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/">I promised to go deeper into memcache&#8217;s origins</a>. Memcache was originally developed at Danga as a way to reduce the database load and improve the speed of LiveJournal.</p>
<p>Rather than developing a standalone server application, Danga&#8217;s engineers designed memcache to sit on lower-end hardware and on web servers where it would use a small amount of the overal memory. Memcache instances don&#8217;t talk to each other: the client machines are aware of all the memcache instances and attempt to write their information evenly to each. This allows memcache to scale almost limitlessly without adding significant overhead to the caching process.</p>
<p><strong>When to Use</strong><br />
Quite simply: if you&#8217;re building an application for the LAMP stack, build in memcache support. When treated as a necessary component from the beginning, caching support adds almost zero overhead to development; however <a href="http://www.alwaysgetbetter.com/blog/2011/04/18/memcache-mysql/">it will always pay off</a> as soon as real world traffic is coming to your site.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/18/memcache-mysql/' rel='bookmark' title='Using Memcache with MySQL'>Using Memcache with MySQL</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/' rel='bookmark' title='Memcached as Session Handler'>Memcached as Session Handler</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/' rel='bookmark' title='Tracking Down Website Speed Problems'>Tracking Down Website Speed Problems</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/04/10/memcache-mysqls-hero/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Memcached as Session Handler</title>
		<link>http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 12:24:26 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=369</guid>
		<description><![CDATA[By default PHP loads and saves sessions to disk. Disk storage has a few problems: 1. Slow IO: Reading from disk is one of the most expensive operations an application can perform, aside from reading across a network. 2. Scale: If we add a second server, neither machine will be aware of sessions on the [...]
Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2012/01/30/setting-wordpress-nginx-fastcgi/' rel='bookmark' title='Setting up WordPress with nginx and FastCGI'>Setting up WordPress with nginx and FastCGI</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/10/memcache-mysqls-hero/' rel='bookmark' title='Memcache as MySQL&#8217;s Hero'>Memcache as MySQL&#8217;s Hero</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/' rel='bookmark' title='Tracking Down Website Speed Problems'>Tracking Down Website Speed Problems</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>By default PHP loads and saves sessions to disk. Disk storage has a few problems:</p>
<p>1. Slow IO: Reading from disk is one of the most expensive operations an application can perform, aside from reading across a network.<br />
2. Scale: If we add a second server, neither machine will be aware of sessions on the other.</p>
<p><strong>Enter Memcached</strong><br />
I <a href="http://www.alwaysgetbetter.com/blog/2010/11/20/php-accelerator-speed-website/">hinted at Memcached</a> before as a content cache that can improve application performance by preventing trips to the database. Memcached is also perfect for storing session data, and has been supported in PHP for quite some time.</p>
<p>Why use memcached rather than file-based sessions? Memcache stores all of its data using key-value pairs in RAM &#8211; it does not ever hit the hard drive, which makes it F-A-S-T. In multi-server setups, PHP can grab a persistent connection to the memcache server and share all sessions between multiple nodes.</p>
<p><strong>Installation</strong><br />
Before beginning, you&#8217;ll need to have the Memcached server running. I won&#8217;t get into the details for building and installing the program as it is different in each environment, but there are good guides <a href="http://memcached.org/">on the memcached site</a>. On Ubuntu it&#8217;s as easy as <strong>aptitude install memcached</strong>. Most package managers have a memcached installation available.</p>
<p>Installing memcache for PHP is hard (not!). Here&#8217;s how you do it:</p>
<p><code><br />
pecl install memcache<br />
</code></p>
<p>Careful, it&#8217;s <strong>memcache</strong>, without the &#8216;d&#8217; at the end. Why is this the case? It&#8217;s a long story &#8211; let&#8217;s save the history lesson for another day.</p>
<p>When prompted to install session handling, answer &#8216;Yes&#8217;.</p>
<p><strong>Usage</strong><br />
Using memcache for sessions is as easy as changing the session handler settings in PHP.ini:<br />
session.save_handler = memcache<br />
session.save_path = &#8220;tcp://127.0.0.1:11211&#8243; (assuming memcached is set up to use default port)</p>
<p>Now restart apache (or nginx, or whatever) and watch as your sessions are turbo-charged.</p>
<p>Related posts:<ol>
<li><a href='http://www.alwaysgetbetter.com/blog/2012/01/30/setting-wordpress-nginx-fastcgi/' rel='bookmark' title='Setting up WordPress with nginx and FastCGI'>Setting up WordPress with nginx and FastCGI</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/10/memcache-mysqls-hero/' rel='bookmark' title='Memcache as MySQL&#8217;s Hero'>Memcache as MySQL&#8217;s Hero</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2011/04/19/tracking-website-speed-problems/' rel='bookmark' title='Tracking Down Website Speed Problems'>Tracking Down Website Speed Problems</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2011/04/09/memcached-session-handler/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: alwaysgetbetter.com @ 2012-02-05 03:49:46 -->
