<?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>Floorplanner Tech Blog &#187; Uncategorized</title>
	<atom:link href="http://techblog.floorplanner.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Our latest geek adventures!</description>
	<lastBuildDate>Tue, 16 Mar 2010 18:45:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Database replication in 5 easy steps</title>
		<link>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/</link>
		<comments>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 13:34:00 +0000</pubDate>
		<dc:creator>Gert-Jan van der Wel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database replication mysql]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=753</guid>
		<description><![CDATA[Running an online service like Floorplanner is not without risks. There are a lot of things that can go wrong. One of them is downtime of your service due to a crashing system. It doesn&#8217;t have to happen of course, but when it does, it can have some nasty consequences. A good way to reduce [...]]]></description>
			<content:encoded><![CDATA[<p>Running an online service like <a href="http://floorplanner.com">Floorplanner</a> is not without risks. There are a lot of things that can go wrong. One of them is downtime of your service due to a crashing system. It doesn&#8217;t have to happen of course, but when it does, it can have some nasty consequences. A good way to reduce the risk of a crashing system is to set up a redundant system.</p>
<p>In short, a redundant system is an exact copy of your main system. When your main system goes down (for whatever reason), the redundant system can take over. One of the most important parts of any online service is the database. A way to maintain an exact copy of your database is setting up database replication. This post gives you the basics on how to set up database replication using a MySQL database.</p>
<p>Database replication isn&#8217;t probably something you&#8217;d setup right from the start. This means that you have to work with a running system when you decide to do so. From past experience we know that it&#8217;s not a good idea to replicate your database to the same machine, let alone to the same disk. To make this work, you need a separate machine with MySQL installed. This is your slave machine and database.</p>
<p>Let&#8217;s get down to business. These are the steps for setting up database replication:</p>
<ol>
<li>Enable binary logging on master database</li>
<li>Create a backup of master database</li>
<li>Transfer backup to slave machine</li>
<li>Import backup to slave database</li>
<li>Start slave database</li>
</ol>
<h3>1. Enable binary logging on master database</h3>
<blockquote><p><em>The binary log contains all statements that update data [..]. Statements are stored in the form of “events” that describe the modifications. The binary log also contains information about how long each statement took that updated data.</em></p></blockquote>
<p>Every write action that&#8217;s performed on your database, like an insert or an update, is stored in these binary logs (bin logs). The master dumps all actions in these logs and the slave database can read them  and perform the same actions. This way your master and slave databases will always have the same data.</p>
<p>To enable binary logging you have to create a config file, for example master.cnf. An important thing here is the server-id, which is needed for replication to work. Then there is log-bin which specifies base name of binary logs, and finally binlog-do-db, which specifies which databases should be bin logged.</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">[mysqld]
datadir=/home/yourname/mysql/myisam/data
basedir=/usr/local/mysql
port=3306
server-id=1
log-bin=mysql-bin
binlog-do-db=my_fat_db1
binlog-do-db=ma_other_fat_db</pre></div></div>

<p>Then start (or restart) the master database using the config file:</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">~ $ mysqld --defaults-file=master.cnf&amp;amp;</pre></div></div>

<p>The slave database needs a userid/password in order to access the master machine. It&#8217;s best practice create a dedicated user with just the required privileges. This can be done with the following SQL statement.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> replication slave <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">*.*</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'repl'</span>@<span style="color: #ff0000;">'slave-ip-here'</span></pre></div></div>

<h3>2. Create a backup of master database</h3>
<p>The next step it to create a backup of your master database. The type of your database is very important for this action. If you use MyISAM, you need to schedule some downtime to dump your database. Otherwise the dumped data isn&#8217;t consistent and therefor useless. <span style="background-color:#FFE789">With InnoDB it&#8217;s possible to dump a consistent backup of your database while keeping it up and running</span>. We stumbled on this feature by accident, but we haven&#8217;t been able to in the official documentation.</p>
<p>MyISAM</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">~ $ mysqldump --lock-all-tables</pre></div></div>

<p>InnoDB</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">~ $ mysqldump --single-transaction</pre></div></div>

<h3>3. Transfer backup to slave machine</h3>
<p>Now that the backup is created on the master machine, it needs to be transferred to the slave machine.</p>
<h3>4. Import backup to slave database</h3>
<p>Once the backup is present on the slave machine, it can be imported into the slave database:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family: Monaco,monospace;">~ $ mysql &amp;lt; filename</pre></div></div>

<h3>5. Start slave database</h3>
<p>The last step is to tell the database that it&#8217;s a slave database. First we have to give it an server id. We use a config file for this, slave.cnf:</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">[mysqld]
datadir=/home/yourname/mysql/myisam/data
basedir=/usr/local/mysql
port=3306
server-id=2
replicate-do-db=my_fat_db1
replicate-do-db=my_other_fat_db</pre></div></div>

<p>Then we start the database with this config file:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family: Monaco,monospace;">~ $ mysqld --defaults-file=slave.cnf&amp;amp;</pre></div></div>

<p>and we issue the following SQL statement:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">CHANGE</span> MASTER <span style="color: #993333; font-weight: bold;">TO</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_HOST<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'master-ip-here'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_PORT<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">3306</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_USER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_PASSWORD<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_LOG_FILE<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'bin-log-filename-here'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_LOG_POS<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">4</span>;</pre></div></div>

<p>It&#8217;s hard to predict the MASTER_LOG_POS. You can find this number by issuing the following SQL statement on the <strong>master</strong> database:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> MASTER <span style="color: #993333; font-weight: bold;">STATUS</span>\G;</pre></div></div>

<p>Once the slave is configured correctly it will get the bin logs from the master machine, parse them and execute each action. It takes some time to have an exact copy of the master database, depending on the size and number of bin logs. To get an idea about the delay, issue the following query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> SLAVE <span style="color: #993333; font-weight: bold;">STATUS</span>\G;</pre></div></div>

<p>With this post we hope to contribute to a less riskier world and more peaceful state of mind for the sys admins out there <img src='http://techblog.floorplanner.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Evaluating static ParseTree subtrees</title>
		<link>http://techblog.floorplanner.com/2009/10/03/evaluating-static-parsetree-subtrees/</link>
		<comments>http://techblog.floorplanner.com/2009/10/03/evaluating-static-parsetree-subtrees/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 12:34:21 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[evaluate]]></category>
		<category><![CDATA[ParseTree]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[syntax tree]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=734</guid>
		<description><![CDATA[ParseTree is a very useful to gem that can translate Ruby code into a syntax tree. I recently needed to evaluate a static part of this tree to return the original hash it represented. I wrote a simple method called ParseTree.eval_static_tree for this purpose. 
The method can only evaluate trees that have a static value [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://parsetree.rubyforge.org/">ParseTree</a> is a very useful to gem that can translate Ruby code into a syntax tree. I recently needed to evaluate a static part of this tree to return the original hash it represented. I wrote a simple method called <code>ParseTree.eval_static_tree</code> for this purpose. </p>
<p>The method can only evaluate trees that have a static value composed of hashes, arrays, strings, symbols and numerics. You can however pass a block to the function that will be called for every dynamic part the method encounters (function calls, etc.) </p>
<p><script src="http://gist.github.com/200607.js"></script></p>
<p>A quick sample on how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family: Monaco,monospace;">code = <span style="color:#996600;">'{ :static_array =&gt; [&quot;str&quot;, 123, 4.5], :dynamic =&gt; method_call }'</span>
tree = ParseTree.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span>code<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># =&gt; [:hash, [:lit, :static_array], [:array, [:str, &quot;str&quot;], </span>
<span style="color:#008000; font-style:italic;">#       [:lit, 123], [:lit, 4.5]], [:lit, :dynamic], [:vcall, :method_call]]</span>
&nbsp;
ParseTree.<span style="color:#9900CC;">eval_static_tree</span><span style="color:#006600; font-weight:bold;">&#40;</span>tree<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># =&gt; RuntimeError: tree is not static: :vcall ...</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Pass a block to simply return nil for every dynamic item in the tree.</span>
ParseTree.<span style="color:#9900CC;">eval_static_tree</span><span style="color:#006600; font-weight:bold;">&#40;</span>tree<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>dynamic_subtree<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># =&gt; {:dynamic=&gt;nil, :static_array=&gt;[&quot;str&quot;, 123, 4.5]}</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/10/03/evaluating-static-parsetree-subtrees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Request-log-analyzer 1.4.0</title>
		<link>http://techblog.floorplanner.com/2009/09/30/request-log-analyzer-1-4-0/</link>
		<comments>http://techblog.floorplanner.com/2009/09/30/request-log-analyzer-1-4-0/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 09:40:04 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[log analysis]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[Rack CommonLogger]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[request-log-analyzer]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=729</guid>
		<description><![CDATA[Bart and I have been working a lot on request-log-analyzer lately, our tool to produce performance reports for web applications based on their log files. Today, we released version 1.4.0, which boasts many new features since I last blogged about a release. The changelog contains all changes we have implemented recently with some additional information, [...]]]></description>
			<content:encoded><![CDATA[<p>Bart and I have been working a lot on <a href="http://github.com/wvanbergen/request-log-analyzer">request-log-analyzer</a> lately, our tool to produce performance reports for web applications based on their log files. Today, we released version 1.4.0, which boasts many new features since I last blogged about a release. The <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/changelog">changelog</a> contains all changes we have implemented recently with some additional information, but these are the highlights:</p>
<ul>
<li><strong>New and improved log formats:</strong> r-l-a can now handle <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/apache-access-log">Apache access logs</a>, <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/apache-access-log#rack">Rack CommonLogger logs</a> and <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/amazon-s3-access-log">Amazon S3 access logs</a>. Moreover, the Rails format has been restructured to offer <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/rails-request-log">more flexibility</a>.</li>
<li><strong>Improved database support: </strong>the database supports other databases than SQLite3 as well, and r-l-a can append information to an existing database instead of overwriting it. Moreover, a console tool similar to Rails&#8217;s script/console is bundled to inspect the database and run queries on it easily.</li>
<li><strong>Added standard deviation to reports: </strong>the standard deviation measure has been added to duration and traffic reports to get some feel of the variation in values besides the mean.</li>
<li><strong>E-mailing reports:</strong> r-l-a can email the performance report to a given e-mail address. This can be useful when running r-l-a in a cron job.</li>
<li><strong>Compressed log support:</strong> r-l-a will decompress compressed logs automatically.</li>
<li><strong>Speed improvements:</strong> we have profiled <a href="http://techblog.floorplanner.com/2009/09/27/performance-tweaking-of-ruby-algorithms/">request-log-analyzer itself</a> and significantly improved its performance.</li>
<li><strong>API:</strong> we created a basic API so it is possible to use the r-l-a engine as a library as well.</li>
<li><strong>Monitoring integration:</strong> integrate performance information into your <a href="http://github.com/barttenbrinke/munin-plugins-rails/">Munin dashboard</a> or your <a href="http://wiki.github.com/wvanbergen/request-log-analyzer/scout">Scout account</a>.</li>
</ul>
<p>As always, use <code>sudo gem install request-log-analyzer</code> to install or upgrade.</p>
<h3>Ruby en Rails 2009 conference</h3>
<p>Bart and I will be presenting request-log-analyzer and performance tuning of Rails applications in general at the <a href="http://2009.rubyenrails.nl">Ruby en Rails</a> conference in Amsterdam, October 30-31 2009. We hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/09/30/request-log-analyzer-1-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Finished reading Code Complete</title>
		<link>http://techblog.floorplanner.com/2007/11/20/72/</link>
		<comments>http://techblog.floorplanner.com/2007/11/20/72/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 09:43:21 +0000</pubDate>
		<dc:creator>Gert-Jan van der Wel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/72.html</guid>
		<description><![CDATA[
Yesterday I finally finished reading Steve McConnell&#8217;s Code Complete &#8211; A practival handbook of software construction. I really loved reading it and I definitely learned a lot from it, but it takes a while to finish the 914 pages  
If you are in the business of writing code, I recommend you to buy a [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;margin-right:10px;"><a href="http://cc2e.com/" target="_blank"><img src="http://tbn0.google.com/images?q=tbn:CEofuCj0j96x2M:https://tlsj.tenlong.com.tw/WebModule/BookSearch/cover/E01/0735619670.jpg" alt="Code Complete"/></a></div>
<p>Yesterday I finally finished reading Steve McConnell&#8217;s <a href="http://cc2e.com/" target="_blank">Code Complete &#8211; A practival handbook of software construction</a>. I really loved reading it and I definitely learned a lot from it, but it takes a while to finish the 914 pages <img src='http://techblog.floorplanner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you are in the business of writing code, I recommend you to buy a copy of this book and start reading it right away!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2007/11/20/72/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Changing coding style</title>
		<link>http://techblog.floorplanner.com/2007/08/01/changing-coding-style/</link>
		<comments>http://techblog.floorplanner.com/2007/08/01/changing-coding-style/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 12:55:34 +0000</pubDate>
		<dc:creator>Gert-Jan van der Wel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/changing-coding-style.html</guid>
		<description><![CDATA[After reading the chapter Layout and Style of the (very good) book Code Complete 2nd Edition Steve McConnell convinced me to change the way I write my functions. Before I wrote functions like this:

function functionName&#40;&#41;
&#123;
    ...
&#125;

This way you have a nice line of white space between the function declaration and the inside [...]]]></description>
			<content:encoded><![CDATA[<p>After reading the chapter <b>Layout and Style</b> of the (very good) book <a href="http://www.amazon.com/Code-Complete-Second-Steve-McConnell/dp/0735619670/sr=1-1/qid=1169499581?ie=UTF8&#038;s=books" target="_blank">Code Complete 2nd Edition</a> Steve McConnell convinced me to change the way I write my functions. Before I wrote functions like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">function</span> functionName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This way you have a nice line of white space between the function declaration and the inside of the function. I thought this line of white space improved the readability of the code. Steve McConnell learned me that although that may be true, it cripples the most important thing of code layout: the layout has to follow logical structure of the code.  So I&#8217;m back to using this style:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">function</span> functionName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you want to know more about this subject or anything else regarding software construction I can certainly recommend you to read <a href="http://www.amazon.com/Code-Complete-Second-Steve-McConnell/dp/0735619670/sr=1-1/qid=1169499581?ie=UTF8&#038;s=books" target="_blank">Code Complete 2nd Edition</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2007/08/01/changing-coding-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Pragmatic Programmer</title>
		<link>http://techblog.floorplanner.com/2007/05/02/the-pragmatic-programmer/</link>
		<comments>http://techblog.floorplanner.com/2007/05/02/the-pragmatic-programmer/#comments</comments>
		<pubDate>Wed, 02 May 2007 10:48:34 +0000</pubDate>
		<dc:creator>Gert-Jan van der Wel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/?p=44</guid>
		<description><![CDATA[I really enjoyed reading The Pragmatic Programmer. It made me realise that there is still a lot to learn.  

]]></description>
			<content:encoded><![CDATA[<p>I really enjoyed reading <a href="http://www.pragmaticprogrammer.com/ppbook/index.shtml" target="_blank">The Pragmatic Programmer</a>. It made me realise that there is still a lot to learn. <img src='http://techblog.floorplanner.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://www.pragmaticprogrammer.com/ppbook/index.shtml" target="_blank"><img src="http://techblog.floorplanner.com/wp-content/uploads/2007/05/pp_cover_small.jpg" border="0"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2007/05/02/the-pragmatic-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
