<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Reader. Reaper. Piper.</title>
	<atom:link href="http://rerepi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rerepi.wordpress.com</link>
	<description>Software development tips for newbies</description>
	<lastBuildDate>Wed, 20 Apr 2011 14:23:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rerepi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Reader. Reaper. Piper.</title>
		<link>http://rerepi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rerepi.wordpress.com/osd.xml" title="Reader. Reaper. Piper." />
	<atom:link rel='hub' href='http://rerepi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>forget about the environment</title>
		<link>http://rerepi.wordpress.com/2009/05/03/forget-about-the-environment/</link>
		<comments>http://rerepi.wordpress.com/2009/05/03/forget-about-the-environment/#comments</comments>
		<pubDate>Sun, 03 May 2009 14:02:27 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/?p=23</guid>
		<description><![CDATA[Maybe this is obvious (and still flammable topic) for most of system administrators, but it worth to say it again. You should never rely on the environment variables, unless you explicitly specify that in the documentation (which is still bad way in most cases). You script must work if there&#8217;s no PATH env. variable, or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=23&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Maybe this is obvious (and still flammable topic) for most of system administrators, but it worth to say it again.</p>
<p>You should never rely on the environment variables, unless you explicitly specify that in the documentation (which is still bad way in most cases). You script must work if there&#8217;s no PATH env. variable, or no EDITOR set, etc. Yes, it may say error to the end user in unresolvable conditions, as `svn ci` do if no EDITOR and no -m specified, but generally it shouldn&#8217;t fail.</p>
<p>Not `sh`, but `/bin/sh`, not `cat`, but `/bin/cat`! Remember it and you&#8217;ll save a lot of nerves for you and all those people that will use your tools.</p>
<p>Thank you.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=23&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2009/05/03/forget-about-the-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Even munin have things to simplify</title>
		<link>http://rerepi.wordpress.com/2009/05/03/even-munin-have-things-to-simplify/</link>
		<comments>http://rerepi.wordpress.com/2009/05/03/even-munin-have-things-to-simplify/#comments</comments>
		<pubDate>Sun, 03 May 2009 09:24:29 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[munin]]></category>
		<category><![CDATA[complaints]]></category>
		<category><![CDATA[FreeBSD]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/?p=20</guid>
		<description><![CDATA[The &#8216;config&#8217; option in munin plugins is probably unnecessary and exists only because somebody didn&#8217;t think long enough about it. No, seriously, I understand why there&#8217;s &#8216;autoconf&#8217; and &#8216;suggest&#8217; options &#8211; they&#8217;re really rarely called, maybe on node installation or when module first added to the configuration. But &#8216;config&#8217; should be (and it is) called [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=20&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The &#8216;config&#8217; option in munin plugins is probably unnecessary and exists only because somebody didn&#8217;t think long enough about it.</p>
<p>No, seriously, I understand why there&#8217;s &#8216;autoconf&#8217; and &#8216;suggest&#8217; options &#8211; they&#8217;re really rarely called, maybe on node installation or when module first added to the configuration. But &#8216;config&#8217; should be (and it is) called before each data fetch. Because graph legend or graph options may change between calls. So, if we always call &#8216;config&#8217; and &#8216;fetch&#8217; pair why do we have separate commands for them?</p>
<p>So, it is not an option and should be merged into the &#8216;fetch&#8217; command.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=20&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2009/05/03/even-munin-have-things-to-simplify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>munin and gaps in df_ graphs</title>
		<link>http://rerepi.wordpress.com/2009/05/02/munin-and-gaps-in-df_-graphs/</link>
		<comments>http://rerepi.wordpress.com/2009/05/02/munin-and-gaps-in-df_-graphs/#comments</comments>
		<pubDate>Sat, 02 May 2009 23:23:56 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[samba]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/?p=16</guid>
		<description><![CDATA[Someone forgot to add samba filesystem into the df&#8217;s ignore list in FreeBSD port of munin-node. They grep out strings  with &#8220;//&#8221;  (which is&#8230; strange, not to say stupid). Most of users will have gaps in df munin graphs as the result. Remote filesystem info may be not accessible for dozens of reasons and cause [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=16&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Someone forgot to add samba filesystem into the df&#8217;s ignore list in FreeBSD port of munin-node. They grep out strings  with &#8220;//&#8221;  (which is&#8230; strange, not to say stupid).</p>
<p>Most of users will have gaps in df munin graphs as the result. Remote filesystem info may be not accessible for dozens of reasons and cause the whole df_ plugin to timeout, which will report &#8220;unknown&#8221; values to munin and you will get alert email into your inbox and gap in the graph.</p>
<p>To resolve the problem you will need to add smbfs and cifs into the ignore list in two lines of both /usr/local/share/munin/plugins/df_ and df_inode files:</p>
<blockquote><p>/bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,nfs,smbfs | tail +2 | grep -v “//” | while read i; do</p></blockquote>
<p>This should be fixed in <em>two lines</em> in each file. You may remove `grep` if you want, I keep it just to be safe.</p>
<p>P.S.: As far as I know the problem exists also in Linux. In the RedHat&#8217;s and Ubuntu&#8217;s repos at least.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=16&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2009/05/02/munin-and-gaps-in-df_-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding new entry into /etc/periodic/</title>
		<link>http://rerepi.wordpress.com/2008/05/24/adding-new-entry-into-etcperiodic/</link>
		<comments>http://rerepi.wordpress.com/2008/05/24/adding-new-entry-into-etcperiodic/#comments</comments>
		<pubDate>Sat, 24 May 2008 08:58:16 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[periodic]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/?p=12</guid>
		<description><![CDATA[Did you know that you can easily add new time intervals into the system&#8217;s periodic feature? Let&#8217;s add /etc/periodic/hourly as the example: #&#62; mkdir /etc/periodic/hourly #&#62; # creating the crontab entry to run scripts at 25 minutes every hour #&#62; echo "25 * * * * root periodic hourly" &#62;&#62; /etc/crontab into /etc/periodic.conf: hourly_output="root" # [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=12&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Did you know that you can easily add new time intervals into the system&#8217;s periodic feature?</p>
<p>Let&#8217;s add /etc/periodic/hourly as the example:</p>
<p><span id="more-12"></span></p>
<pre>#&gt; mkdir /etc/periodic/hourly
#&gt; # creating the crontab entry to run scripts at 25 minutes every hour
#&gt; echo "25	*	*	*	*	root	periodic hourly" &gt;&gt; /etc/crontab</pre>
<p>into /etc/periodic.conf:</p>
<pre>hourly_output="root"				# user or /file
weekly_show_success="NO"			# scripts returning 0
weekly_show_info="YES"				# scripts returning 1
weekly_show_badconfig="NO"			# scripts returning 2</pre>
<p>That&#8217;s all. We are done! Now you can place executable scripts into /etc/periodic/hourly and they will run every hour under root account.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=12&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2008/05/24/adding-new-entry-into-etcperiodic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Tuning FreeBSD to serve 100-200 thousands of connections</title>
		<link>http://rerepi.wordpress.com/2008/04/19/tuning-freebsd-sysoev-rit/</link>
		<comments>http://rerepi.wordpress.com/2008/04/19/tuning-freebsd-sysoev-rit/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 18:50:58 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[translations]]></category>
		<category><![CDATA[software tuning]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/?p=11</guid>
		<description><![CDATA[FreeBSD needs to be configured the special way to be able to handle hundreds of thousands of connection simultaneously.
<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=11&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="margin-bottom:0;">I&#8217;m back finally. There&#8217;s the translation of the Igor Sysoev&#8217;s report made on the <a title="Russina internet Technologies site (Russain language!)" href="http://www.rit2008.ru/">RIT</a> conference. Igor Sysoev is the creator of one of the most used lightweight http servers in Russia and the world &#8211; <a title="Sysoev's website" href="http://sysoev.ru/en/">nginx</a>.<span id="more-11"></span></p>
<p style="margin-bottom:0;">I also use nginx as reverse-proxy and load balancer in my project.</p>
<h2>mbuf clusters</h2>
<p style="margin-bottom:0;">FreeBSD stores the network data in the mbuf clusters 2Kb each, but only 1500B are used in each cluster (the size of the Ethernet packet)</p>
<h2>mbufs</h2>
<p>For each mbuf cluster there is “mbuf” structure needed, which have 256B in size and used to organize mbuf clusters in chains. There&#8217;s possibility to store some additional useful 100B data into the mbuf, but it is not always used.</p>
<p>If server have the RAM of 1Gb or more 25 thousands of mbuf clusters will be created by default but it is not enough in some cases.</p>
<p>When there&#8217;s no any free mbuf clusters available FreeBSD enters the zonelimit state and stops to answer to any network requests. You can see it as the `zoneli` state in the output of the `top` command.</p>
<p>To fix this problem the only solution is to log in through the local console and reboot the system. It is impossible to kill the process in `zoneli` state. This problem is also actual for Linux 2.6.x but even local console will not work in this state for Linux.</p>
<p>There is the patch that fixes the problem, it returns ENOBUFS error,  which indicates entering the `zoneli` state and the program may close some connections when receives the error. Unfortunately this patch have not been merged into FreeBSD yet.</p>
<p>The state of used mbuf clusters can be checked by the following command:</p>
<blockquote><p>&gt; netstat -m<br />
1/1421/1425 mbufs in use (current/cache/total)</p>
<p>0/614/614/25600 mbufs clusters in use (current/cache/total/max)</p></blockquote>
<p>You can increase quantity of the mbufs clusters through the kern.ipc.nmbclusters parameter:</p>
<blockquote><p>&gt; sysctl kern.ipc.nmbclusters=65536</p></blockquote>
<p>For earlier versions of FreeBSD mbuf clusters can be configured only in boot time:</p>
<blockquote><p>/boot/loader.conf:</p>
<p>kern.ipc.mbclusters=65536</p></blockquote>
<p>25000 mbuf clusters takes bout a 50Mb in the memory, 32000 – 74Mb, 65000 – 144 Mb (raises by the power of 2). 65000 is the boundary value and I can&#8217;t recommend to exceed it without increasing address space of the kernel first.</p>
<h2>Increasing the amount of memory available for kernel</h2>
<p>The default space for the kernel in memory is 1Gb for i386 architecture. To set it to 2Gb specify the following line in the kernel configuration file:</p>
<blockquote><p>options KVA_PAGES=512</p></blockquote>
<p>On the amd64 the the KVA is always 2Gb and there&#8217;s no possibility to increase it yet.</p>
<p>In addition to increasing the address space there&#8217;s the possibility to increase the limit of the physical memory available for kernel (320Mb by default). Let&#8217;s increase it to 1Gb:</p>
<blockquote><p>/boot/loader.conf:</p>
<p>vm.kmem_size=1G</p></blockquote>
<p>And reserve 275Mb for mbuf cluster from that space:</p>
<blockquote><p>sysctl kern.ipc.nmbclusters=262144</p></blockquote>
<h2>Establishing the connection. syncache and syncookies</h2>
<p>There&#8217;s approximately 100 bytes needed to serve one single connection.<br />
Approximatelly 100 bytes space is used for single unfinished connection in syncache.<br />
There&#8217;s possibility to store information about 15000 connections in memory. Approximately.</p>
<p>Snyncache parameters can bee seen by “sysctl net.inet.tcp.syncache” command (read-only).</p>
<p>Syncache parameters can be changed only during boot time:</p>
<blockquote><p>/boot/loader.conf:<br />
net.inet.tcp.syncache.hashsize=1024<br />
net.inet.tcp.syncache.bucketlimit=100</p></blockquote>
<p>when the new connection does not fit into overfull syncache FreeBSD enters the `syncookies` state (TCP SYN cookies). This possibility is enabled with:</p>
<blockquote><p>sysctl net.inet.tcp.syncookies=1</p></blockquote>
<p>The syncache population and the syncookies stats can be seen with `ntestat -s -p tcp` command.</p>
<p>When the connection is accepted it comes to the “listen socket queue”</p>
<p>Their&#8217;s stats can be seen with the `netstat -Lan` command.</p>
<p>Inreasing of the queue is possible with the `sysctl kern.ipc.somaxconn=4096` command</p>
<p>Whan the connection is accepted FreeBSD creates the sockets structures.</p>
<p>To increase the limit of the open sockets:</p>
<blockquote><p>sysctl kern.ipc.maxsockets=204800</p></blockquote>
<p>In earlier versions:</p>
<blockquote><p>/boot/loader.conf:<br />
kern.ipc.maxsockets=204800</p></blockquote>
<p>The current state can be seen with the following command:</p>
<blockquote><p>&gt; vmstat -z</p></blockquote>
<h2>tcb hash</h2>
<p>If the server processes several tens of thousands connections the tcb hash allows to detect the target connection for each incoming tcp packet quickly.</p>
<p>The tcb hash is 512 bytes by default.</p>
<p style="page-break-before:always;">The current size can be seen with:</p>
<blockquote><p>sysctl net.inet.tcp.tcbhashsize</p></blockquote>
<p>It is changeable in the boot time:</p>
<blockquote><p>/boot/loader.conf:|<br />
sysctl net.inet.tcp.tcbhashsize=4096</p></blockquote>
<h2>Files</h2>
<p>Applicatios are working not with the sockets but with files. And there&#8217;s file descriptor needed for each socket because of that. To increase:</p>
<blockquote><p>sysctl kern.maxfiles=204800<br />
sysctl kern.maxfilesperproc=200000</p></blockquote>
<p>These options can be changed on the live system but they will not affect already running processes. nginx have the ability to change the open files limit on the fly:</p>
<blockquote><p>nginx.conf:<br />
worker_limit_nofile  200000;<br />
events {<br />
worker_connections  200000;<br />
}</p></blockquote>
<h2>receive buffers</h2>
<p>Buffers for incoming data. 64Kb by default, if there&#8217;s no large uploads can be decreased to 8Kb (decreases the probability of overflow during a DDoS attack):</p>
<blockquote><p>sysctl net.inet.tcp.recvspace=8192</p></blockquote>
<p>For nginx:</p>
<blockquote><p>nginx.conf:<br />
listen 80 default rcvbuf=8k;</p></blockquote>
<h2>send buffers</h2>
<p>Buffers for outgoing data. 32K by default. If data have a small size usually or there&#8217;s a lack of mbuf clusters it may be decreased:</p>
<blockquote><p>sysctl net.inet.tcp.sendspace=16384</p></blockquote>
<p>For nginx:</p>
<blockquote><p>nginx.conf:<br />
listen 80 default sendbuf=16k;</p></blockquote>
<p>In the case when server has written some data to the socket but the client do not want to receive it the data will live in the kernel for several minutes even after the connection will be closed by timeout. Nginx have the option to erase all data after the timeout:</p>
<blockquote><p>nginx.conf:<br />
reset_timedout_connections on;</p></blockquote>
<h2>sendfile</h2>
<p>Another way to save some mbuf clusters is the sendfile. It uses the kernel file buffers memory to send the data to the network interface without any intermediate buffers usage.</p>
<p>To enable in nginx:</p>
<blockquote><p>nginx.conf:<br />
sendfile on;</p></blockquote>
<p>(you should explicitly switch it off if you&#8217;re sending files from the partition mounted via smbfs or cifs &#8211; <em>ReRePi</em>)</p>
<p>On the i386 platform with 1Gb and more memory 6656 sendfile buffers will be allocated which is usually enough. On the amd64 platform more optimal implementation is used and there&#8217;s no need in sendbufs at all.</p>
<p>On the sendbuf overflow the process stucks in the `sfbufa` state, but things turns ok after the buffer size is increased:</p>
<blockquote><p>/boot/loader.conf:<br />
kern.ipc.nsfbufs=10240</p></blockquote>
<h2>TIME_WAIT</h2>
<p>After the connection was closed the socket enters the TIME_WAIT state. In this state it can live for 60 seconds by default. This time can be changed with sysctl (in milliseconds divided by 2. 2&#215;30000 MSL = 60 seconds):</p>
<blockquote><p>sysctl net.inet.tcp.msl=30000</p></blockquote>
<h2>TCP/IP ports</h2>
<p>Outgoing connection are bind to the ports from the 49152 – 65535 range (16 thousands). It is better to be increased (1024 – 65535):</p>
<blockquote><p>sysctl net.inet.ip.portrange.first=1024<br />
sysctl net.inet.ip.portrange.last=65535</p></blockquote>
<p>To use ports in natural order instead of random (to make the second connection for the same port impossible before TIME_WAIT):</p>
<blockquote><p>sysctl net.inet.ip.portrange.randomized=0</p></blockquote>
<p>In FreeBSD 6.2 the possibility to not create TIME_WAIT state for localhost connections was added:</p>
<blockquote><p>sysctl net.inet.tcp.nolocaltimewait=1</p></blockquote>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=11&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2008/04/19/tuning-freebsd-sysoev-rit/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Dell notebook</title>
		<link>http://rerepi.wordpress.com/2007/11/20/dell-notebook/</link>
		<comments>http://rerepi.wordpress.com/2007/11/20/dell-notebook/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 20:48:55 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[complains]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[notebook]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/2007/11/20/dell-notebook/</guid>
		<description><![CDATA[Just complaining&#8230; Some time ago I bought Latitude D620 and was completelly happy about it &#8211; it was fast, relatively small and not too heavy. And everything was working. Until I&#8217;ve re-installed the operating system. Even with Dell drivers I don&#8217;t have bluetooth now, I had approximatelly a week of hardcode fucking with wi-fi, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=10&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just complaining&#8230;</p>
<p>Some time ago I bought Latitude D620 and was completelly happy about it &#8211; it was fast, relatively small and not too heavy. And everything was working. Until I&#8217;ve re-installed the operating system. Even with Dell drivers I don&#8217;t have bluetooth now, I had approximatelly a week of hardcode fucking with wi-fi, and it is overheating now. Even when idle. If I&#8217;ll install Linux will it explode?</p>
<p>I can&#8217;t believe things can be such bad in 21th century!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=10&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2007/11/20/dell-notebook/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>My Little Servers Plant</title>
		<link>http://rerepi.wordpress.com/2007/11/14/my-little-servers-plant/</link>
		<comments>http://rerepi.wordpress.com/2007/11/14/my-little-servers-plant/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 00:00:14 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cluster]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/2007/11/14/my-little-servers-plant/</guid>
		<description><![CDATA[Just want to describe the servers set-up I&#8217;m using on my current project. In next several posts I&#8217;ll tell why things was made some way and not another, and I&#8217;ll describe my future plans also. But for now only the whole system layout: I have six servers at the moment. Two of them is isolated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=9&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just want to describe the servers set-up I&#8217;m using on my current project. In next several posts I&#8217;ll tell why things was made some way and not another, and I&#8217;ll describe my future plans also.</p>
<p>But for now only the whole system layout:</p>
<p>I have six servers at the moment. Two of them is isolated set-up and runs live installation of the application. They will  run it until I&#8217;ll get the next release online on new servers set-up.</p>
<p>Remaining four servers:</p>
<p>Two absolutelly same relatively powerfull servers used for web front-end. Almost typical Apache+mod_php installation and nginx reverse-proxy for load-balancing.</p>
<p>One server if dedicated for the MySQL and some background tasks like images processing.</p>
<p>One server (unlike others it is not very powerfull) is now doing absolutely nothing. I&#8217;m planning to put system monitoring, logs, backups, staging installation,  and maybe some other non-critical stuff there.</p>
<p>All four servers runs under FreeBSD 6.2, shared storage required by application is located on third-party windows server (client&#8217;s data-center) and mounted through smb protocol.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=9&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2007/11/14/my-little-servers-plant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Interfaces and Usability</title>
		<link>http://rerepi.wordpress.com/2007/11/13/interfaces-and-usability/</link>
		<comments>http://rerepi.wordpress.com/2007/11/13/interfaces-and-usability/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 22:02:40 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[UML]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/2007/11/13/interfaces-and-usability/</guid>
		<description><![CDATA[There are a lot of UML software, but nothing is better yet than large whiteboard. Why?..<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=8&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are a lot of UML software, but nothing is better yet than large whiteboard. Why?..</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=8&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2007/11/13/interfaces-and-usability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>Denormalization again</title>
		<link>http://rerepi.wordpress.com/2007/11/11/denormalization-again/</link>
		<comments>http://rerepi.wordpress.com/2007/11/11/denormalization-again/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 12:47:47 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[denormalization]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/2007/11/11/denormalization-again/</guid>
		<description><![CDATA[Just realized that there is one more benefit in denormalizing  way described in previous post:  you can easily move Orders records to another database server because you don&#8217;t really need foreign keys to products database. Helps with the scalability.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=6&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just realized that there is one more benefit in <a href="http://rerepi.wordpress.com/2007/11/11/one-more-reason-for-denormalization/" title="One More Reason for “Denormalization”">denormalizing</a>  way described in previous post:  you can easily move Orders records to another database server because you don&#8217;t really need foreign keys to products database. Helps with the scalability.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=6&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2007/11/11/denormalization-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
		<item>
		<title>One More Reason for &#8220;Denormalization&#8221;</title>
		<link>http://rerepi.wordpress.com/2007/11/11/one-more-reason-for-denormalization/</link>
		<comments>http://rerepi.wordpress.com/2007/11/11/one-more-reason-for-denormalization/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 11:21:49 +0000</pubDate>
		<dc:creator>rerepi</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[denormalization]]></category>
		<category><![CDATA[normalization]]></category>

		<guid isPermaLink="false">http://rerepi.wordpress.com/2007/11/11/one-more-reason-for-denormalization/</guid>
		<description><![CDATA[Everyone knows what is database normalization for and everyone tries to keep their database normalized at maximum possible level. Guaranteed data integrity, impossibility of insert/update/delete anomalies &#8211; all that cool things, you know&#8230; Most of developers also know what is database denormalization for &#8211; for improving performance in most cases. Btw because of cheap hardware [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=5&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Everyone knows what is <a href="http://en.wikipedia.org/wiki/Database_normalization" title="Wikipedia article">database normalization</a> for and everyone tries to keep their database normalized at maximum possible level. Guaranteed data integrity, impossibility of insert/update/delete anomalies &#8211; all that cool things, you know&#8230;</p>
<p>Most of  developers also know what is <a href="http://en.wikipedia.org/wiki/Denormalization" title="Wikipedia article">database <strong>de</strong>normalization</a> for &#8211; for improving performance in most cases.</p>
<p>Btw because of cheap hardware and relatively expensive development services for most applications maximum performance is not the  main goal. So, seems like no reason for denormalizaition?</p>
<p>Nope. There&#8217;s no reason for denormalization only if the data never changes.</p>
<p>Let&#8217;s see the simple example. We have a shop and we&#8217;re selling blankets with custom art printed on them.  There are several steps from order submit to shipping &#8211; the art should at least be rendered, approved by quality control team and printed. What will happen if we will change some properties of the product when order is already submitted but not yet rendered? The size of printable area for example (we&#8217;re going to buy some new printing equipment with smaller printable area and don&#8217;t want to allow users to use old large area anymore).</p>
<p>With perfectly normalized  database structure we will take the size of the printable area from the product properties and we will finally render smaller image. Will it be cropped or resized &#8211; doesn&#8217;t matter because it will differ from what user expected to get and what he saw on the preview anyway.</p>
<p>There are several possible approaches to avoid this problem. First is to make a clone of the product record on every change, so all old orders will point to unchanged data. In some cases it is acceptable way &#8211; if product info changed rarely we will not have too much garbage in the database, but if it is changed relatively frequently, or we expect the system to keep data for several years, then the second way is better I think.</p>
<p>The second way is  to keep all information necessary for printing within the order record even if it will duplicate some product&#8217;s properties.  It is actually not the &#8216;denormalization&#8217; if we&#8217;ll call that &#8216;extra&#8217; fields in order record not the &#8220;product&#8217;s editable area size&#8221; but &#8220;image size this order was submitted with&#8221;. This simple trick allows us to consider the whole database still perfectly normalized.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rerepi.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rerepi.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rerepi.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rerepi.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rerepi.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rerepi.wordpress.com&amp;blog=2077044&amp;post=5&amp;subd=rerepi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rerepi.wordpress.com/2007/11/11/one-more-reason-for-denormalization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/941c45b6e9671f372375a9286373d62f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rerepi</media:title>
		</media:content>
	</item>
	</channel>
</rss>
