<?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>All things Sysadmin &#187; Sundry sysadmin</title>
	<atom:link href="http://northernmost.org/blog/category/random-things-to-do-with-system-administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://northernmost.org/blog</link>
	<description>Just another manic Monday</description>
	<lastBuildDate>Sat, 10 Mar 2012 10:34:51 +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>Font rendering &#8211; no more jealousy</title>
		<link>http://northernmost.org/blog/font-rendering-no-more-jealousy/</link>
		<comments>http://northernmost.org/blog/font-rendering-no-more-jealousy/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 23:14:52 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[Sundry sysadmin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=417</guid>
		<description><![CDATA[f you like me is an avid Fedora user, I'm sure you've thrown glances at colleague's or friend's Ubuntu machines and thought that there was something that was slightly different about the way it looked (aside from the obvious Gnome vs Unity differences). Shinier somehow...  So had I, but I mainly dismissed it as a case of "the grass is always greener...".  <a href="http://northernmost.org/blog/font-rendering-no-more-jealousy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I suppose this kind of content is what most people use twitter for these days. But since I&#8217;ve remained strong and stayed well away from that, I suppose I will have to be a tad retro and write a short blog post about it.<br />
If you like me are an avid <a href="http://fedoraproject.org">Fedora</a> user, I&#8217;m sure you&#8217;ve thrown glances at colleague&#8217;s or friend&#8217;s Ubuntu machines and thought that there was something that was slightly different about the way it looked (aside from the obvious Gnome vs Unity differences). Shinier somehow&#8230;  So had I, but I mainly dismissed it as a case of &#8220;the grass is always greener&#8230;&#8221;. </p>
<p>It turns out that the grass actually IS greener. Tonight I stumbled upon <a href="http://www.infinality.net/blog/infinality-freetype-patches/">this</a>. It&#8217;s a patched version of freetype. For what I assume are political reasons (free as in speech), Fedora ships a Freetype version without subpixel rendering. These patches fixes that and <a href="http://www.infinality.net/forum/viewtopic.php?f=2&#038;t=18">other things</a>. </p>
<p>With a default configuration file of 407 lines, it&#8217;s quite extensible and configurable as well. Lucky, I quite like the default!</p>
<p>If you&#8217;re not entirely happy with the way your fonts look on Fedora &#8211; it&#8217;s well worth a look</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/font-rendering-no-more-jealousy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find out what is using your swap</title>
		<link>http://northernmost.org/blog/find-out-what-is-using-your-swap/</link>
		<comments>http://northernmost.org/blog/find-out-what-is-using-your-swap/#comments</comments>
		<pubDate>Fri, 27 May 2011 22:52:37 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=383</guid>
		<description><![CDATA[Have you ever logged in to a server, ran `free`, seen that a bit of swap is used and wondered what's in there? It's usually not very indicative of anything, or even overly helpful knowing what's in there, mostly it's a curiosity thing.
Either way, starting from kernel 2.6.16, we can find out using smaps found in the proc filesystem. I've written a simple bash script which prints out all running processes and their swap usage.  <a href="http://northernmost.org/blog/find-out-what-is-using-your-swap/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever logged in to a server, ran `free`, seen that a bit of swap is used and wondered what&#8217;s in there? It&#8217;s usually not very indicative of anything, or even overly helpful knowing what&#8217;s in there, mostly it&#8217;s a curiosity thing.</p>
<p>Either way, starting from kernel 2.6.16, we can find out using smaps which can be found in the proc filesystem. I&#8217;ve written a simple bash script which prints out all running processes and their swap usage.<br />
It&#8217;s quick and dirty, but does the job and can easily be modified to work on any info exposed in /proc/$PID/smaps<br />
If I find the time and inspiration, I might tidy it up and extend it a bit to cover some more alternatives. The output is in kilobytes. </p>
<p><code>#!/bin/bash<br />
# Get current swap usage for all running processes<br />
# Erik Ljungstrom 27/05/2011<br />
SUM=0<br />
OVERALL=0<br />
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do<br />
        PID=`echo $DIR | cut -d / -f 3`<br />
        PROGNAME=`ps -p $PID -o comm --no-headers`<br />
        for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`<br />
        do<br />
                let SUM=$SUM+$SWAP<br />
        done<br />
        echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"<br />
        let OVERALL=$OVERALL+$SUM<br />
        SUM=0</p>
<p>done<br />
echo "Overall swap used: $OVERALL"</code></p>
<p><strong>This will need to be ran as root</strong> for it to be able to gather accurate numbers. It will still work even if you don&#8217;t, but it will report 0 for any processes not owned by your user.<br />
Needless to say, it&#8217;s Linux only. The output is ordered alphabetically according to your locale (which admittedly isn&#8217;t a great thing since we&#8217;re dealing with numbers), but you can easily apply your standard shell magic to the output. For instance, to find the process with most swap used, just run the script like so:</p>
<p><code>$ ./getswap.sh | sort -n -k 5 </code><br />
Don&#8217;t want to see stuff that&#8217;s not using swap at all?<br />
<code>$ ./getswap.sh  | egrep -v "Swap used: 0" |sort -n -k 5</code></p>
<p>&#8230; and so on and so forth</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/find-out-what-is-using-your-swap/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Site slow after scaling out? Yeah, possibly!</title>
		<link>http://northernmost.org/blog/site-slow-after-scaling-out-yeah-possibly/</link>
		<comments>http://northernmost.org/blog/site-slow-after-scaling-out-yeah-possibly/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 22:25:40 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sundry sysadmin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=333</guid>
		<description><![CDATA[So, doing the maths, you're seeing 25*0.2*50= 250ms in just network latency per page load for your SQL queries. This is obviously a lot more than you see over a local UNIX socket.  <a href="http://northernmost.org/blog/site-slow-after-scaling-out-yeah-possibly/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Every now and then, we have customers who outgrow their single server setup. The next natural step is of course splitting the web layer from the DB layer. So they get another server, and move the database to that.</p>
<p>So far so good! A week or so later, we often get the call <em>&#8220;Our page load time is higher now than before the upgrade! We&#8217;ve got twice as much hardware, and it&#8217;s slower! You have broken it!&#8221;</em><br />
It&#8217;s easy to see where they&#8217;re coming from. It makes sense, right? </p>
<p>That is until you factor in the newly introduced network topology! Today it&#8217;s not unusual (that&#8217;s not to say it&#8217;s acceptable or optimal) for your average<br />
wordpress/drupal/joomla/otherspawnofsatan site to run 40-50 queries per page load. Quite often even more! </p>
<p>Based on a tcpdump session of a reasonably average query (if there is such a thing), connecting to a server, authenticating, sending a query and receiving a 5 row result set of 1434 bytes yields 25 packets being sent between my laptop and a remote DB server on the same wired, non-congested network. A normal, average latency of TCP/IP over Ethernet is ~0.2 ms for the size of packets we&#8217;re talking here.<br />
So, doing the maths, you&#8217;re seeing 25*0.2*50= 250ms in just network latency per page load for your SQL queries. This is obviously a lot more than you see over a local UNIX socket. </p>
<p>This is inevitable, laws of physics. It is nothing you, your sysadmin and/or your hosting company can do anything about. There may however be something your developer can do about the amount of queries!<br />
You also shouldn&#8217;t confuse response-times with availability. Your response times may be slower, but you can (hopefully) serve a lot more users with this setup! </p>
<p>Sure, there are <a href="http://www.dolphinics.com/">technologies</a> out there which have considerably less latency than ethernet, but they come with quite the price-tag, and there are more often than not quite a few avenues to go down before it makes sense to start looking at that kind of thing. </p>
<p>You could also potentially looking at running the full stack on both machines using master/master replication for your DBs, and load balance your front-ends and have them both read locally, but only write to one node at a time! That kind of DB scenario is something fairly easily set up using <a href="http://mysql-mmm.org/">mmm</a> for MySQL. But in my experience, this often ends up more costly and potentially introducing more complexities than it solves.<br />
I&#8217;m an avid advocate for keeping server roles separate as much as possible! </p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/site-slow-after-scaling-out-yeah-possibly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GlusterFS init script and Puppet</title>
		<link>http://northernmost.org/blog/glusterfs-init-script-and-puppet/</link>
		<comments>http://northernmost.org/blog/glusterfs-init-script-and-puppet/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 20:43:49 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=278</guid>
		<description><![CDATA[I got most of it set up, and got started on writing up the glusterfs Puppet module. Fairly straight forward, a few directories, configuration files and a mount point. Then I came to the Service declaration, and of course we want this to be running at all times, so I went on and wrote... <a href="http://northernmost.org/blog/glusterfs-init-script-and-puppet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The other day I had quite the head scratcher. I was setting up a new environment for a customer which included the usual suspects in a LAMP stack spread across a few virtual machines in an ESXi cluster.<br />
As the project is quite volatile in terms of requirements, amount of servers, server roles, location etc. I decided to start off using Puppet to make my life easier further down the road. </p>
<p>I got most of it set up, and got started on writing up the glusterfs Puppet module. Fairly straight forward, a few directories, configuration files and a mount point. Then I came to the Service declaration, and of course we want this to be running at all times, so I went on and wrote:</p>
<p><code>	service { "glusterfsd":<br />
		ensure => running,<br />
		enable => true,<br />
		hasrestart => true,<br />
		hasstatus => true,<br />
	}<br />
</code><br />
expecting glusterfsd to be running shortly after I purposefully stopped it. But it didn&#8217;t. So I dove into puppet (Yay Ruby!) and deduced that the way it determines whether something is running or not is the return code of:<br />
/sbin/service servicename status</p>
<p>So a quick look in the init script which ships with glusterfs-server shows that it calls the stock init function &#8220;status&#8221; on glusterfsd, which is perfectly fine, but then it doesn&#8217;t exit with the return code from this function, it simply runs out of scope and exits with the default value of 0. </p>
<p>So to get around this, I made a quick change to the init script and used the return code from the &#8220;status&#8221; function (/etc/rc.d/init.d/functions on RHEL5)  and exited with $?, and Puppet had glusterfsd running within minutes.  </p>
<p>I couldn&#8217;t find anything when searching for this, so I thought I&#8217;d make a note of it here.</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/glusterfs-init-script-and-puppet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Legitimate emails being dropped by Spamassassin in RHEL5</title>
		<link>http://northernmost.org/blog/legitimate-emails-being-dropped-by-spamassassin-in-rhel5/</link>
		<comments>http://northernmost.org/blog/legitimate-emails-being-dropped-by-spamassassin-in-rhel5/#comments</comments>
		<pubDate>Wed, 26 May 2010 13:21:08 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>
		<category><![CDATA[rhel5]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spamassassnin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=266</guid>
		<description><![CDATA[Over the past few months, an increasing number of customers have complained that their otherwise OK spam filters have started dropping an inordinate amount of legitimate emails.  <a href="http://northernmost.org/blog/legitimate-emails-being-dropped-by-spamassassin-in-rhel5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Over the past few months, an increasing number of customers have complained that their otherwise OK spam filters have started dropping an inordinate amount of legitimate emails.<br />
The first reaction is of course to increase the score required to be filtered, but that just opens up for more spam. I looked in the quarantine on one of these servers, and ran a few of the legitimate ones through spamassassin in debug mode. I noticed one particular rule which was prevalent in the vast majority of the emails. Here&#8217;s an example:</p>
<p><code>...<br />
[2162] dbg: learn: initializing learner<br />
[2162] dbg: check: is spam? score=4.004 required=6<br />
[2162] dbg: check: tests=FH_DATE_PAST_20XX,HTML_MESSAGE,SPF_HELO_PASS<br />
...</code></p>
<p>4 is obviously quite a high score for an email whose only flaw is being in HTML. But FH_DATE_PAST_20XX caught my eye in all of the outputs. So to the rule files:</p>
<p><code>$ grep FH_DATE_PAST_20XX /usr/share/spamassassin/72_active.cf<br />
##{ FH_DATE_PAST_20XX<br />
header   FH_DATE_PAST_20XX      Date =~ /20[1-9][0-9]/ [if-unset: 2006]<br />
describe FH_DATE_PAST_20XX      The date is grossly in the future.<br />
##} FH_DATE_PAST_20XX</code></p>
<p>Aha. This is a problem. With 50_scores.cf containing this:<br />
<code><br />
$ grep FH_DATE_PAST /usr/share/spamassassin/50_scores.cf<br />
score FH_DATE_PAST_20XX 2.075 3.384 3.554 3.188 # n=2</code></p>
<p>there&#8217;s no wonder emails are getting dropped! I guess this is a problem one can expect when running a distribution with packages 6 years old and neglect to frequently (or at least every once in a while) <a href="http://wiki.apache.org/spamassassin/RuleUpdates">update the rules</a>!</p>
<p>Luckily, this rule is gone altogether from RHEL6&#8242;s version of spamassassin.</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/legitimate-emails-being-dropped-by-spamassassin-in-rhel5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control groups in RHEL6</title>
		<link>http://northernmost.org/blog/control-groups-in-rhel6/</link>
		<comments>http://northernmost.org/blog/control-groups-in-rhel6/#comments</comments>
		<pubDate>Thu, 13 May 2010 17:12:54 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=253</guid>
		<description><![CDATA[One new feature that I'm very enthusiastic about in RHEL6 is Control Groups (cgroup for short). It allows you to create groups and allocate resources to these. You can then bunch your applications into groups at your heart's content.  <a href="http://northernmost.org/blog/control-groups-in-rhel6/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One new feature that I&#8217;m very enthusiastic about in RHEL6 is Control Groups (cgroup for short). It allows you to create groups and allocate resources to these. You can then bunch your applications into groups at your heart&#8217;s content. </p>
<p>It&#8217;s relatively simple to set up, and configuration can be done in two different ways. You can use the supplied cgset command, or if you&#8217;re accustomed to doing it the usual way when dealing with kernel settings, you can simply echo values into the pseudo-files under the control group. </p>
<p>Here&#8217;s a controlgroup in action:</p>
<p><code>[root@rhel6beta cgtest]# grep $$ /cgroup/gen/group1/tasks<br />
1138<br />
[root@rhel6beta cgtest]# cat /cgroup/gen/group1/memory.limit_in_bytes<br />
536870912<br />
[root@rhel6beta cgtest]# gcc alloc.c -o alloc &#038;&#038; ./alloc<br />
Allocating 642355200 bytes of RAM,,,<br />
Killed<br />
[root@rhel6beta cgtest]# echo `echo 1024*1024*1024| bc` > /cgroup/gen/group1/memory.limit_in_bytes<br />
[root@rhel6beta cgtest]# ./alloc<br />
Allocating 642355200 bytes of RAM,,,<br />
Successfully allocated 642355200 bytes of RAM, captn' Erik...<br />
[root@rhel6beta cgtest]#</code></p>
<p>The first line shows that the shell which launches the app is under the control of the cgroup group1, so subsequently all it&#8217;s child processes are subject to the same restrictions.</p>
<p>As you can also see, the initial memory limit in the group is 512M. Alloc is a simple C app I wrote which calloc()s 612M of RAM (for demonstrative purposes, I&#8217;ve disabled swap on the system altogether). At the first run, the kernel kills the process in the same way it would if the whole system had run out of memory. The kernel message also indicates that the control group ran out of memory, and not the system as a whole:</p>
<p><code>...<br />
May 13 17:56:20 rhel6beta kernel: Memory cgroup out of memory: kill process 1710 (alloc) score 9861 or a child<br />
May 13 17:56:20 rhel6beta kernel: Killed process 1710 (alloc)</code></p>
<p>Unfortunately it doesn&#8217;t indicate which cgroup the process belonged to. Maybe it should?</p>
<p>cgroups doesn&#8217;t just give you the ability to limit the amount of RAM, it has a lot of tuneables. You can even set swappiness on a per-group basis! You can limit the devices applications are allowed to access, you can freeze processes as well as tag outgoing network packets with a class ID, in case you want to do shaping or profiling on your network! Perfect if you want to prioritise SSH traffic over anything else, so you can comfortably worked even when your uplink is saturated. Furthermore, you can easily get an overview of memory usage, CPU accounting etc. of applications in any given group.</p>
<p>All this means you can clearly separate resources and to quite a large extent ensure that some applications won&#8217;t starve the whole system, or each other from resources. Very handy, no more waiting for half an hour for the swap to fill up and OOM to kick (and often chose the wrong PID) in when customer&#8217;s applications have run astray. </p>
<p>A much welcomed addition to RHEL! </p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/control-groups-in-rhel6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Hiphop PHP gotcha</title>
		<link>http://northernmost.org/blog/building-hiphop-php-gotcha/</link>
		<comments>http://northernmost.org/blog/building-hiphop-php-gotcha/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 03:04:22 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>
		<category><![CDATA[Webservers]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=219</guid>
		<description><![CDATA[Tonight I've delved into the world of Facebook's HipHop for PHP. Unfortunately I set about this task on an RHEL 5.4 box, and it hasn't been a walk in the park. Quite a few dependencies were out of date or didn't exist in the repositories, libicu, boost, onig, tbb etc. Though, CMake did a good job of telling me what was wrong, so it wasn't a huge deal, I just compiled the missing pieces from source and put them in $CMAKE_PREFIX_PATH. One thing CMake didn't pick up on however, was that the flex version shipped with current RHEL is rather outdated. <a href="http://northernmost.org/blog/building-hiphop-php-gotcha/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Tonight I&#8217;ve delved into the world of Facebook&#8217;s <a title="HipHop for PHP" href="http://developers.facebook.com/news.php?story=358&amp;blog=1" target="_blank">HipHop for PHP</a>. Let me early on point out that I&#8217;m not doing so because I believe that I will need it any time soon, but I am convinced  that I without a shadow of a doubt  will be approached by customers who think they do, and I rather not have opinions or advise against things I haven&#8217;t tried myself or at least have a very good understanding of.</p>
<p>Unfortunately I set about this task on an RHEL 5.4 box, and it hasn&#8217;t been a walk in the park. Quite a few dependencies were out of date or didn&#8217;t exist in the repositories, libicu, boost, onig, tbb etc.</p>
<p>Though, CMake did a good job of telling me what was wrong, so it wasn&#8217;t a huge deal, I just compiled the missing pieces from source and put them in $CMAKE_PREFIX_PATH. One thing CMake didn&#8217;t pick up on however, was that the flex version shipped with current RHEL is rather outdated. Once I thought I had everything configured, I set about the compilation, and my joy was swiftly abrupted by this:</p>
<p><code>[  3%] [FLEX][XHPScanner] Building scanner with flex /usr/bin/flex version 2.5.4<br />
/usr/bin/flex: unknown flag '-'.  For usage, try	/usr/bin/flex --help</code></p>
<p>Not entirely sure what it was actually doing here, I took the shortcut of replacing /usr/bin/flex with a shell script which just exited after putting $@ in a file in /tmp/ and re-ran `make`. Looking in the resulting file, this is the argument flex is given:</p>
<p><code>-C --header-file=scanner.lex.hpp -o/home/erik/dev/hiphop-php/src/third_party/xhp/xhp/scanner.lex.cpp /home/erik/dev/hiphop-php/src/third_party/xhp/xhp/scanner.l</code></p>
<p>To me that looks quite valid, and there&#8217;s certainly no single &#8211; in that command line.</p>
<p>Long story short, flex introduced &#8211;header-file in a relatively &#8220;recent&#8221; version (2.5.33 it seems, but I may be wrong on that one, doesn&#8217;t matter). Unlike most other programs (using getopt), it won&#8217;t tell you &#8220;Invalid option &#8216;&#8211;header-file&#8217;&#8221;. So after compiling a newer version of flex, I was sailing again.</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/building-hiphop-php-gotcha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flush bash_history after each command</title>
		<link>http://northernmost.org/blog/flush-bash_history-after-each-command/</link>
		<comments>http://northernmost.org/blog/flush-bash_history-after-each-command/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 02:47:13 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash_history]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=156</guid>
		<description><![CDATA[If you, like me, often work in a lot of terminals on a lot of servers, or even a lot of terminals on the same one, you may recognise the frustration of a lost bash history.  <a href="http://northernmost.org/blog/flush-bash_history-after-each-command/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you, like me, often work in a lot of terminals on a lot of servers, or even a lot of terminals on the same one, you may recognise the frustration of a lost bash history.<br />
I don&#8217;t always gracefully log out of my sessions, so every so often my ~/.bash_history isn&#8217;t written and all my flashy commands are lost (the history buffer is only committed when you log out, everything that you see in `history` is not actually written to disk). I quite often find myself rewriting the same one-liners or long option list just because I closed my <a href="http://konsole.kde.org/">konsole</a> or <a href="http://www.vandyke.com/products/securecrt/">SecureCRT</a> window without first logging out of all the sessions properly.</p>
<p>So I put some effort into finding a solution to this, and whilst reading through the bash manpage, I saw PROMPT_COMMAND. *pling*<br />
<code>export PROMPT_COMMAND='history -a'</code></p>
<p>To quote the manpage: &#8220;If set, the value is executed as a command prior to issuing each primary prompt.&#8221;<br />
So every time my command has finished, it appends the unwritten history item to ~/.bash_history before displaying the prompt (only $PS1) again. </p>
<p>So after putting that line in /etc/bashrc I don&#8217;t have to find myself reinventing wheels or lose valuable seconds re-typing stuff just because I was lazy with my terminals.</p>
<p>This is one of those things that I should have done ages ago, but never took the time to.</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/flush-bash_history-after-each-command/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>btrfs &#8211; filesystem to end all filesystems?</title>
		<link>http://northernmost.org/blog/btrfs-filesystem-to-end-all-filesystems/</link>
		<comments>http://northernmost.org/blog/btrfs-filesystem-to-end-all-filesystems/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 02:05:31 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[Sundry sysadmin]]></category>
		<category><![CDATA[btrfs]]></category>
		<category><![CDATA[crfs]]></category>
		<category><![CDATA[filesystem]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=83</guid>
		<description><![CDATA[There are some good stuff on the horizon! It&#8217;s called btrfs (&#8220;butter-fs&#8221;). It was originally announced/&#8221;released&#8221; over a year ago by our friends at Oracle and has, in my opinion, not quite received the attention it deserves. I&#8217;m keeping a &#8230; <a href="http://northernmost.org/blog/btrfs-filesystem-to-end-all-filesystems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are some good stuff on the horizon! It&#8217;s called <a title="btrfs" href="http://btrfs.wiki.kernel.org/index.php/Main_Page" target="_blank">btrfs</a> (&#8220;butter-fs&#8221;). It was originally announced/&#8221;released&#8221; over a year ago by our friends at Oracle and has, in my opinion, not quite received the attention it deserves. I&#8217;m keeping a close eye on the very intensive devlopment of this as the feature list is very interesting from several aspects. It&#8217;s got some of the big names behind it and will undoubtedly be widely deployed and accepted into the vanilla kernel once stable.</p>
<p>btrfs, like <a href="http://opensolaris.org/os/community/zfs/">ZFS</a>, implements copy-on-write model, so yes &#8211; it will be able to do snapshots! Writeable ones at that. In fact, it&#8217;s got the ability to do snapshots of snapshots! Quasi-MVC filesystem!<br />
COW unfortunately makes a filesystem more prone to fragmentation, but luckily btrfs comes with online defragmentation and fs check abilities. The speed of read and write operations will obviously be impaired during such operations, but there&#8217;s always ways around that in most performance sensitive setups! If not, there should be!<br />
Sadly, COW isn&#8217;t that good of a choice for database workloads. But fret not, COW can be disabled with a mount option (-o nodatacow). This doesn&#8217;t mean you will lose the snapshot ability, as btrfs ignores this option if a data extent is referenced by more than one snapshot, so COW will, as far as I understand, be enabled from that you initiate a snapshot and stay that way until you&#8217;re done with it.</p>
<p>Early <a href="http://oss.oracle.com/projects/btrfs/dist/documentation/benchmark.html">benchmarks</a> show that btrfs is extremely fast at writing, and a little poorer at reading. It will be interesting to see how these numbers change as development proceeds. If added features will have any negative impact on performance. As a side note &#8211; I was quite surprised to see the poor numbers for ext3 in these benchmarks! </p>
<p>So if you&#8217;re a DBA and your data fits in memory, this filesystem will be right up your alley. With a reasonable amount of tables and some proper values for innodb_open_files and table_cache, I wouldn&#8217;t expect any remarkable difference in day-to-day database operation since the real bottleneck usually is in the hardware.<br />
This is generally speaking of course. I&#8217;m sure there are workloads out there which will benefit a lot more than &#8220;the norm&#8221;. Likewise, people with awkward read heavy setups with a lot of data in a lot of files may probably be better off not using btrfs.<br />
If you, like myself, often use blinks of an eye as a unit, you know what I&#8217;m talking about. </p>
<p>Yet another interesting functionality built in is the multiple device support. I will not call it a substitute for proper hardware based RAID, but could well be one for LVM (bearing the snapshots in mind as well)!</p>
<p>Another thing worth keeping an eye on is a related project; <a href="http://oss.oracle.com/projects/crfs/">CRFS</a> which may turn out to be a worthy NFS replacement. While it&#8217;s planned to get failover capabilities, I would much rather have seen a client-agnostic <a href="http://www.danga.com/mogilefs/">MogileFS-</a> style implementation.</p>
<p>Sadly, they are not production ready yet. By far. But it&#8217;s something to look forward to. I&#8217;ll give it a version or two until I will put it under the microscope further and chuck some real world load onto it. Can&#8217;t wait!</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/btrfs-filesystem-to-end-all-filesystems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some trickery or resilience with Varnish</title>
		<link>http://northernmost.org/blog/some-trickery-or-resilience-with-varnish/</link>
		<comments>http://northernmost.org/blog/some-trickery-or-resilience-with-varnish/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 00:56:11 +0000</pubDate>
		<dc:creator>Erik Ljungstrom</dc:creator>
				<category><![CDATA[Sundry sysadmin]]></category>
		<category><![CDATA[resilience]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://northernmost.org/blog/?p=33</guid>
		<description><![CDATA[If you've got two or more backends, and under some condition can't or won't serve a request immediately or want to send it elsewhere depending on some circumstance, you can do this using HTTP return code or header with the not-so-well-documented feature 'restart'  <a href="http://northernmost.org/blog/some-trickery-or-resilience-with-varnish/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As of now, Varnish has no means to detect whether a backend is available or at good health before sending a request (periodic checking is scheduled for ver 2.0 and will presumably work with the cluster mode as well). So if you&#8217;ve got two or more backends, and under some condition can&#8217;t or won&#8217;t serve a request immediately or want to send it elsewhere depending on some circumstance, you can do this using HTTP return code or header with the not-so-well-documented feature &#8216;restart&#8217; (then again, what feature is well documented in Varnish?). </p>
<p>&#8216;restart&#8217; will effectively increase a counter by 1 and re-run vcl_recv(). You can set how many times a restart should take place before giving up entirely &#8211; should you not use the counter in a condition prior to it reaching the limit &#8211; by starting varnishd with -p max_restarts=n or &#8216;param.set max_restarts 1&#8242; on the CLI. This variable defaults to 4, and you can of course set conditions depending on the number of restarts. </p>
<p>Here&#8217;s a sample VCL to do this:</p>
<p><code> backend be1 {<br />
                .host = "127.0.0.1";<br />
                .port = "81";<br />
        }<br />
        backend  be2 {<br />
                .host = "10.0.0.2";<br />
                .port = "81";<br />
        }</p>
<p>        sub vcl_recv {<br />
                if (req.restarts == 0) {<br />
                        set req.backend = be1;<br />
                } else if (req.restarts == 1) {<br />
                        set req.backend = be2;<br />
                }<br />
        }</p>
<p>        sub vcl_fetch {<br />
                if (obj.status != 200 &#038;&#038; obj.status != 302) {<br />
                        restart;<br />
                }<br />
        }<br />
</code></p>
<p>In this simple VCL, a request destined for this instance of Varnish which doesn&#8217;t return 200 or 302 from the backend, is effectively sent to 10.0.0.2 which may have something else in store for the visitor!</p>
<p>If I for instance use the above VCL and set be1 to return a 301 for / and send a request to Varnish, this is what shows up in varnishlog:</p>
<p>&#8230;<br />
10 ObjProtocol  c HTTP/1.1<br />
<strong>   10 ObjStatus    c 301</strong><br />
   10 ObjResponse  c Moved Permanently<br />
   10 ObjHeader    c Date: Tue, 22 Jul 2008 00:25:29 GMT<br />
   10 ObjHeader    c Server: Apache/2.0.59 (CentOS)<br />
   10 ObjHeader    c X-Powered-By: PHP/5.1.6<br />
   10 ObjHeader    c Location: http://be1.northernmost.org:6081/links.php/<br />
   10 ObjHeader    c Content-Type: text/html; charset=UTF-8<br />
   13 BackendClose b be1<br />
   10 TTL          c 1839681264 RFC 120 1216686329 1216686329 0 0 0<br />
   10 VCL_call     c fetch<br />
 <strong>  10 VCL_return   c restart</strong><br />
   10 VCL_call     c recv<br />
   10 VCL_return   c lookup<br />
   10 VCL_call     c hash<br />
   10 VCL_return   c hash<br />
   10 VCL_call     c miss<br />
   10 VCL_return   c fetch<br />
   12 BackendClose b be2<br />
   <strong>12 BackendOpen  b be2 </strong>10.0.0.1 38478 10.0.0.2 81<br />
   12 TxRequest    b GET<br />
   12 TxURL        b /<br />
   12 TxProtocol   b HTTP/1.1<br />
&#8230;<br />
   10 ObjProtocol  c HTTP/1.1<br />
   10 ObjStatus    c 200<br />
   10 ObjResponse  c OK<br />
   10 ObjHeader    c Date: Mon, 21 Jul 2008 23:37:24 GMT<br />
   10 ObjHeader    c Server: Apache/2.2.6 (FreeBSD) mod_ssl/2.2.6 OpenSSL/0.9.8e DAV/2<br />
   10 ObjHeader    c Last-Modified: Thu, 10 Jul 2008 14:26:46 GMT<br />
   10 ObjHeader    c ETag: &#8220;35e801-3-3702d580&#8243;<br />
   10 ObjHeader    c Content-Type: text/html<br />
   12 BackendReuse b be2<br />
&#8230;</p>
<p>You can of course use this for very basic resilience as well, but that&#8217;s definitely a job for your load balancer. Also be aware about the overhead in this, since the request after all <strong>is</strong> sent to the backend and processed before passed on to the other node.</p>
<p>Maybe it&#8217;s not the most useful feature in the world, but I thought it was nifty!</p>
]]></content:encoded>
			<wfw:commentRss>http://northernmost.org/blog/some-trickery-or-resilience-with-varnish/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

