<?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>mFabrik - mobile sites, apps, HTML5 and CMS software development &#187; debian</title>
	<atom:link href="http://blog.mfabrik.com/tag/debian/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mfabrik.com</link>
	<description>Freedom delivered.</description>
	<lastBuildDate>Wed, 03 Aug 2011 09:47:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Reducing MySQL memory usage on Ubuntu / Debian Linux</title>
		<link>http://blog.mfabrik.com/2011/03/31/reducing-mysql-memory-usage-on-ubuntu-debian-linux/</link>
		<comments>http://blog.mfabrik.com/2011/03/31/reducing-mysql-memory-usage-on-ubuntu-debian-linux/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 10:56:46 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plone]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[mtop]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[res]]></category>
		<category><![CDATA[top]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virt]]></category>
		<category><![CDATA[virtual memory]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1149</guid>
		<description><![CDATA[If you are running your services on a low end virtual hosting every byte of memory you can save is important. The memory is often the limiting factor of how many applications you can run on VPS: CPUs are shared, memory not, on the same physical host. Low-end VPS come with 512 MB memory or [...]]]></description>
			<content:encoded><![CDATA[<p>If you are running your services on a low end virtual hosting every byte of memory you can save is important. The memory is often the limiting factor of how many applications you can run on VPS: CPUs are shared, memory not, on the same physical host.</p>
<ul>
<li>Low-end VPS come with 512 MB memory or less</li>
<li>Front front-end server Apache / Nginx / Varnish takes &gt; 100 MB +  min. 20 MB for each child process</li>
<li>Memecached takes its toll</li>
<li>MySQL takes 200 &#8211; 400 MB</li>
<li>Each Python / PHP process takes at least 15 MB and you need parallel processes for paraller HTTP requests (FCGI, pre-fork, others&#8230; )</li>
<li>Operating system processes need some memory (SSH, cron, sendmail)</li>
</ul>
<p>As you can see it gets very crowded in 512 MB.</p>
<p>It&#8217;s especially troublesome since the memory is allocated lazily and the memory usage builds up slowly. In some point caches are no longer caches, but swapped to a disk &#8211; virtual memory usage grows beyond available RAM. To keep the server response, everything time critical should fit to RAM once and if the processes themselves don&#8217;t know how to release memory in this situation you need to tune a memory cap for them.</p>
<h2>MySQL memory consumption</h2>
<p>MySQL can be a greedy bastard what comes to memory consumption. Here on this server MySQL seems to take 417M virtual memory which seems to be little excessive for just running two WordPress instances and one Django / Python application:</p>
<pre>1310 mysql     20   0  417M 21100  2776 S  0.0  1.2  0:00.00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/v</pre>
<p>After some tuning I was able to bring it down a bit</p>
<pre>3354 mysql     20   0  276m  19m 2848 S    0  1.2   3:41.19 mysqld</pre>
<p>A reduction of 130 MB, or 1/4 of the server total memory. Not bad.</p>
<p><a href="http://ubuntu-snippets.blogspot.com/2009/02/mtop-mysql-monitor.html">Use mtop to monitor running MySQL</a>, its querieries, etc. so you know what&#8217;s going on. As you can see this MySQL has very good cache rate meaning that basically it is keeping everything in memory. If the content of the sites is less than 10 MBytes total, 400 MB contains plenty of space to cache the content:</p>
<pre>load average: 0.05, 0.08, 0.16 mysqld 5.0.51a-3ubuntu5.8-log up 1 day(s), 19:47 hrs                                                             
2 threads: 1 running, 6 cached. Queries/slow: 187.1K/0 Cache Hit: 99.39%</pre>
<h2>What eats memory</h2>
<p>I am not an expert on MySQL, so I hope someone with more insight could post comments regarding how to tune MySQL for low memory situations and how it is expected to behave.</p>
<p>Some ideas I run through my head</p>
<ul>
<li>MySQL default cache settings are not too tight on Ubuntu/Debian, making it suitable for moderate loads, not low loads. If you don&#8217;t have much content, everything is just kept in memory (even if not needed)</li>
<li>MySQL uses round robin for connections and if there is 100 max connections it will allocate a thread stack for each connection (someone please confirm this &#8211; I found contracting infos).</li>
</ul>
<h2>Configuring MySQL</h2>
<p>Here are listed some methods how to reduce the memory usage. This is what I done on this little box</p>
<p>MySQL is mostly configured in <em>/etc/mysql/my.cnf</em> on Ubuntu / Debian.</p>
<ul>
<li>Let&#8217;s halve key_buffer from 16M to 8M. <a href="http://dev.mysql.com/doc/refman/5.0/en/myisam-key-cache.html">It is used by MyISAM table cache</a>.</li>
<li>Halve <a href="http://techgurulive.com/2010/10/20/query_cache_size-tuning-optimizing-my-cnf-file-for-mysql/">query_cache_size</a>. query_cache_size  = 8M. Also, decrease query_cache_limit to 512 K.</li>
<li><a href="http://www.mysqlperformanceblog.com/2006/05/17/mysql-server-memory-usage/">Each connection, even if idle, will have 256 KB buffer</a>. Decrease the number of max. connections. (XXX: not sure about this). Drop max connections from 100 -&gt; 30, as we do not have that many concurrent visitors on the site. Also, set less aggressive thread_stack size.</li>
</ul>
<p>The final adjustments</p>
<pre>key_buffer              = 8M
max_connections         = 30
query_cache_size        = 8M
query_cache_limit       = 512K
thread_stack            = 128K</pre>
<h2>More info</h2>
<ul>
<li><a href="http://www.zimbio.com/Linux/articles/692/Fine+Tuning+MYSQL+Reducing+Memory+Usage">Fine-tuning MySQL</a></li>
<li><a href="http://www.electrictoolbox.com/mysql-table-storage-engine/">Showing what database engine MySQL tables are using</a></li>
<li><a href="http://www.mysqlperformanceblog.com/2006/05/17/mysql-server-memory-usage/">MySQL server memory usage</a></li>
<li><a href="http://www.lowendbox.com/blog/reducing-mysql-memory-usage-for-low-end-boxes/">Reducing MySQL memory usage for low end boxes</a></li>
</ul>
<p>Send in more tips please! Is 32-bit better than 64-bit for low end VPS, how much this affects MySQL?
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/31/reducing-mysql-memory-usage-on-ubuntu-debian-linux/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Setting up Apache virtual hosts behind Varnish</title>
		<link>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/</link>
		<comments>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 10:44:28 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[plone]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[listen]]></category>
		<category><![CDATA[namevirtualhost]]></category>
		<category><![CDATA[ports]]></category>
		<category><![CDATA[static media]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1058</guid>
		<description><![CDATA[Varnish is a very fast front end cache server. You might want to use it at the front of Apache to speed up loading of your static pages and static media, for example for your WordPress blog. You can also use Varnish backends to multiplex the requests between Plone and Apache based PHP software running [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.varnish-cache.org/">Varnish</a> is a very fast front end cache server. You might want to use it at the front of Apache to speed up loading of your static pages and static media, for example for your WordPress blog. You can also use Varnish backends to multiplex the requests between Plone and Apache based PHP software running on the same server using different <em>backend</em> directives.</p>
<p>However if you wish to use Apache virtual hosts with Varnish there is a trick in it.</p>
<p>We use the following setup</p>
<ul>
<li>Varnish listens to port 80, HTTP</li>
<li>Apache listens to port 81</li>
<li>Varnish uses Apache as a backend</li>
</ul>
<p>The related <em>varnish.vcl</em> is</p>
<pre>backend backend_apache {
.host = "127.0.0.1";
.port = "81";
}

sub vcl_recv {
 ...
 elsif (req.http.host ~ "^blog.mfabrik.com(:[0-9]+)?$") {
    set req.backend = backend_apache;
 }
 ...
}</pre>
<p>Note that the backend IP is 127.0.0.1 (localhost). By default, with Debian or Ubuntu Linux, Apache configuration does not do virtual hosting for this.</p>
<p>So if <em>/etc/apache2/sites-enabled/blog.mfabrik.com </em>looks like:</p>
<pre>&lt;VirtualHost *:81&gt;

 ServerName blog.mfabrik.com
 ...
 LogFormat       combined
 TransferLog     /var/log/apache2/blog.mfabrik.com.log

 ...

 ExpiresActive On
 ExpiresByType image/gif A3600
 ExpiresByType image/png A3600
 ExpiresByType image/image/vnd.microsoft.icon A3600
 ExpiresByType image/jpeg A3600
 ExpiresByType text/css A3600
 ExpiresByType text/javascript A3600
 ExpiresByType application/x-javascript A3600
&lt;/VirtualHost&gt;</pre>
<p>And now the trick &#8211; you need to add the following to <em>/etc/apache2/httpd.conf</em></p>
<pre>NameVirtualHost *:81</pre>
<p>Unless you do all this, Apache will just pick the first virtualhost file in <em>/etc/apache2/sites-enabled</em> and use it for all requests.</p>
<p>Also you need to edit ports.conf and change Apache to listen to port 81:</p>
<pre>Listen 81</pre>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Perfect dual boot crypted hard disk setup with Truecrypt and LUKS</title>
		<link>http://blog.mfabrik.com/2008/07/15/perfect-dual-boot-crypted-hard-disk-setup-with-truecrypt-and-luks/</link>
		<comments>http://blog.mfabrik.com/2008/07/15/perfect-dual-boot-crypted-hard-disk-setup-with-truecrypt-and-luks/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 00:33:55 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vista]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[alternate]]></category>
		<category><![CDATA[crypted]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[dual boot]]></category>
		<category><![CDATA[encrypt]]></category>
		<category><![CDATA[grub]]></category>
		<category><![CDATA[hard disk]]></category>
		<category><![CDATA[hd]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[mbr]]></category>
		<category><![CDATA[truecrypt]]></category>

		<guid isPermaLink="false">http://blog.redinnovation.com/?p=55</guid>
		<description><![CDATA[I have a work laptop used in Symbian and web development. I need to be able to boot both Vista and Linux. Due to client privacy, both operating systems must be crypted for the case of lost laptop. Even if I do not use Windows actively, its web browser data may contain stored password for [...]]]></description>
			<content:encoded><![CDATA[<p>I have a work laptop used in Symbian and web development. I need to be able to boot both Vista and Linux. Due to client privacy, both operating systems must be crypted for the case of lost laptop. Even if I do not use Windows actively, its web browser data may contain stored password for client systems and it would be catastrophic to leak them accidentally.</p>
<p>Here are instructions how to encrypt your hard disk in safely but performance effective manner with Ubuntu 8.04 Hardy Heron and Windows Vista. These instructions can be applied for any version of Vista, since we use third party open source Truecrypt suite to encrypt the Windows partition. The instructions also give priority for Grub boot loader, so that the computer will boot to Linux if there is no user interaction during the boot.</p>
<p style="text-align: center;"><a href="http://blog.redinnovation.com/wp-content/uploads/2008/07/2669747740_ea50af33a0.jpg"><img class="alignnone size-medium wp-image-56 aligncenter" title="2669747740_ea50af33a0" src="http://blog.redinnovation.com/wp-content/uploads/2008/07/2669747740_ea50af33a0-300x225.jpg" alt="" width="300" height="225" /></a></p>
<ol>
<li>Install Windows Vista from the factory first boot installer</li>
<li>Download Ubuntu 8.04 <strong>alternative</strong> install CD. The alternative install CD contains installer menus to encrypt your HD using <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">LVM</a> and <a href="http://luks.endorphin.org/">LUKS</a>.</li>
<li>For the sake of performance, we only crypt /home directory on Linux partition which contains all user editable files. All other files in Linux, maybe excluding configuration files in /etc, are open source and encrypting them only slows your application start-up times. <a href="http://blog.gnist.org/article.php?story=EncryptedSwapAndHomeUbuntu">It is possible to encrypt /home after install</a>, but it is much easier during the install time. <a href="http://users.piuha.net/martti/comp/ubuntu/en/cryptolvm.html">Here are instructions how to set up encrypted home partition with alternative install CD</a>.</li>
<li>After this comes the exciting part. You must encrypt the Windows system partition using Truecrypt. Since Truecrypt is going to overwrite Ubuntu&#8217;s Grub bootloader on Master Boot Record (MBR), <a href="http://ph.ubuntuforums.com/showpost.php?s=a35bb947b3593e4557135380109a40d7&amp;p=4786419&amp;postcount=10">some magic is needed (detailed instructions)</a>.
<ol>
<li>Install Truecrypt and overwrite MBR.</li>
<li>Boot Ubuntu from live CD. Alternative install CD doesn&#8217;t work as it does not have grub binary. You could also try to boot from your Linux partition by giving out manual kernel root file system parameters for the CD boot loader.</li>
<li>Back-up Truecrypt&#8217;s MBR to a file on /boot partition using dd</li>
<li>Add Truecrypt&#8217;s MBR as a chain boot loader in Grub</li>
<li>Rewrite MBR using Grub</li>
</ol>
</li>
</ol>
<p>For foreigners: You might want to keep <a href="http://www.zimmers.net/anonftp/pub/cbm/b/documents/keymap-us.gif">the US keymap</a> in hand, since the installer environment has  not necessarily keymap set up correctly.</p>
<p>Note: Since my HP Pavilion dv9000 laptop has two 250 GB hds, the actual setup is following: windows system partition, windows data partition, rest is set up for Linux using LVM in stripe RAID containing the root partition and the crypted home. This effectively gives near 100 MB/s read speed from two 5400 RPM hds.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2008/07/15/perfect-dual-boot-crypted-hard-disk-setup-with-truecrypt-and-luks/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

