<?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>Garrett Bluma &#187; Linux</title>
	<atom:link href="http://garrettbluma.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://garrettbluma.com</link>
	<description>Web Developer</description>
	<lastBuildDate>Mon, 21 May 2012 00:00:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Monitor Your Web Services from Bash</title>
		<link>http://garrettbluma.com/2011/09/22/monitor-your-services-from-bash/</link>
		<comments>http://garrettbluma.com/2011/09/22/monitor-your-services-from-bash/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 22:51:06 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=898</guid>
		<description><![CDATA[A lengthy explanation of a one liner I use to detect when a service is not responding.  Bash-fu included.]]></description>
			<content:encoded><![CDATA[<p>I have a web service that is continually causing me grief. It always fails at inconvenient times and, really, I ought to at least know <em>when</em> it fails.  For other things I usually just use a service like <a href="http://www.uptimerobot.com">Uptime Robot</a>,  but for this one I have different requirements:</p>
<ul>
<li>The service I want to monitor has a firewall that only allows access from a single host.</li>
<li>And on that host, I didn't have permission to install new software. (It's temporary anyway)</li>
<li>But, I <em>do</em> have access to SSH & Bash.</li>
</ul>
<p>Therefore, here is my solution!</p>
<p>The only dependencies that are needed are common commands like <tt>curl</tt>, <tt>watch</tt>, <tt>mail</tt>, and the script I'll show you about.</p>
<p><strong>1. Download and install <a href="http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3">this timeout script</a></strong></p>
<pre>curl -L http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3 > timeout3
chmod +x ./timeout3</pre>
<p><strong>2. Craft your one-liner.</strong></p>
<p>Actual code (You can call this in your terminal or save it to a file):</p>
<pre>watch -n 300 \
  ./timeout3 -t 15 \
    curl -q -X GET http://url \
      || { echo "Cannot access PAGE_NAME. Waited 15 seconds on `date`" \
           | mail -s "Web Site Not Responding" \
             garrett.bluma@gmail.com; }</pre>
<p><strong>3. Done!</strong></p>
<p>Oh, what's that?  One-liners are complex and frustrating? I totally agree -- let's break it down!
<pre>watch -n 300 \</pre>
<p><tt>Watch</tt> is a program for monitoring command line applications output different information between calls.  It calls the same command on a given interval and displays the results. This is handy for watching processes, but <em>here</em> we are using it solely for it's ability to kick off an application at some time interval.  For a more elegant solution feel free to remove this and <em>actually</em> cron the thing.</p>
<pre>  ./timeout3 -t 15 \</pre>
<p><tt>timeout3</tt> is the script we downloaded earlier.  Passing in <tt>-t 15</tt> means that want the command (that is about to be defined) will be allowed to run for 15 seconds -- but once it reaches that limit, <tt>timeout3</tt> will kill it.</p>
<pre>    curl -q -X GET http://url \</pre>
<p>With <tt>curl</tt> we are simply sending a <tt>GET</tt> request to a server (over HTTP).  If we receive a response, we do nothing and fall back to the <tt>watch</tt> command and wait until the next iteration.  However, if this request takes too long however, the process will be interrupted by <tt>timeout3</tt> and exit with an error -- this signals our script to send an email.</p>
<pre>      || { echo "Cannot access PAGE_NAME. Waited 15 seconds on `date`" \
           | mail -s "Web Site Not Responding" \
             garrett.bluma@gmail.com; }</pre>
<p>If the timeout process triggers an error (which we assume means the request took more than 15 seconds), then we send an email. We do this via the <tt>mail</tt> command, which we assign some options to and pass data in via stdin. You could also read it as follows;</p>
<pre>      || { echo "message" \
           | mail -s "title" \
             "recipient"; }</pre>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2011/09/22/monitor-your-services-from-bash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx / Memcached Direct Page Caching</title>
		<link>http://garrettbluma.com/2010/08/16/nginx-memcached-direct-page-caching/</link>
		<comments>http://garrettbluma.com/2010/08/16/nginx-memcached-direct-page-caching/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 03:57:55 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Joomla]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=313</guid>
		<description><![CDATA[There are a few different approaches to caching; data caching, fragment caching, and full-page caching. But first, here's the typical model of a web application. User requests a page, and it works through the web server, through several layers, and finally to the database. Data caching takes the place of a database call and can be effective if there are a lot of database requests.  You would typically want to do this if you know that a piece of data is very common and unlikely to change. This saves time on one step of the process. Fragment caching is a [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few different approaches to caching; data caching, fragment caching, and full-page caching. But first, here's the typical model of a web application. User requests a page, and it works through the web server, through several layers, and finally to the database.</p>
<p><img class="aligncenter size-full wp-image-331" title="Typical webapp flow chart" src="http://garrettbluma.com/wp-content/uploads/2010/08/server-caching1.png" alt="" width="602" height="101" /></p>
<p><strong>Data caching </strong>takes the place of a database call and can be effective if there are a lot of database requests.  You would typically want to do this if you know that a piece of data is very common and unlikely to change. This saves time on one step of the process.</p>
<p><img class="aligncenter size-full wp-image-332" title="Web app flowchart 2" src="http://garrettbluma.com/wp-content/uploads/2010/08/server-caching2.png" alt="" width="602" height="102" /></p>
<p><strong>Fragment caching</strong> is a little more complicated.  Instead of caching the data that you would input into another process to build a layout (for example), you just cache that layout directly.  This is great for a "featured news" section that changes only once a day and is viewed often.  It would be silly to cache that data and calculate the layout for every view, so instead we would just cache the layout itself. Saves a bunch of work.</p>
<p>Moving on, we have <strong>page caching</strong>.  Which is the topic which I really want to go over. I have a warning though, page caching is dumb. REAL dumb. But, in that magnificent dumness is speed. Page caching is the most efficient of the three. It takes the gains we get from fragment caching and goes even further. Think about it, we hardly need to do anything—and therein lies the problem, we lose ALL dynamic ability of the page. This is not an issue for a lot of sites; news pages, catalogs, and blogs can all benefit from this method of caching.</p>
<p style="text-align: center;"><img class="size-full wp-image-333  aligncenter" title="Memcache flowchart" src="http://garrettbluma.com/wp-content/uploads/2010/08/server-caching3.png" alt="" width="449" height="102" /></p>
<p style="text-align: center;">. . .</p>
<p>The method I describe here I used allowed a <em>real</em> site to receive 250,000 <em>real</em> page-views in 40 min (~104 requests/sec). I expect you can do much more. (More number towards the end.)</p>
<p>What I haven't mentioned yet is that I'm using PHP (specifically Joomla). PHP is certainly not the fastest language around, but considering the whole spectrum of issues facing a web developer, script performance is minimal. And since I'm on this rabbit trail, I'll mention that <a href="http://developer.yahoo.com/performance/rules.html">Javascript/CSS is the first thing to fix</a>, then caching. I don't need to explain more about this, there are volumes about it already.</p>
<p style="text-align: center;">. . .</p>
<p>Moving on, the method described for page caching is based on a simple fallback plan. Here is the psudo-code.</p>
<pre>If the page requested is in cache
    serve cached version
otherwise
    serve it dynamically
    add result to memcached</pre>
<p style="text-align: center;">. . .</p>
<p><strong>Joomla Plugin</strong></p>
<p>With Joomla we can actually do this very easily. We just need to hook into the <em>onAfterRender</em> event and grab the page data.  You might notice we're using the database name as the prefix to the URL in the key name. This is just to be friendly to any other sites hosted on the same server (or copies of the same site using a different database).</p>
<p>You also might notice that we're grabbing the gzipped version of the page. This is just to trim a little off what the user needs to download.</p>
<pre>// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class  plgSystemFullPageMemcache extends JPlugin
{
    function plgSystemFullPageMemcache(&amp; $subject, $config) {
        parent::__construct($subject, $config);
    }

    function onAfterRender() {
        global $mainframe;
        $config = new JConfig();
        $cache_id= $config-&gt;db . ":" . $_SERVER['REQUEST_URI'];

        $data = JResponse::toString($mainframe-&gt;getCfg('gzip'));

        $db = new Memcache;
        $db-&gt;addServer('127.0.0.1', '11211', true);
        $db-&gt;set($cache_id, $data, 1, 3600);
    }
}</pre>
<p><strong>Nginx configuration</strong></p>
<pre>server {

  listen 80;
  server_name  yourdomain.com www.yourdomain.com;

  # ...

  location ~ \.php$ {
    set $memcached_key "yourdomain:$request_uri";
    memcached_pass 127.0.0.1:11211;

    default_type       text/html;
    error_page 404 405 502 = @cache_miss;
  }

  location @cache_miss {
    fastcgi_pass 127.0.0.1:9002;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/yoursite/htdocs$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
  }

  # ...
}</pre>
<p style="text-align: center;">. . .</p>
<p>Here you can see <em>@cache_miss</em> will get called when nginx can't find anything in the memcache for the given key (the url). This triggers our fallback plan where the cache will fill itself with any missing data. When we do hit the cache, we actually bypass PHP altogether. No initialization wait, no slowness, and no database calls. By educated guess, nginx and memcached in this setup can start serving content in under 15 milliseconds. Compare this with the 50-100 milliseconds we commonly see.</p>
<p>Theoretically you could serve content faster using this system than just using files due to time spent waiting on disk access. In my proof of concept, I was able to serve about 2500 requests/second but I have reason to believe that limit was imposed by the network card. The CPU was at 10% the whole time and I'm sure it could handle more.</p>
<p>Happy caching!</p>
<p>(Downloadable Plugin Coming Soon)</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2010/08/16/nginx-memcached-direct-page-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx 0.5.33 + SSL + gzip = corrupt data (on large files)</title>
		<link>http://garrettbluma.com/2009/04/17/nginx-0533-ssl-gzip-corrupt-data-on-large-files/</link>
		<comments>http://garrettbluma.com/2009/04/17/nginx-0533-ssl-gzip-corrupt-data-on-large-files/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 04:40:26 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.garrettbluma.com/?p=126</guid>
		<description><![CDATA[First off, I love Nginx—It is by far, the best web-server I have ever used. I came across a bug recently which really caused me to scratch my head. It took me a couple days just to isolate the issue and then I couldn't find anyone who wrote about it—so that's what I'm doing here. The problem: On one particular javascript file I could never download the whole thing. This file was the concatenated version of about 8 files totaling near a megabyte. Turning on gzip compression helped significantly: 1mb turned into just over 250k. One caveat though, was that [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-147 aligncenter" title="Nginx Logo" src="http://www.garrettbluma.com/wp-content/uploads/2009/04/nginx-logo.png" alt="Nginx Logo" width="350" height="90" /></p>
<p>First off, I love <a href="http://nginx.net">Nginx</a>—It is by far, the best web-server I have ever used.</p>
<p>I came across a bug recently which really caused me to scratch my head. It took me a couple days just to isolate the issue and then I couldn't find anyone who wrote about it—so that's what I'm doing here.</p>
<p><strong>The problem:</strong><br />
On one particular javascript file I could never download the whole thing.</p>
<p>This file was the concatenated version of about 8 files totaling near a megabyte. Turning on gzip compression helped significantly: 1mb turned into just over 250k. One caveat though, was that this file would need to be accessed in both HTTP and HTTPS.</p>
<p>Here-in lies the problem—over HTTPS (and only over HTTPS) the file would truncate about 3/4 of the way through, leaving all sorts of broken code in the wake. Always at the same spot, and always in SSL—but only that one file.</p>
<p><strong>The Solution:</strong><br />
To test my theory, I cloned my server and upgraded to the newest stable version of nginx. I also figured it was a good time since there are a number of security fixes and I was only using the legacy version because Ubuntu had an easy installer for it.</p>
<p>Needless to say upgrading Nginx to 0.6.36 took care of the issue as well as patched up those nasty security holes.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2009/04/17/nginx-0533-ssl-gzip-corrupt-data-on-large-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing php5-mssql in Ubuntu 8.04 LTS</title>
		<link>http://garrettbluma.com/2009/01/21/installing-php5-mssql-in-ubuntu-804-lts/</link>
		<comments>http://garrettbluma.com/2009/01/21/installing-php5-mssql-in-ubuntu-804-lts/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 02:32:01 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[aptitude]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://gbluma.com/?p=11</guid>
		<description><![CDATA[I needed to migrate an old website which still relied on an MSSQL connection not supported in our new server I just built. Luckily someone else has already figured this one out (http://ubuntuforums.org/showthread.php?t=350269&#38;page=3) Here's the gist of it (pertaining to php5): aptitude install php5-sybase This installs the generic support for mssql (FYI, mssql is based on sybase) but is missing a few mssql specific functions for php. pear install --nodeps MDB2_Driver_mssql This command installs those extra functions and everything seems to work. Cheers!]]></description>
			<content:encoded><![CDATA[<p>I needed to migrate an old website which still relied on an MSSQL connection not supported in our new server I just built. Luckily someone else has already figured this one out (<a href="http://ubuntuforums.org/showthread.php?t=350269&amp;page=3">http://ubuntuforums.org/showthread.php?t=350269&amp;page=3</a>)</p>
<p>Here's the gist of it (pertaining to php5):</p>
<pre class="bash">aptitude <span style="color: #c20cb9; font-weight: bold;">install</span> php5-sybase</pre>
<p>This installs the generic support for mssql (FYI, mssql is based on sybase) but is missing a few mssql specific functions for php.</p>
<pre class="bash">pear <span style="color: #c20cb9; font-weight: bold;">install</span> --nodeps MDB2_Driver_mssql</pre>
<p>This command installs those extra functions and everything seems to work. Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2009/01/21/installing-php5-mssql-in-ubuntu-804-lts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 4/9 queries in 0.002 seconds using memcached
Object Caching 332/341 objects using memcached

Served from: garrettbluma.com @ 2012-05-21 02:53:03 -->
