Urban Hafner : Tag stable, everything about stable http://bettong.net/tag/stable.rss en-us 40 Stable Typo on Textdrive <p>This <a href="http://typosphere.org/">Typo</a> blog is hosted on <a href="http://textdrive.com/">Textdrive</a>, which is a really nice hosting company. More in the style of the <em>guys next door</em> than your average company that just wants to make money.</p> <p>One problem though is that I have a shared account on one of their severs and therefore have rather strict limits on the number of processes I can run and their memory consumption. This is of course understandable as otherwise it wouldn&#8217;t be possible for them to offer such accounts. The problem I had for a long time with this was that my blog consumed quite some memory and got killed quite regularly. To keep it running most of the times I created a cron job that I ran 4 times a day to kill my <a href="http://rubyonrails.org/">Rails</a> fcgi instance and spawn a new one:</p> <div class="textmate-source twilight"> <pre class="textmate-source"><span class="source source_shell"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_shell"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_shell">#</span>!/bin/sh </span>APP=www ROOT=/users/home/hafner/bettong.net/<span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>APP</span> TMP=/users/home/hafner/var/run <span class="comment comment_line comment_line_number-sign comment_line_number-sign_shell"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_shell">#</span> Kill the old process </span>date kill -9 <span class="string string_interpolated string_interpolated_backtick string_interpolated_backtick_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">`</span>cat $TMP/$APP-0.pid<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">`</span></span> sleep 1 <span class="comment comment_line comment_line_number-sign comment_line_number-sign_shell"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_shell">#</span> Start a new one </span>RAILS_ENV=production /usr/local/bin/spawn-fcgi -f <span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>ROOT</span>/public/dispatch.fcgi \ -s <span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>TMP</span>/<span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>APP</span>-0.socket -P <span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>TMP</span>/<span class="variable variable_other variable_other_normal variable_other_normal_shell"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_shell">$</span>APP</span>-0.pid</span></pre> </div> <p>Unfortunately that didn&#8217;t always work. Sometimes the <code>spawn-fcgi</code> exited complaining that I couldn&#8217;t allocate enough memory. But it worked well enough to keep the site running often enough.</p> <p>Some days ago while restoring my Typo database (don&#8217;t worry, Typo didn&#8217;t mess up anything, it was entirely my fault that I deleted all comments while only trying to delete the spam &#8230; Oh, well) I noticed that the session table was quite full. So I created another cron script that would remove all session entries older that 3 days:</p> <div class="textmate-source twilight"> <pre class="textmate-source"><span class="source source_shell"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_shell"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_shell">#</span>!/bin/sh </span>echo <span class="string string_quoted string_quoted_double string_quoted_double_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">"</span>Clear Typo session table<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">"</span></span> /usr/local/bin/ruby /home/hafner/bettong.net/www/script/runner \ <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>ActiveRecord::Base.connection.delete("DELETE FROM sessions WHERE updated_at &lt; now() - INTERVAL 72 HOUR")<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span> </span></pre> </div> <p>Interestingly though since then my blog has been running much more stable (i.e. the <code>restart-rails.sh</code> cron job always had to kill the Rails fcgi before spawning a new one which certainly hasn&#8217;t been the case before). So I&#8217;ve now reduced the number of times <code>restart-rails.sh</code> is called to twice a day. So maybe the whole contents of the session table is loaded into memory and that caused the process to be so big. I&#8217;ll see how the process behaves when running for half a day and if that works out I&#8217;ll gradually increase the running time of the process. I&#8217;ll report back to you when I have some more data.</p> Sun, 01 Apr 2007 19:00:23 +0000 urn:uuid:2c914c40-cbf6-4e8e-ac60-f4f2c8a3a489 urban@bettong.net (Urban Hafner) http://bettong.net/2007/04/01/stable-typo-on-textdrive#comments web memory stable textdrive blog typo http://bettong.net/trackbacks?article_id=stable-typo-on-textdrive&day=01&month=04&year=2007 http://bettong.net/2007/04/01/stable-typo-on-textdrive