<?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>chrisstreeter.com &#187; linux</title>
	<atom:link href="http://www.chrisstreeter.com/archive/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.chrisstreeter.com</link>
	<description>Chris Streeter&#039;s location on the Internet.</description>
	<lastBuildDate>Tue, 20 Sep 2011 15:53:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Python virtualenvwrapper and Logging</title>
		<link>http://www.chrisstreeter.com/archive/2011/01/792/python-virtualenvwrapper-and-logging</link>
		<comments>http://www.chrisstreeter.com/archive/2011/01/792/python-virtualenvwrapper-and-logging#comments</comments>
		<pubDate>Fri, 21 Jan 2011 03:51:03 +0000</pubDate>
		<dc:creator>streeter</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virtualenv]]></category>
		<category><![CDATA[virtualenvwrapper]]></category>

		<guid isPermaLink="false">http://www.chrisstreeter.com/?p=792</guid>
		<description><![CDATA[I ran into this issue, and couldn&#8217;t find a resolution anywhere online. Well, I figured it out, and thought that I&#8217;d put it online for others to find. The issue was that I got exception tracebacks when sourcing the /usr/local/bin/virtualenvwrapper.sh &#8230; <a href="http://www.chrisstreeter.com/archive/2011/01/792/python-virtualenvwrapper-and-logging">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I ran into this issue, and couldn&#8217;t find a resolution anywhere online. Well, I figured it out, and thought that I&#8217;d put it online for others to find.</p>
<p>The issue was that I got exception tracebacks when sourcing the <code>/usr/local/bin/virtualenvwrapper.sh</code> script upon bash initialization. However, the exception happens while Python is running it&#8217;s <a href="http://docs.python.org/library/atexit.html">atexit</a> handlers. So the stack was only 3 levels deep. I&#8217;m running <code>virtualenv</code> and <code>virtualenvwrapper</code> on my Ubuntu 9.04 server.<br />
<span id="more-792"></span> Here&#8217;s the output of the exception that I got:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>streeter<span style="color: #000000; font-weight: bold;">@</span>mail<span style="color: #7a0874; font-weight: bold;">&#93;</span>:~$ <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>virtualenvwrapper.sh
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/handlers.py&quot;</span>, line <span style="color: #000000;">72</span>, <span style="color: #000000; font-weight: bold;">in</span> emit
self.doRollover<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/handlers.py&quot;</span>, line <span style="color: #000000;">129</span>, <span style="color: #000000; font-weight: bold;">in</span> doRollover
os.rename<span style="color: #7a0874; font-weight: bold;">&#40;</span>self.baseFilename, dfn<span style="color: #7a0874; font-weight: bold;">&#41;</span>
OSError: <span style="color: #7a0874; font-weight: bold;">&#91;</span>Errno <span style="color: #000000;">13</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Permission denied
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/handlers.py&quot;</span>, line <span style="color: #000000;">71</span>, <span style="color: #000000; font-weight: bold;">in</span> emit
<span style="color: #000000; font-weight: bold;">if</span> self.shouldRollover<span style="color: #7a0874; font-weight: bold;">&#40;</span>record<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/handlers.py&quot;</span>, line <span style="color: #000000;">145</span>, <span style="color: #000000; font-weight: bold;">in</span> shouldRollover
self.stream.seek<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #666666; font-style: italic;">#due to non-posix-compliant Windows feature</span>
ValueError: I<span style="color: #000000; font-weight: bold;">/</span>O operation on closed <span style="color: #c20cb9; font-weight: bold;">file</span>
Error <span style="color: #000000; font-weight: bold;">in</span> atexit._run_exitfuncs:
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/atexit.py&quot;</span>, line <span style="color: #000000;">24</span>, <span style="color: #000000; font-weight: bold;">in</span> _run_exitfuncs
func<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">*</span>targs, <span style="color: #000000; font-weight: bold;">**</span>kargs<span style="color: #7a0874; font-weight: bold;">&#41;</span>
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/__init__.py&quot;</span>, line <span style="color: #000000;">1508</span>, <span style="color: #000000; font-weight: bold;">in</span> shutdown
h.flush<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/__init__.py&quot;</span>, line <span style="color: #000000;">754</span>, <span style="color: #000000; font-weight: bold;">in</span> flush
self.stream.flush<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
ValueError: I<span style="color: #000000; font-weight: bold;">/</span>O operation on closed <span style="color: #c20cb9; font-weight: bold;">file</span>
Error <span style="color: #000000; font-weight: bold;">in</span> sys.exitfunc:
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/atexit.py&quot;</span>, line <span style="color: #000000;">24</span>, <span style="color: #000000; font-weight: bold;">in</span> _run_exitfuncs
func<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">*</span>targs, <span style="color: #000000; font-weight: bold;">**</span>kargs<span style="color: #7a0874; font-weight: bold;">&#41;</span>
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/__init__.py&quot;</span>, line <span style="color: #000000;">1508</span>, <span style="color: #000000; font-weight: bold;">in</span> shutdown
h.flush<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
File <span style="color: #ff0000;">&quot;/usr/lib/python2.6/logging/__init__.py&quot;</span>, line <span style="color: #000000;">754</span>, <span style="color: #000000; font-weight: bold;">in</span> flush
self.stream.flush<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
ValueError: I<span style="color: #000000; font-weight: bold;">/</span>O operation on closed <span style="color: #c20cb9; font-weight: bold;">file</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>streeter<span style="color: #000000; font-weight: bold;">@</span>mail<span style="color: #7a0874; font-weight: bold;">&#93;</span>:~$</pre></div></div>

<p>As you can see, not a lot to go with. So it seems that virtualenvwrapper does some logging, and it looks like the logging module wants to rename that logfile. Digging even deeper, the logging module wants to rotate the logfile because it got too big. Well, where is the log file? Turns out that virtualenvwrapper sets up a logfile called <code>hook.log</code> at the root of the <code>WORKON_HOME</code> environment variable. My <code>WORKON_HOME</code> is set to <code>/usr/local/pythonenv</code> and lo and behold, that directory was not writeable by my logged in user.  Thats an easy fix. Just change the permissions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisstreeter.com/archive/2011/01/792/python-virtualenvwrapper-and-logging/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Benchmarking Redis and PRedis</title>
		<link>http://www.chrisstreeter.com/archive/2010/01/434/benchmarking-redis-and-predis</link>
		<comments>http://www.chrisstreeter.com/archive/2010/01/434/benchmarking-redis-and-predis#comments</comments>
		<pubDate>Sat, 16 Jan 2010 06:51:37 +0000</pubDate>
		<dc:creator>streeter</dc:creator>
				<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[predis]]></category>

		<guid isPermaLink="false">http://www.chrisstreeter.com/?p=434</guid>
		<description><![CDATA[At work, I recently was tasked with looking into some NoSQL solutions for upcoming projects. For various reasons, I focused on the open source Redis project. Redis looks to be adding new features quickly and seemed to be a great &#8230; <a href="http://www.chrisstreeter.com/archive/2010/01/434/benchmarking-redis-and-predis">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At work, I recently was tasked with looking into some <a href="http://en.wikipedia.org/wiki/NoSQL" target="_blank">NoSQL</a> solutions for upcoming projects. For various reasons, I focused on the <a title="Redis" href="http://code.google.com/p/redis/" target="_blank">open source Redis</a> project. Redis looks to be adding new features quickly and seemed to be a great potential solution.</p>
<p>I then started looking into PHP clients as our current environment is mostly PHP. We require that the client support <a href="http://en.wikipedia.org/wiki/Consistent_hashing" target="_blank">consistent hashing</a>, and, from a quick search, a couple turned up. <a title="PRedis" href="http://github.com/nrk/predis/" target="_blank">PRedis</a> seemed to offer the most potential, and after some quick tests, also seemed to offer the greatest performance. So I set up a more elaborate benchmark of the the client and server package.</p>
<p>My test setup involved using 5 servers with between 2 and 5 enabled at a time on the clients (ie. I disabled up to 3 of the servers in the client configurations). For performance, I configured the servers to never write to disk, though periodically syncing to disk should not cause too much of a performance loss. In fact performance was most greatly affected by forcing an fsync after every write. I then had 9 other client boxes running the same code base, with all 9 enabled for each test.</p>
<p>Each client would start a master PHP process that forked 20, 30 or 40 child processes to simulate greater and greater load. Each forked PHP process then did 10,000 SETs on random keys with 4 byte payloads (early tests showed that payload size didn&#8217;t drastically affect the results). I was using the <a href="http://github.com/nrk/predis/tree/php5.2_backport" target="_blank">PHP 4.2.6 branch of the PRedis client</a>, and had optimized it a bit so that it did fewer counts of the consistent hash array. I made the optimizations based on some results after profiling the code. I then had the master PHP process on each box repeat the test 5 times to help to average the test results.</p>
<p>I used dsh to start the test simultaneously on all the clients, timing how long it took the dsh process to start and finish executing. This was the amount of time it took to execute (5 repeats) * (9 client boxes) * (20, 30 or 40 client processes / box) * (10,000 requests) = X total requests. I then graphed the results below.</p>
<div id="attachment_441" class="wp-caption aligncenter" style="width: 483px"><a href="http://www.chrisstreeter.com/wp-content/uploads/2010/01/redis.png"><img class="size-full wp-image-441 " title="Graphing Requests / Second With Redis and PRedis" src="http://www.chrisstreeter.com/wp-content/uploads/2010/01/redis.png" alt="Graphing Requests / Second With Redis and PRedis" width="473" height="267" /></a><p class="wp-caption-text">Graphing Requests / Second With Redis and PRedis</p></div>
<p>This ended up showing that with 9 clients, going up to 4 servers was the point of diminishing returns. Adding the fifth server (with that client box count) did not increase throughput, but rather, the throughput went down. The reason for this is most likely a combination of network interface contention on each client and higher overhead from consistent hashing. So with 9 clients, I found that the sweet spot, with my setup, was 4 servers. By adding more clients, along with more servers, the throughput would increase, instead of the decrease I was starting to see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisstreeter.com/archive/2010/01/434/benchmarking-redis-and-predis/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GMail IMAP Backup With mbsync on Ubuntu</title>
		<link>http://www.chrisstreeter.com/archive/2009/04/305/gmail-imap-backup-with-mbsync-on-ubuntu</link>
		<comments>http://www.chrisstreeter.com/archive/2009/04/305/gmail-imap-backup-with-mbsync-on-ubuntu#comments</comments>
		<pubDate>Fri, 01 May 2009 07:56:06 +0000</pubDate>
		<dc:creator>streeter</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[isync]]></category>
		<category><![CDATA[mbsync]]></category>

		<guid isPermaLink="false">http://www.chrisstreeter.com/?p=305</guid>
		<description><![CDATA[Well, it sure has been a while since my last post on here. So I thought I&#8217;d kick it off with a discussion of how I went about getting my email backed up. First, a description of my situation. I &#8230; <a href="http://www.chrisstreeter.com/archive/2009/04/305/gmail-imap-backup-with-mbsync-on-ubuntu">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, it sure has been a while since my last post on here. So I thought I&#8217;d kick it off with a discussion of how I went about getting my email backed up.</p>
<p>First, a description of my situation. I run all my email through GMail. I enjoy the interface and the fact that it is a cloud service; I can access my email seamlessly on my phone, my home computer, my work computer, some other computer, etc. However, I don&#8217;t want to lose all that information. Google is great, but who is to say that something terrible won&#8217;t happen and some (or all) of my mail is lost? So I wanted to setup some sort of backup. And then once I got that setup, make it automated.</p>
<p>At home, I run an <a href="http://www.ubuntu.com/">Ubuntu</a> box, that I just upgraded to 9.04, <a href="http://www.ubuntu.com/news/ubuntu-9.04-desktop">Jaunty Jackalope</a>. This machine primarily serves as a media box, hosting video that <a href="http://pytivo.armooo.net/">streams to my Tivo</a> off the 1.5TB RAID 5 array. I also use it as a <a href="http://www.kremalicious.com/2008/06/ubuntu-as-mac-file-server-and-time-machine-volume/">network mounted TimeMachine</a> box as well. Since I have extra storage on it, I figured I&#8217;d get something to sync my mail over IMAP periodically, and then I have a nice little backup.</p>
<p>After some searching, I came across <a href="http://el-tramo.be/blog/gmail-mbsync">two</a> <a href="http://blog.rectalogic.com/2007/11/automated-gmail-backup-via-imap.html">sites</a> that had instructions using the utility <a href="http://isync.sourceforge.net/mbsync.html">mbsync</a> (<a href="http://isync.sourceforge.net/">formerly isync</a>). I found that following the instructions worked pretty well, though I had to customize the patch provided to get it to work with the version provided by Ubuntu.  And then I thought I&#8217;d detail my steps here for others to see.<br />
<span id="more-305"></span></p>
<ol>
<li>First, enable IMAP in your GMail account.</li>
<li>Install the dependencies for mbsync:
<pre><code>sudo apt-get install libc6 libdb4.8 libdb-dev libdb4.8-dev libssl0.9.8 libssl-dev</code></pre>
</li>
<li>Get the source for mbsync on Ubuntu with:
<pre><code>sudo apt-get source isync</code></pre>
<p>This will download the source for mbsync and create a directory (in your current directory) named isync-1.0.4 (Yes, I know it is called isync. That is a legacy name).</li>
<li>Now the normal mbsync install works just fine. However, it doesn&#8217;t support recursive directories. I use GMail labels setup to provide a hierarchy using forward slashes. It turns out that the fix to get mbsync to support directories like this is really easy to do and someone went through the trouble to get it to work. However, it doesn&#8217;t quite work on the version of the code packaged with Ubuntu. So I had to modify the patch a bit. The patch I created can be found <a href="http://www.chrisstreeter.com/wp-content/uploads/2009/04/recursive_imap_ubuntu.patch">here</a>.  Download it and put it somewhere on your system. To apply the patch, change directories into the isync-1.0.4 directory that was just downloaded and run:
<pre><code>patch -p1 &lt; /path/to/patch/file/recursive_imap_ubuntu.patch</code></pre>
<p>Once you&#8217;ve patched the directory, configure (<code>./configure</code>), build (<code>make</code>) and install (<code>sudo make install</code>).</li>
<li>Now you should have an executable <code>mbsync</code> in your path. So it is time to start preparing to do the initial sync. Choose a place to store your backups. I chose
<pre><code>/export/backups/mail/</code></pre>
</li>
<li>We want to connect to Google securely which means you&#8217;ll need the latest SSL certificates. To get those, use the openssl client on your machine. Run:
<pre><code>openssl s_client -connect imap.gmail.com:993 -showcerts</code></pre>
<p>which should show two blocks of</p>
<pre><code>-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----</code></pre>
<p>in the output. You&#8217;ll want to take each block (including the BEGIN/END CERTIFICATE lines), and put each of them into their own file. I put the first one in a file <code>gmail.crt</code> and the second one in the file <code>google.crt</code> (since the first signs imap.gmail.com which is signed by Google Internet Authority, the second certificate).</li>
<li>The second certificate, the one for the Google Internet Authority, is signed by Equifax. So we&#8217;ll need Equifax&#8217;s certificate also. An as it turns out, Ubuntu has a copy of Equifax&#8217;s certificate already sitting in the repositories. Just run
<pre><code>sudo apt-get install ca-certificates</code></pre>
<p>to get the latest CA certificates. After installing the CAs, Equifax&#8217;s CA sits at <code>/usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt</code>, which we&#8217;ll need in the configuration file in the next step.</li>
<li>Now we can write the configuration file we are going to use. Here is a copy of mine:
<pre><code>IMAPAccount gmail
Host imap.gmail.com
User <em>yourusername@gmail.com</em>
UseIMAPS yes
CertificateFile /export/backups/mail/gmail.crt
CertificateFile /export/backups/mail/google.crt
CertificateFile /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt&nbsp;

IMAPStore gmail-remote
Account gmail

MaildirStore gmail-local
Path /export/backups/mail/gmail/
Inbox /export/backups/mail/gmail/Inbox

</code></pre>
<pre><code>Channel gmail
Master :gmail-remote:
Slave :gmail-local:
# Exclude everything under the internal [Gmail] folder, except the interesting folders
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"
Create Slave
Sync Pull
SyncState *</code></pre>
<p>Check out the Patterns line. That is where you would include or exclude various labels. All lables are stored at the root of the hierarchy, with the special directory [Gmail] having things like &#8216;Sent Mail&#8217;, &#8216;Spam&#8217;, &#8216;Starred&#8217;, etc in it. I wanted to exclude all the items in the [Gmail] directory except for the ones listed. The &#8216;*&#8217; at the beginning includes all other labels. You will also want to change the Path and Inbox lines to point to your mail location, as well as the first two CertificateFile lines. Also, be sure to enter your actual GMail login on the User line. Now save this file somewhere. Note: saving it as ~/.mbsyncrc will cause it to be automatically loaded when mbsync is run, meaning you don&#8217;t need to specify which config file with the -c option.</li>
<li>Now go ahead and test it out by listing the labels in your account with the command <code>mbsync -l -c /path/to/the/configfile.rc gmail</code>. Running it will look like this and ask you for your password:
<pre><code>[streeter@scout]:~$ mbsync -l -c ~/.mbsyncrc gmail
Reading configuration file /home/streeter/.mbsyncrc
Resolving imap.gmail.com... ok
Connecting to 209.85.199.109:993... ok
Connection is now encrypted
Logging in...
Password (<em>yourusername@gmail.com</em>@imap.gmail.com):
Channel gmail
lists/code
bills
archive/cron
archive/classes
archive/work
[Gmail]/Starred
[Gmail]/Sent Mail
[Gmail]/All Mail
INBOX
@followup
[streeter@scout]:~$</code></pre>
<p>If you see something like this, then it worked! Now just go ahead and start your first mail download with <code>mbsync -c /path/to/the/configfile.rc gmail</code> And then you get to wait while it finishes which can take a while depending on how much mail you have.</li>
</ol>
<p>You can go an extra step and save your password in the file. If you add the line <code>Pass <em>yourpasswordhere</em></code> right after the User line, you won&#8217;t be asked for your password and can then setup a cronjob to automatically keep mail locally on a schedule. However, your password for your Google Account then is stored in cleartext on your machine. So only do this is you absolutely know what you are doing and who can access the machine.</p>
<p>Hopefully this becomes useful for people.</p>
<p><strong>Update 4/18/2011:</strong></p>
<p>I just updated the directions slightly for Ubuntu 10.10 Maverick Meerkat. For Maverick, I had to also install <code>libssl-dev</code> to get it to work with recursive directories.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisstreeter.com/archive/2009/04/305/gmail-imap-backup-with-mbsync-on-ubuntu/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

