<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<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/"
	>

<channel>
	<title></title>
	<link>http://blog.edhickey.com</link>
	<description>computers, music, what am i missing?</description>
	<pubDate>Sat, 04 Apr 2009 00:35:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Mysql, OSX Leopard and Ruby</title>
		<link>http://blog.edhickey.com/2009/04/03/mysql-osx-and-ruby/</link>
		<comments>http://blog.edhickey.com/2009/04/03/mysql-osx-and-ruby/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 00:34:04 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2009/04/03/mysql-osx-and-ruby/</guid>
		<description><![CDATA[My MacBook had a blowout the other day.  Sent it to Apple and they had to replace the hard drive.  That said, I&#8217;ve spent most of the day reinstalling everything.   I tried to use the ruby that comes with OSX, but was having too many issues so I went with a [...]]]></description>
			<content:encoded><![CDATA[<p>My MacBook had a blowout the other day.  Sent it to Apple and they had to replace the hard drive.  That said, I&#8217;ve spent most of the day reinstalling everything.   I tried to use the ruby that comes with OSX, but was having too many issues so I went with a basic install from source.</p>
<p>  The problem I had was when I tried to MySQL working.  I installed MySQL via the 64-bit .pkg they have on their site.  That took fine.  The issue was installing the mysql ruby gem.  I kept getting errors from extconf.rb about missing headers, etc.  After an hour of googling and trying everything from an OSX Ports install and compiling against the 32-bit MySQL files, I finally got it.</p>
<p>  The golden combo in the end was to install MySQL from source (<a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx">mysql-5.1.33-osx10.5-x86_64.tar</a>) but then don&#8217;t try to use the gem command to install the mysql gem.  Instead, I grabbed the latest source version of the gem <a href="http://www.tmtm.org/en/ruby/mysql/">here</a> and simply followed the install instructions<br />
<code><br />
% ruby ./setup.rb<br />
% ruby ./test.rb localhost root<br />
# ruby ./install.rb<br />
</code></p>
<p>And it works!<br />
Hopefully this helps someone else.  I know I&#8217;ll probably forget and need this in a year or less&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2009/04/03/mysql-osx-and-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>E.V.A.C. - Dj Mix @ The Church, Denver 2002</title>
		<link>http://blog.edhickey.com/2009/02/04/evac-dj-mix-the-church-denver-2002/</link>
		<comments>http://blog.edhickey.com/2009/02/04/evac-dj-mix-the-church-denver-2002/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 17:16:16 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2009/02/04/evac-dj-mix-the-church-denver-2002/</guid>
		<description><![CDATA[I haven&#8217;t posted much music-related in awhile so I figured I&#8217;d get back into it with a free download.
Of the 4 people who read this blog, probably none of them know that I was in an electronic much project named E.V.A.C.  The &#8220;group&#8221; consisted of me and Jeremy Goldstein. We released a few records [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t posted much music-related in awhile so I figured I&#8217;d get back into it with a free download.<br />
Of the 4 people who read this blog, probably none of them know that I was in an electronic much project named E.V.A.C.  The &#8220;group&#8221; consisted of me and <a href="http://www.q5studios.com">Jeremy Goldstein</a>. We released a few records (vinyl!) and played quite a few shows locally and nationally.  Towards the end of my stint, we gladly sold our soul to some ad agencies.  Hey, gotta pay the bills.</p>
<p>The mixset I&#8217;m posting today is from a show we played with <a href="http://www.tippermusic.net/" title="Tipper">Tipper</a> and <a href="http://www.virb.com/wreck" title="Salim Rafiq/DJ Wreck">Salim Rafiq (DJ Wreck)</a> when they were on their Fuel Records tour in 2002.  Tipper is one of the producers we admired since Day 1, so playing alongside him was pretty outstanding.  We decided that since we were playing with some fairly uncompromising musicians, that&#8217;d we&#8217;d bring The Thunder.  Generally when we DJ&#8217;d a club, we would hold back somewhat when choosing which tracks to play.  We definitely favored the dark, difficult and warped&#8230;and that&#8217;s not always what people want to hear after 3 Appletinis.  This time though, we basically went all out.</p>
<p><strong>Disclaimer:</strong> This isn&#8217;t the best DJ work we&#8217;ve done.  To shorten a potentially long story, we were scolded by the promoter about 10 minutes into our set with him yelling &#8220;You guys better stop playing all that dark shit or you&#8217;ll never play here again!&#8221;.  So instead of bowing to his asinine request, we decided to milk the open tab we had at the bar (that&#8217;s all we got &#8220;paid&#8221; that night) and continue to play what we planned on playing.  That said, we got pretty tipsy during the set.  As fun as it was, some of the mixes definitely show signs of intoxication.  </p>
<p>At any rate, hopefully you can appreciate the music even if the technically mastery wasn&#8217;t all there.<br />
<a href="/wp-content/uploads/2009/02/EVAC-Fuel_Tour_DJ_mix_Denver_2002.mp3">Download the mix</a></p>
<hr />
<h3>Tracklisting</h3>
<ol>
<li>Andrea Parker - The Swamp</li>
<li>Carl Finlow - Hardwired</li>
<li>Electronic Corporation - Elektronimechanik</li>
<li>Scuba Z - Hip Bounce (BLIM rmx)</li>
<li>Cause for Concern - Shiver (@33 RPM)</li>
<li>Tipper - SuperSport (Barge Charge&#8217;s Super Rollers rmx)</li>
<li>Subphonic - Vega Beach Party (Tipper rmx)</li>
<li>Wayward Soul - Electric Man</li>
<li>B.L.I.M. - Earth Man</li>
<li>A.S.A.P - Heavy Water</li>
<li>Adam Beyer - Remainings III (DK remix)</li>
<li>Dobrag - The Counterattack Part 2 (Jaws of Mylor) Groundloop remix</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2009/02/04/evac-dj-mix-the-church-denver-2002/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Memory leak in Ruby 1.8.6 String class</title>
		<link>http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/</link>
		<comments>http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 16:41:46 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[job]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/</guid>
		<description><![CDATA[So I ran into this memory leak about a year ago but had forgotten about it so I&#8217;m going to document it in the hopes I check my own blog next time I find it.  I came across the leak again when looking into why one of my apps was getting so bloated after [...]]]></description>
			<content:encoded><![CDATA[<p>So I ran into this memory leak about a year ago but had forgotten about it so I&#8217;m going to document it in the hopes I check my own blog next time I find it.  I came across the leak again when looking into why one of my apps was getting so bloated after running for a few days.  The leak has been reported in <a href="http://groups.google.com/group/god-rb/tree/browse_frm/thread/1cca2b7c4a581c2/9543ac469b0c44a0?rnum=11&#038;lnk=ol">numerous</a> <a href="http://rubyforge.org/tracker/?group_id=426&#038;atid=1698&#038;func=detail&#038;aid=19088">places</a> but doesn&#8217;t appear to have been patched in 1.8.6.</p>
<p>This should demonstrate it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Just a helper method to show the memory usage output</span>
<span style="color:#008000; font-style:italic;"># @NOTE: Won't work on Windows</span>
<span style="color:#9966CC; font-weight:bold;">def</span> log
  leak=<span style="color:#996600;">'fix'</span>
  ps = <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#40;</span>ps u <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#008000; font-style:italic;">#{Process.pid}).strip.split(/\n/).last.split(/\s+/)</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{ps[4]}     #{ps[5]}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># This leaks memory</span>
<span style="color:#9966CC; font-weight:bold;">def</span> bad
  <span style="color:#996600;">&quot;ruby+memory+leak&quot;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'+'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Defining a variable before the String#split</span>
<span style="color:#008000; font-style:italic;"># fixes the leak</span>
<span style="color:#9966CC; font-weight:bold;">def</span> good
  rm = <span style="color:#996600;">'+'</span>
  <span style="color:#996600;">&quot;ruby+memory+leak&quot;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span>rm<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;VSZ       RSS&quot;</span>
<span style="color:#006666;">500</span>_000.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span> |i|
  good
  log <span style="color:#9966CC; font-weight:bold;">if</span> i<span style="color:#006600; font-weight:bold;">%</span>100000 == 0 
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>Watch me leak!&quot;</span>
<span style="color:#006666;">500</span>_000.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span> |i|
  bad
  log <span style="color:#9966CC; font-weight:bold;">if</span> i<span style="color:#006600; font-weight:bold;">%</span>100000 == 0 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>
So the moral of the story is, make sure to define a variable in methods that use String#split, String#gsub and the like.  This doesn&#8217;t leak in ruby 1.8.4.  I haven&#8217;t checked 1.9, but I&#8217;ve heard it&#8217;s fixed there too.<br />
<a href="http://gist.github.com/31584">Here is</a> a more complete script demonstrating the issue with both class and instance methods (since <a href="http://opensynapse.net/post/24570619">some reporters</a> have mentioned it being strictly a class method problem).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Painful install of do_mysql ruby gem</title>
		<link>http://blog.edhickey.com/2008/11/03/painful-install-of-do_mysql-ruby-gem/</link>
		<comments>http://blog.edhickey.com/2008/11/03/painful-install-of-do_mysql-ruby-gem/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 23:55:41 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2008/11/03/painful-install-of-do_mysql-ruby-gem/</guid>
		<description><![CDATA[I spent too long today trying to get merb running on a CentOS box because I had to jump through a lot of hoops to get the do_mysql-0.9.6 gem installed.  I&#8217;m not really sure how to even sum up all the dead ends and changes I had to make, but I&#8217;ll try in the [...]]]></description>
			<content:encoded><![CDATA[<p>I spent too long today trying to get merb running on a CentOS box because I had to jump through a <strong>lot</strong> of hoops to get the do_mysql-0.9.6 gem installed.  I&#8217;m not really sure how to even sum up all the dead ends and changes I had to make, but I&#8217;ll try in the hopes of helping someone else (maybe myself in a month when I forget all this).I was trying for a long time to get the gem installed with a <code>gem install</code>, but ended up having to pull down the source and manually compile and install.Since we have our mysql libs in a non-standard dir on this box, I tried passing them as args to the initial install: </p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">--</span> --with-mysql-<span style="color: #007800;">include</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.0.62<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span> --with-mysql-<span style="color: #007800;">lib</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.0.62<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p> but got something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> -I. -I. -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>x86_64-linux -I. -DHAVE_MYSQL_H -DHAVE_MYSQL_QUERY -DHAVE_MYSQL_SSL_SET  -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>mysql <span style="color: #660033;">-g</span> <span style="color: #660033;">-pipe</span> <span style="color: #660033;">-m64</span> -D_GNU_SOURCE -<span style="color: #007800;">D_FILE_OFFSET_BITS</span>=<span style="color: #000000;">64</span> -D_LARGEFILE_SOURCE <span style="color: #660033;">-fno-strict-aliasing</span> <span style="color: #660033;">-fPIC</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span>   <span style="color: #660033;">-c</span> do_mysql_ext.cdo_mysql_ext.c: In <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000000; font-weight: bold;">`</span>cConnection_initialize<span style="color: #ff0000;">':do_mysql_ext.c:464: error: `MYSQL_OPT_RECONNECT'</span> undeclared <span style="color: #7a0874; font-weight: bold;">&#40;</span>first use <span style="color: #000000; font-weight: bold;">in</span> this <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>do_mysql_ext.c:<span style="color: #000000;">464</span>: error: <span style="color: #7a0874; font-weight: bold;">&#40;</span>Each undeclared identifier is reported only oncedo_mysql_ext.c:<span style="color: #000000;">464</span>: error: <span style="color: #000000; font-weight: bold;">for</span> each <span style="color: #000000; font-weight: bold;">function</span> it appears in.<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #c20cb9; font-weight: bold;">make</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>do_mysql_ext.o<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">1</span></pre></div></div>

<p>I found a few forum posts online and decided to statically set the MYSQL_OPT_RECONNECT variable on line 464 of ext/do_mysql_ext.c to TRUE which got me past that error, but no glory quite yet.  I then had to edit line 46 of the generated Makefile to look in my mysql include dir since that didn&#8217;t seem to take from my initial gem call:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">CPPFLAGS = -DHAVE_MYSQL_H -DHAVE_MYSQL_QUERY -DHAVE_MYSQL_SSL_SET  -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.0.62<span style="color: #000000; font-weight: bold;">/</span>include <span style="color: #660033;">-g</span> <span style="color: #660033;">-pipe</span> <span style="color: #660033;">-m64</span> -D_GNU_SOURCE -<span style="color: #007800;">D_FILE_OFFSET_BITS</span>=<span style="color: #000000;">64</span> -D_LARGEFILE_SOURCE <span style="color: #660033;">-fno-strict-aliasing</span></pre></div></div>

<p>Things seemed to be ok, but another install attempt failed because of some missing hoe tasks referenced by the Rakefile.  Apparently they are only in the full data_objects code (tasks/hoe.rb)&#8230;so the next step was to pull down the <a href="http://github.com/sam/do/tree/master">complete data_objects source</a>.A straight <code>rake install</code> didn&#8217;t work even after the Makefile and do_mysql_ext.c edits.  I was getting this error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">undefined method <span style="color: #000000; font-weight: bold;">`</span>add_development_dependency<span style="color: #ff0000;">' for #&lt;gem&gt;&lt;/gem&gt;</span></pre></div></div>

<p>Thanks to <a href="https://rubyforge.org/forum/message.php?msg_id=59709">this page</a>, I discovered it was related to my &#8220;old&#8221; version of rake (1.1.1).  So I upgraded to rake ver 1.3 and re-ran the install - still no go!I decided to just run each data_objects pkg one at a time.  I first did this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> data_objects <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; rake <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>&#8230;which worked!Then:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>do_mysql <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; rake <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Which also worked!  So, a recap:
<ol>
<li>Download full <a href="http://github.com/sam/do/tree/master">data_objects source</a></li>
<li>Upgrade rake to at least 1.2</li>
<li>Install just data_objects gem</li>
<li>Try to install do_mysql, if fails, edit Makefile and do_mysql_ext.c</li>
</ol>
<p>I know that&#8217;s pretty convoluted, so leave a comment if you&#8217;re having the same issue and want more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/11/03/painful-install-of-do_mysql-ruby-gem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ThinkingSphinx Rails plugin fork</title>
		<link>http://blog.edhickey.com/2008/09/15/thinkingsphinx-rails-plugin-fork/</link>
		<comments>http://blog.edhickey.com/2008/09/15/thinkingsphinx-rails-plugin-fork/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 21:28:03 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[job]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2008/09/15/thinkingsphinx-rails-plugin-fork/</guid>
		<description><![CDATA[I&#8217;ve been working on a fork of the ThinkingSphinx Rails plugin that has now been in production for over a week without issue.  The Freelancing Gods have done a great job writing easy-to-read code that&#8217;s fairly easy to extend.  Most areas of the code are solid, but we needed to squeeze more out of the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a fork of the <a href="http://ts.freelancing-gods.com/" target="_blank" title="link to ThinkingSphinx">ThinkingSphinx Rails plugin</a> that has now been in production for over a week without issue.  The Freelancing Gods have done a great job writing easy-to-read code that&#8217;s fairly easy to extend.  Most areas of the code are solid, but we needed to squeeze more out of the plugin to be able to use it on our environment.  In <a href="http://www.validclick.com" target="_blank">Validclick,</a> we deal with a massive database of keywords that need indexing very frequently.  The table in question is nearly 50mil rows and replicated out to dozens of MySQL servers, therefore schema changes are best avoided.</p>
<p>The original delta indexing method used in the TS plugin requires you add a tinyint column on all tables requiring delta indexing.  The code also automatically fires the reindexing process on <em>each</em> model update.  To address these 2 issues, I forked the original plugin and came up with some solutions.  So far they&#8217;ve worked great in production, your mileage may vary.</p>
<h3>Complex Delta&#8217;ing</h3>
<p>For the column issue, I stole some ideas from Evan Weaver&#8217;s <a href="http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/files/README.html" target="_blank">UltraSphinx plugin.</a>  While Evan has definitely contributed some amazing code (much of which I use daily), trying to extend his Sphinx plugin was a nightmare.  Maybe he&#8217;s just too smart for me, but that code gives me a headache when I read it!  The one great thing about his plugin is that you can specify a delta on any column, instead of just a boolean.  I stole that idea and put it in TS.  So now, instead of adding a tinyint/boolean column to your table and adding this in your model:</p>

<div class="wp_syntax"><div class="code"><pre class="rails rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  define_index <span style="color:#9966CC; font-weight:bold;">do</span>
    indexes <span style="color:#ff3333; font-weight:bold;">:name</span>
    set_property <span style="color:#ff3333; font-weight:bold;">:delta</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You could do this, which will use the table&#8217;s existing updated_on field to create the delta index of anything that has been changed in the past day (requiring no altering of your table):</p>

<div class="wp_syntax"><div class="code"><pre class="rails rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  define_index <span style="color:#9966CC; font-weight:bold;">do</span>
    indexes <span style="color:#ff3333; font-weight:bold;">:name</span>
    set_property <span style="color:#ff3333; font-weight:bold;">:delta</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:field <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:updated_on</span>, <span style="color:#ff3333; font-weight:bold;">:threshold</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 1.<span style="color:#5A0A0A; font-weight:bold;">day</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The code only supports datetime fields now, but that could likely be extended.  The original boolean-based deltas are still supported.</p>
<h3>Offline Indexing</h3>
<p>Having the Sphinx indexing process fire off on each record update just doesn&#8217;t scale.  If you have an API or a multi-record edit interface, you could ostensibly incur thousands of (nearly) simultaneous updates which would obviously cause issue on your Sphinx server.<br />
Even just simply having multiple mongrel process and (even worse) multiple servers running could cause indexing collisions or high server load.  So I added configuration setting that allows you to override the default delta indexing functionality.  Just slap this in your environment.rb and TS won&#8217;t call the indexer every time a model is changed:</p>

<div class="wp_syntax"><div class="code"><pre class="rails rails" style="font-family:monospace;">ThinkingSphinx.<span style="color:#9900CC;">offline_indexing</span> = <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>Note that this requires you to run the meta indexing on your own.  We run it through cron every 20 minutes.</p>
<h3>Extra rake tasks</h3>
<p>Another snag from the UltraSphinx codebase was some rake tasks.  They&#8217;re a bit different than in US, but the same general idea:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">rake thinking_sphinx:index         <span style="color:#008000; font-style:italic;"># Index data for all or 1 Sphinx indexes.</span>
rake thinking_sphinx:index:all     <span style="color:#008000; font-style:italic;"># Index data for all Sphinx indexes.</span>
rake thinking_sphinx:index:delta   <span style="color:#008000; font-style:italic;"># Index data for all or 1 Sphinx deltas.</span>
rake thinking_sphinx:index:merge   <span style="color:#008000; font-style:italic;"># Merges the core and delta indexes for all or 1 Sphinx deltas.</span></pre></div></div>

<p>All of the tasks except for index:all allow you to set a MODEL environment variable to denote which model you want to operate on.  The default is all pertinent indexes.  To reindex just the Account data, you could issue the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">MODEL=account rake thinking_sphinx:index</pre></div></div>

<p>I haven&#8217;t found any bugs yet, but there is surely room for improvement in the code.  I haven&#8217;t pulled in all of Freelancing Gods&#8217; latest changes, so that&#8217;s definitely on the list.  If you feel like following or contributing, <a href="http://github.com/bassnode/thinking-sphinx/tree/master" target="_blank" title="GitHub">my fork</a> is on <a href="http://github.com/bassnode/thinking-sphinx/tree/master" target="_blank" title="GitHub">GitHub</a>:</p>
<p>git clone git://github.com/bassnode/thinking-sphinx.git</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/09/15/thinkingsphinx-rails-plugin-fork/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mongrel memory usage</title>
		<link>http://blog.edhickey.com/2008/02/08/mongrel-memory-usage/</link>
		<comments>http://blog.edhickey.com/2008/02/08/mongrel-memory-usage/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 21:22:44 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[job]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2008/02/08/mongrel-memory-usage/</guid>
		<description><![CDATA[We run around 100 mongrels between all our servers.   90% of them serve hundreds of XML requests a second, around the clock.  We&#8217;ve been following the &#8217;scale-out&#8217; methodology, but it can only go so far before you have to look at squeezing more performance out of your hardware and software before buying [...]]]></description>
			<content:encoded><![CDATA[<p>We run around 100 mongrels between all our servers.   90% of them serve hundreds of XML requests a second, around the clock.  We&#8217;ve been following the &#8217;scale-out&#8217; methodology, but it can only go so far before you have to look at squeezing more performance out of your hardware and software before buying that next $3,000 server.</p>
<p>The problem we were having was, without a restart, 5 mongrels will eat all the memory (2GB) on any of our quad-core, 64bit servers in about 30 hours.     Note that this is not necessarily a generalization about mongrel but in my current application of it.   The mongrels in question are running rails code that creates around 1GB of text in the production.log per hour.   The bigger the production.log gets, the more memory mongrel/rails eats.  Clear the log, mongrel gets back its memory - no restart needed.  This doesn&#8217;t happen on our front-end GUI mongrels, just the ones  creating all the logs.<br />
<u><strong>Graph of available memory over the course of 1 day (</strong><strong>Ruby 1.8.4 / Mongrel 1.1.1)</strong></u></p>
<p><em>Rails production.log grows to around 1GB in size. </em>production.log only truncated at 1AM:</p>
<p><img src="http://blog.edhickey.com/wp-content/uploads/2008/01/free_mem_ruby184_mongrel111-no_rolloff.png" alt="free_mem_ruby184_mongrel111-no_rolloff.png" /></p>
<p>Rails production.log truncated every hour:</p>
<p><img src="http://blog.edhickey.com/wp-content/uploads/2008/01/free_mem_ruby184_mongrel111-with_rolloff.png" alt="free_mem_ruby184_mongrel111-with_rolloff.png" /></p>
<p>My first thought was that it was something in my code that was obviously leaking memory.  That was until I realized that just truncating the production.log freed the memory.  That leads me to believe the issue is either in rails and/or the Logger class.</p>
<p><a href="http://groups.google.com/group/god-rb/browse_frm/thread/1cca2b7c4a581c2/" target="_blank" title="god google group"><strong>UPDATE (2008/03/20): Tom Werner discovered leaks in Logger</strong></a></p>
<p>I&#8217;ve tried different versions of things: the situation looks only slightly better on ruby 1.8.6 than 1.8.4.   I&#8217;ve also tried older versions of mongrel without any luck.  I recently added the rails <a href="http://blog.pluron.com/2008/01/ruby-on-rails-i.html" target="_blank" title="Plugon blogpost">patches</a> by the guys at <a href="http://pluron.com" target="_blank">Pluron</a>  which helped out quite a bit with CPU usage (25% drop!) but not much with memory.</p>
<p>I&#8217;m mostly posting this for historical purposes.   I hope to have some time soon to get down and dirty with Valgrind or something similar to see where the memory is really going.   Hopefully I&#8217;ll have an update soon about how I solved the problem!   Any insight is welcome.</p>
<p><a href="http://pluron.com" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/02/08/mongrel-memory-usage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I am a workaholic</title>
		<link>http://blog.edhickey.com/2008/01/17/i-am-a-workaholic/</link>
		<comments>http://blog.edhickey.com/2008/01/17/i-am-a-workaholic/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 16:59:28 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[job]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/2008/01/17/i-am-a-workaholic/</guid>
		<description><![CDATA[The passionate worker doesn&#8217;t show up because she&#8217;s afraid of getting in trouble, she shows up because it&#8217;s a hobby that pays.I agree completely.  I try to explain this to my wife and she&#8217;s hard-pressed to understand.  But it&#8217;s true - I love what I do.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://sethgodin.typepad.com/seths_blog/2008/01/workaholics.html" target="_blank">The passionate worker doesn&#8217;t show up because she&#8217;s afraid of getting in trouble, she shows up because it&#8217;s a hobby that pays.</a><br class="webkit-block-placeholder" />I agree completely.  I try to explain this to my wife and she&#8217;s hard-pressed to understand.  But it&#8217;s true - I love what I do.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/01/17/i-am-a-workaholic/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An intro of sorts&#8230;</title>
		<link>http://blog.edhickey.com/2008/01/16/an-intro-of-sorts/</link>
		<comments>http://blog.edhickey.com/2008/01/16/an-intro-of-sorts/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 22:43:02 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[job]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/?p=7</guid>
		<description><![CDATA[This blog has more or less languished over the past couple years.  I never really got into the daily blogging rhythm, so there&#8217;s not much here to speak of.  That said, I&#8217;ve obtained a lot of experience and learned a lot over the past 2 years at my current job.  I figure I might as [...]]]></description>
			<content:encoded><![CDATA[<p>This blog has more or less languished over the past couple years.  I never really got into the daily blogging rhythm, so there&#8217;s not much here to speak of.  That said, I&#8217;ve obtained a lot of experience and learned a lot over the past 2 years at my current job.  I figure I might as well try to blog about it since it could prove useful to someone else.  And, if not, it will at least be a way for me to supplement my horrible memory.</p>
<p>So, a bit of history.  Over the past (almost) 2 years, I&#8217;ve worked for <a href="http://www.litmusmedia.com/" title="Litmus" target="_blank">Litmus Media</a> as a ruby developer.  We are a web company specializing in click fraud protection.  We were acquired by <a href="http://www.thinkpartnership.com" title="THK" target="_blank">Think Partnership</a> about the time I came onboard and not much has changed.  I was brought on to write an web-based advertising platform that would allow advertisers to create marketing campaigns to be distributed through our click-protected network.  The platform is called DirectAds and includes a web UI, XML service (for serving the ads) and click processor. </p>
<p>I choose the Ruby on Rails framework for various reasons.  The biggest reason was that I was tired of my current tools (perl, PHP, and tons of scattered libraries) and Rails looked like it was sizing up to be a great framework.  Plus, ruby just looked so <span style="font-style: italic" class="Apple-style-span">sexy</span> - how could I deny it?  So, 2 years later I can&#8217;t complain at all.  Although, like I mentioned, there were certainly hurdles to overcome when using this new, fancy-pants technology.  I plan to expand on my experiences in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2008/01/16/an-intro-of-sorts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sebastian Tellier vs. Radiohead</title>
		<link>http://blog.edhickey.com/2007/11/27/sebastian-tellier-vs-radiohead/</link>
		<comments>http://blog.edhickey.com/2007/11/27/sebastian-tellier-vs-radiohead/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 02:00:57 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/?p=6</guid>
		<description><![CDATA[A friend sent me a Sebastian Tellier song the other day that I quite liked.  Though, immediately upon hearing it I realized it sounded a lot like something off the new Radiohead album.  You be the judge:
Sebastian Tellier - La Ritournelle (Sessions, 2005)
YouTube
flash version w/ drums
Radiohead - Reckoner (In Rainbows, 2007)
YouTube
Not a direct [...]]]></description>
			<content:encoded><![CDATA[<p>A friend sent me a Sebastian Tellier song the other day that I quite liked.  Though, immediately upon hearing it I realized it sounded a lot like something off the new Radiohead album.  You be the judge:</p>
<p><strong>Sebastian Tellier - La Ritournelle</strong> (<em>Sessions</em>, 2005)<br />
<a href="http://www.youtube.com/watch?v=JlERiqDVRHs" target="_blank">YouTube</a><br />
<a href="http://www.boomkat.com/item.cfm?id=38179&#038;ljb=1&#038;tracks=63258&#038;type=music" target="_blank">flash version w/ drums</a></p>
<p><strong>Radiohead - Reckoner</strong> (<em>In Rainbows</em>, 2007)<br />
<a href="http://www.youtube.com/watch?v=KBalSWs5ngY" target="_blank">YouTube</a></p>
<p>Not a direct rip either way, but very similar.  Also, I&#8217;m not sure who wrote their&#8217;s first.  I&#8217;ve read reports online saying Radiohead played a version of Reckoner as far back as 2001.  At any rate, it&#8217;s a good riff!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2007/11/27/sebastian-tellier-vs-radiohead/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Carlton breaks it down</title>
		<link>http://blog.edhickey.com/2007/09/07/carltons-fuckin-it-up/</link>
		<comments>http://blog.edhickey.com/2007/09/07/carltons-fuckin-it-up/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 02:08:53 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[Random Bits]]></category>

		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://blog.edhickey.com/?p=5</guid>
		<description><![CDATA[Oh my goodness
A Carlton breakdance instructional?  I need it!
Yes, like the Carlton from The Fresh Prince of Bel-Air.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.collegehumor.com/video:1770257">Oh my goodness</a><br />
A Carlton breakdance instructional?  I need it!</p>
<p>Yes, like the Carlton from The Fresh Prince of Bel-Air.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edhickey.com/2007/09/07/carltons-fuckin-it-up/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
