<?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>bitblogr.com &#187; PC</title>
	<atom:link href="http://www.bitblogr.com/category/pc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitblogr.com</link>
	<description>design, tutorials, inspiration, creativity</description>
	<lastBuildDate>Sat, 05 Jun 2010 17:20:23 +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>VPS, CDN and advanced server techniques: 2</title>
		<link>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-2/</link>
		<comments>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-2/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 03:18:10 +0000</pubDate>
		<dc:creator>Opeyemi Obembe</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[PC]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[mod_deflate]]></category>
		<category><![CDATA[mod_expire]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://www.bitblogr.com/?p=104</guid>
		<description><![CDATA[In this piece, we will focus more on scalability &#8211; which I simply define as the ability of a server to efficiently adapt to more load. It is more complex as that sounds and to know more, you can check out scalability @ wikipedia. As a server administrator, optimizing your site and server for scalability [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;margin-right:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fvps-cdn-and-advanced-server-techniques-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fvps-cdn-and-advanced-server-techniques-2%2F&amp;source=bitblogr&amp;style=normal&amp;service_api=R_2574ec2cdf93a9dc24a80c02f8d96a25&amp;hashtags=caching,mod_deflate,mod_expire,scalability" height="61" width="50" /><br />
			</a>
		</div>
<p>In this piece, we will focus more on scalability &#8211; which I simply define as the ability of a server to efficiently adapt to more load. It is more complex as that sounds and to know more, you can check out <a href="http://en.wikipedia.org/wiki/Scalability">scalability @ wikipedia</a>.<span id="more-104"></span></p>
<p>As a server administrator, optimizing your site and server for scalability is a task you will face occasionally, if nor more often than that. At first, with just a couple of site visitors and members, all may seem well. But as users and visits grow, you will start finding the need.</p>
<p>There are two types of scalability actually &#8211; scaling out which is about adding more system nodes, like buying more servers and scaling up which is about effectively maximizing the potential of what you have on ground already. Scaling up is cheaper than scaling out, in fact, in some instance doesn&#8217;t even cost any dime &#8211; and this is what we are looking at here. Besides, if you start with scaling out, without scaling up, there is the every posiblity you will continue scaling out as just a little wrong thing with your app or server configuration may be causing excessive load and weighing down the server &#8211; a problem scaling out won&#8217;t solve. Scaling up on the other hand will let you detect such. After properly scaling up, you can then scale out.</p>
<p>So the big question &#8211; how do you scale up? And to that is a lot of answers. Yah, there are many ways to optimize your app/server &#8211; every single way you think can save the server memory and number of processes. Some of this include caching, code optimization, profiling and even good configuration of your server and database engine. Caching alone as a big parent, has a lot of children &#8211; setting proxy servers, database caching to mention just two.</p>
<p>In the <a href="http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-part-1/">last piece</a> I mentioned CDN (Content Delivery Network), and even this is a great scalability technique. I guess I do not need to recap the advantages here but having your static files served from a different server entirely saves your deployment server (your app server) more memory and processes, leaving it to take care of more important files (dynamic content for example). Mind you, your static files include your CSS, javascript, images, flash and co. At ngbot (<a href="http://mobile.ngbot.com">mobile</a>, <a href="http://ads.ngbot.com">ads</a>, <a href="http://answers.ngbot.com">answers</a>) though, we don&#8217;t store our CSS, JS and all images in our CDN but there is a simple caching technique we use to reduce the effect of serving it from the deployment server, which I will talk about in a gifi.</p>
<p>Continuing from where I stopped on CDN in the last piece, how do you get content in and out of the CDN? It is simple &#8211; APIs. CDNs provide APIs you can interface directly from your application. Most providers even offer code libraries in different programming language to help out. <a href="http://rackspace.com">Rackspace</a> (which we use) for example has a great php class implementing the api. It is simple. You simply authenticate with some already provided details and you are good to go.</p>
<p>Below is an example code excerpt</p>
<pre>include 'cloud/cloudfiles.php';
# Authenticate. CLOUDUSER and CLOUDAPI predefined with define()
$auth = new CF_Authentication(CLOUDUSER, CLOUDAPI);
$auth-&gt;ssl_use_cabundle();
$auth-&gt;authenticate();
# Get Container obj
$conn = new CF_Connection($auth);
# Get container named 'static'. NB: container = folder
$container = $conn-&gt;get_container('static');
# Public?
if(!$container-&gt;is_public())
{
	# make public and cache content for a day
	echo $container-&gt;make_public(86400).' : '.$v.'
';
}</pre>
<p>Note the cache part where you can set the content to be cached on the user&#8217;s system for a number of seconds (8400 in the example = a day). By such, the content is stored on the user&#8217;s system for the specified duration and won&#8217;t be requested again from the CDN during that time. This consequently saves your CDN traffic and saves you money.</p>
<p>Ok, CDN settled, lets see other ways to serve static content from your server, as we do for our css, js and some of our image files. To start with this is specific to the Apache web server. There are ways to do it with other servers though.</p>
<p>The technique is based on caching. If you serve just static pages in your site (which I doubt) you can actually set your server, Apache in this case, to cache the site content for a specified duration. For people like me who have issues with caching all content and setting up proxy servers however, there are ways to cache some specific content by content-type. It is called <strong>Mod Expire</strong> in Apache and you can read more about it from the <a href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html">Apache docs</a></p>
<p>In general, here is what it looks like (in htaccess).</p>
<pre>ExpiresActive on
# Images and flash
ExpiresByType image/png "access plus 2 month"
ExpiresByType image/gif "access plus 2 month"
ExpiresByType image/jpeg "access plus 2 month"
ExpiresByType application/x-shockwave-flash "access plus 2 month"
# css may change a bit sometimes, so dont cache too long
ExpiresByType text/css "access plus 5 days"
# special MIME type for icons in case not set yet
AddType image/vnd.microsoft.icon .ico
# now we have icon MIME type, we can use it
# But my favicon doesn't change much, so say 3 mnths
ExpiresByType image/vnd.microsoft.icon "access plus 3 months"
ExpiresByType image/x-icon "access plus 3 months"
# JS? A month will do
ExpiresByType application/x-javascript "access plus 1 month"</pre>
<p>I&#8217;d love to go on and on, but again, let&#8217;s leave it at here. Don&#8217;t forget however that scaling is about sniffing and optimizing every little thing that will weigh down your server, starting from checking your server (e.g Apache) and database (e.g MySQL) configuration. If you are using a framework, especially for your server side, you should be sure you set things up properly. Even at that, <a href="http://carsonified.com/blog/dev/databases/speed-up-your-web-app-by-1000-with-1-line-of-sql/">be sensitive to page load speeds</a> and memory consumption. You can check out your server memory consumption and other vital details with the Linux command <strong>free</strong> from shell. If you are not much of the shell/console type, there is <a href="http://phpsysinfo.sourceforge.net/">phpSysinfo</a> which displays vital system info in a web page format.</p>
<p>And finally, talking page load speed, output compression is a life saver. By compressing content sent to the http client (say browser) from the server, you can drastically reduce your page load time. <a href="http://devedgelabs.com">We</a> use <a href="http://prototypejs.org">prototype</a> as our parent js framework wich is quite heavy &#8211; around 74KB minified. Think of how long t will take this alone to load not to talk of other scripts. However, by output compression, the file is reduced to just around 21KB.</p>
<p>Output compression is a very easy thing. Note though, it is an extra work for the server so be sure of the trade off. In Apache (2.x), it is as smple as something like this: (<a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html">Read more here</a>)</p>
<pre># Compress javascript and css files
AddOutputFilterByType DEFLATE application/x-javascript text/css</pre>
<p>Compressing a PHP file on the other hand is as simple as adding the line below just before any output buffering (any content is displayed/echoed)</p>
<pre>ob_start("ob_gzhandler");</pre>
<p>Ok, that&#8217;s all for now. Hope you&#8217;ve been able to learn a thing or two. Catch you later ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VPS, CDN and advanced server techniques: Part 1</title>
		<link>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-part-1/</link>
		<comments>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-part-1/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 16:20:19 +0000</pubDate>
		<dc:creator>Opeyemi Obembe</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[PC]]></category>
		<category><![CDATA[Amazon s3]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[ngBot]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.bitblogr.com/?p=63</guid>
		<description><![CDATA[VPS stands for Virtual Private Server, a type of hosting technology that gives you advanced features and server privilege as against a shared hosting. Its use in this article however refers generally to any type of hosting that allows you root access to your server &#8211; dedicated servers, VPS itself and Cloud servers as examples. [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;margin-right:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fvps-cdn-and-advanced-server-techniques-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fvps-cdn-and-advanced-server-techniques-part-1%2F&amp;source=bitblogr&amp;style=normal&amp;service_api=R_2574ec2cdf93a9dc24a80c02f8d96a25&amp;hashtags=Amazon+s3,Cloud,Facebook,Microsoft,ngBot,Servers,Twitter" height="61" width="50" /><br />
			</a>
		</div>
<p>VPS stands for Virtual Private Server, a type of hosting technology that gives you advanced features and server privilege as against a shared hosting. Its use in this article however refers generally to any type of hosting that allows you root access to your server &#8211; dedicated servers, VPS itself and Cloud servers as examples. I&#8217;d like to explain each in here but that is beyond the scope of this piece. Maybe some other time ;)<span id="more-63"></span></p>
<p>If you are proposing a startup or a big site &#8211; big in the term of eventual traffic and functionalities, then shared hosting is not the option for you. Really, I&#8217;m talking from experience. Go VPS. There are a lot of reasons for this but here are 3 core ones:</p>
<ol>
<li>With VPS, you have the ability to configure your server (app and OS) to your taste, removing and adding stuffs the way you want &#8211; and this is a very important thing.</li>
<li>On shared hosting, there is a limit to how &#8216;big&#8217; you can grow. Let me give you a live example here. We started <a href="http://ngbot.com">ngBot</a> on a shared hosting and everything was going fine till we added <a href="http://mobile.ngbot.com">ngBot mobile</a>. The whole idea was a play thing &#8211; just a place to share mobile items we get here and there and then meet other mobile geeks, but then it started getting more than that. In a while, we grew close to over 4000 members and was clocking around 30k monthly page views. And that was when the axe came from our shared hosting company. They disabled some of our scripts and advised us to go VPS or dedicated. The blow came so sudden and we had to take off the site for around a month till we found and nested on a suitable VPS host (cloud server actually). Needless to say, the one month the site was out cost us a lot of hits, members and Search Engine ranking.</li>
<li>On VPs you do not share resources with anyone like on shared hosting. Shared hostings are like face-to-face apartments where you share a lot of things together and you easily get disturbed by one another. If your neighbour on a shared hosting is a spammer for example, this may affect how mails from your site are delivered as well.</li>
</ol>
<p>One thing to note about VPS however is that they are costlier than shared hosting. Another is that they require a little advanced skill to setup especially if you go the vanilla blank server way and you are doing the OS, server and tools setup yourself. This is a really big one and I advice you go for the preinstalled/configured option if you are not up to it. The already setup ones comes with an admin app (CPanel mostly) and looks pretty much like your shared platform. With the blank ones, all you have is your ugly shell console to do everything you want. And if this is your way, you will find <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">putty</a> very useful.</p>
<p>Needless to say, a good knowledge of your VPS OS is a very important virtue. As a server admin, you should be very familiar with the OS directory structures, installing/removing packages and dependencies (good knowledge of building and compiling important here as well as build tools like make and gcc), editing config files with editors like vi and nano (as you know, this is very common to Linux) among others.</p>
<p>Another very important thing you should know about is DNS setup (A, MX and CNAME especially) and how to configure your A records with your server especially if you want to setup multiple domains on the server. A good into article on DNS is available here: <a href="http://carsonified.com/blog/web-apps/get-started-with-dns/" target="_blank">http://carsonified.com/blog/web-apps/get-started-with-dns/</a></p>
<p>Now, space and bandwidth is one luxury you don&#8217;t have on VPS. It is easy to find shared hosts promising you unlimited space/bandwidth but if you hear that on VPS, run away! The little one we run on at the moment offers just 20GB space as against our former shared hosting space of 1500GB! As a workaround to space and bandwidth issues on VPS, enter CDN (Content Delivery Network)!</p>
<p>CDN serve as storage backbone. Picture the scenario: storing our mobile stuffs (videos, apps, games, pictures) in our little 20GB space will leave us with little space for more upcoming ones. What if we have it stored in a different place &#8211; on a different server designed exclusively for data storage and transfer and not for core server functionalities like script compiling/serving etc? And that is what CDN is all about. CDNs are designed as storage servers for static data. But they don&#8217;t just store. The way they are designed is such that they distribute stored content between different other servers around the world and serve content from the server closest to the request source, making content serving fast. Not only that, CDNs also enable content caching.</p>
<p>You come across CDN in use every minute you surf the web &#8211; <a href="http://facebook.com">Facebook</a> (for storing/serving images/videos), <a href="http://twitter.com/">twitter</a> (for storing profile images), <a href="http://mobile.ngbot.com">ngBot mobile</a> (serving mobile download files) ;) and a lot more. Another good thing about CDN is that you don&#8217;t have a specific size you are limited to. You can consume as much as you want to as you pay per GB of space you use. Much more, it is cheap &#8211; very cheap. On the one we run on (<a href="http://www.rackspacecloud.com/cloud_hosting_products/file">Rackspace cloud files</a>), 1GB costs around $0.15. One of the most popular public CDN is <a href="https://s3.amazonaws.com/">Amazon S3</a>. They have been around for quite a while and a lot of sites use it, <a href="http://twitter.com/">twitter</a> as one. Another is <a href="www.rackspacecloud.com/cloud_hosting_products/file">Rackspace cloud files</a> (which we use) and the new <a href="http://www.microsoft.com/azure/">Microsoft Azure</a>.</p>
<p>So how exactly do you transfer content in and out of a CDN? What other ways are static content served? Why is it necessary? Where does caching comes into this? Join me in the next piece ;)</p>
<blockquote><p>Post update: The Second part of this article has been published <a href="http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-2/">here</a>.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.bitblogr.com/how-to/vps-cdn-and-advanced-server-techniques-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
