<?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>info.michael-simons.eu &#187; memcached</title>
	<atom:link href="http://info.michael-simons.eu/tag/memcached/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.michael-simons.eu</link>
	<description>Just another nerd blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:26:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Phusion Passenger and memcache-client revisited</title>
		<link>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/</link>
		<comments>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 10:35:49 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=313</guid>
		<description><![CDATA[The last Passenger update brought some good explanation off the problems regarding Passenger and memcache-client (see here). Smart spawning of Passenger processes creates shared file descriptors. As the connections to memcached are sockets they are shared as well so data on them gets corrupted which is explained very nicely in the Passenger documentation: Example 1: [...]]]></description>
			<content:encoded><![CDATA[<p>The last <a href="http://www.modrails.com/">Passenger</a> update brought some good explanation off the problems regarding Passenger and memcache-client (see <a href="http://info.michael-simons.eu/2009/02/23/phusion-passenger-and-memcached-memcache-client/">here</a>). </p>
<p>Smart spawning of Passenger processes creates shared file descriptors. As the connections to memcached are sockets they are shared as well so data on them gets corrupted which is explained very nicely in the Passenger documentation: <a href="http://www.modrails.com/documentation/Users%20guide.html#_example_1_memcached_connection_sharing_harmful">Example 1: Memcached connection sharing (harmful)</a>.</p>
<p>The solution presented there works like a charm. The <em>reestablish_connection_to_memcached</em> line is actually not more than <em>CACHE.reset</em> where CACHE is the reference to the memcache connection.</p>
<p>After that change, spawning methods smart-lv2 and smart will work in connection with environment.rb configured memcache connections.</p>
<p><ins datetime="2009-03-25T15:15:15+00:00">Edit</ins>: As requested in the comments, a little example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">memcache_options = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:c_threshold</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10000</span>,
  <span style="color:#ff3333; font-weight:bold;">:compression</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
  <span style="color:#ff3333; font-weight:bold;">:debug</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
  <span style="color:#ff3333; font-weight:bold;">:namespace</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'some_ns'</span>,
  <span style="color:#ff3333; font-weight:bold;">:readonly</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
  <span style="color:#ff3333; font-weight:bold;">:urlencode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
CACHE = MemCache.<span style="color:#9900CC;">new</span> memcache_options
CACHE.<span style="color:#9900CC;">servers</span> = <span style="color:#996600;">'127.0.0.1:11211'</span>
<span style="color:#9966CC; font-weight:bold;">begin</span>
   PhusionPassenger.<span style="color:#9900CC;">on_event</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:starting_worker_process</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>forked<span style="color:#006600; font-weight:bold;">|</span>
     <span style="color:#9966CC; font-weight:bold;">if</span> forked
       <span style="color:#008000; font-style:italic;"># We're in smart spawning mode, so...</span>
       <span style="color:#008000; font-style:italic;"># Close duplicated memcached connections - they will open themselves</span>
       CACHE.<span style="color:#9900CC;">reset</span>
     <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># In case you're not running under Passenger (i.e. devmode with mongrel)</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">NameError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> error
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In this case, CACHE is the global constant that i use to access my memcache-client.</p>
<p>I guess you&#8217;ll need to do the same with the global Rails.cache object, but i&#8217;m not sure. Anyway, the above solution works for me. </p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=313&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_313" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.408 seconds -->

