<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title></title>
  <link href="http://clemensp.com/atom.xml" rel="self"/>
  <link href="http://clemensp.com/"/>
  <updated>2012-01-05T20:25:52-05:00</updated>
  <id>http://clemensp.com/</id>
  <author>
    <name>Clemens Park</name>
    
  </author>

  
  <entry>
    <title>Keeping Passenger Under Control</title>
    <link href="http://clemensp.com/blog/2011/12/23/keeping-passenger-under-control/"/>
    <updated>2011-12-23T10:03:00-05:00</updated>
    <id>http://clemensp.com/blog/2011/12/23/keeping-passenger-under-control</id>
    <content type="html">&lt;h2&gt;The mysterious &amp;#8220;memory leak&amp;#8221;&lt;/h2&gt;

&lt;p&gt;Recently at my workplace, we started to migrate one of our projects from
Rails 2 to Rails 3.1.  Everything seemed to go pretty well.  Then one day,
I started noticing my development machine crawling to a halt for no
apparent reason.  I could see that the memory was full and swapping.  My
initial reaction was that some sort of memory leak was introduced during
the Rails 3 migration, as I also discovered that another colleague was
experiencing the same issue.  After going through a quick process of
&lt;code&gt;kill -9&lt;/code&gt; elimination, the culprit turned out to be Passenger
Standalone.&lt;/p&gt;

&lt;h2&gt;Checking Passenger&amp;#8217;s memory profile&lt;/h2&gt;

&lt;p&gt;Some quick googling turned up the command &lt;code&gt;passenger-memory-stats&lt;/code&gt;.  The
tool shows details regarding the Apache/Nginx processes&amp;#8217; memory profiles,
as well as the Passenger processes&amp;#8217; memory profiles.  I quickly realized
that passenger uses 6 worker processes by default.&lt;/p&gt;

&lt;p&gt;One thing that my team quickly realized during the Rails 3 migration was
that Rails 3 has a much larger overhead in development mode than Rails
2.  This quickly lead to a substantial amount of the dev machine&amp;#8217;s
memory being utilized when passenger was run and a few requests were
made.  In my case, I had also started using gnome-shell, which took up a
good chunk of memory, and that compounded with 6 memory-intensive workers
meant a machine running out of memory.&lt;/p&gt;

&lt;p&gt;I ended up spending some time to find out documentations on how to
configure the number of worker instances.  Much to my surprise, I was
not able to find any information on how to do this for standalone
Passenger.&lt;/p&gt;

&lt;p&gt;It was time to start digging into Passenger&amp;#8217;s internal&amp;#8217;s.&lt;/p&gt;

&lt;h2&gt;Discovering how to configure nginx for standalone Passenger&lt;/h2&gt;

&lt;p&gt;A quick grep for passenger_max_pool_size under the passenger gem root
directory turned up this file: &lt;code&gt;phusion_passenger/templates/standalone/config.erb&lt;/code&gt;.
In the file, I quickly saw these two hopeful looking lines:&lt;/p&gt;

&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;phusion_passenger/templates/standalone/config.erb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class=&#8217;line&#8217;&gt;1&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&#8217;code&#8217; width=&#8217;100%&#8217;&gt;&lt;pre&gt;&lt;code class=&#8217;erb&#8217;&gt;&lt;div class=&#8217;line&#8217;&gt;&lt;span class=&quot;x&quot;&gt;passenger_max_pool_size &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:max_pool_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;&lt;span class=&quot;x&quot;&gt;passenger_min_instances &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:min_instances&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;I proceeded to replace the two erb tags with 2 and 1 respectively.
After restarting passenger and running &lt;code&gt;passenger-memory-stats&lt;/code&gt;, I saw
only two passenger workers.  Success!!&lt;/p&gt;

&lt;h2&gt;Looking for a better solution&lt;/h2&gt;

&lt;p&gt;Modifying the nginx config template worked.  However, modifying the gem
directly was not an ideal solution.  One option that I had was to fork
the gem and modify the template, but that also did not seem like a clean
solution for this problem.  So I started digging a bit further into
passenger.  A grep for &amp;#8216;config.erb&amp;#8217; turned up this line:
&lt;code&gt;lib/phusion_passenger/standalone/command.rb:179: template_filename = File.join(TEMPLATES_DIR, &quot;standalone&quot;, &quot;config.erb&quot;)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A quick scan through the file revealed this bit of code:&lt;/p&gt;

&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;lib/phusion_passenger/standalone/command.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class=&#8217;line&#8217;&gt;1&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;2&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;3&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;4&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;5&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;6&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;7&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;8&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;9&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;10&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&#8217;code&#8217; width=&#8217;100%&#8217;&gt;&lt;pre&gt;&lt;code class=&#8217;ruby&#8217;&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;parse_options!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;description&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;c1&quot;&gt;# cut&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;n&quot;&gt;global_config_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;HOME&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;LOCAL_DIR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;standalone&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exist?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;global_config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;      &lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;phusion_passenger/standalone/config_file&amp;#39;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defined?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ConfigFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;      &lt;span class=&quot;no&quot;&gt;ConfigFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:global_config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;global_config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;      &lt;span class=&quot;vi&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;merge!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;global_options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;c1&quot;&gt;# cut&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This showed that the template was configurable, by looking at
&lt;code&gt;~/.passenger/standalone/config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A quick peek into the ConfigFile class showed this initializer:&lt;/p&gt;

&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;lib/phusion_passenger/standalone/config_file.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class=&#8217;line&#8217;&gt;1&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;2&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;3&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;4&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;5&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;6&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;7&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;8&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;9&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&#8217;code&#8217; width=&#8217;100%&#8217;&gt;&lt;pre&gt;&lt;code class=&#8217;ruby&#8217;&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;vi&quot;&gt;@context&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;vi&quot;&gt;@filename&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;r&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;      &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;LOCK_SH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;      &lt;span class=&quot;nb&quot;&gt;instance_eval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;It looks like Passenger reads in the local config file, and evals the content.
Looking at the content of config_file.rb, it contains these two methods:&lt;/p&gt;

&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;config_file.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class=&#8217;line&#8217;&gt;1&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;2&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;3&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;4&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;5&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;6&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;7&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;8&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&#8217;code&#8217; width=&#8217;100%&#8217;&gt;&lt;pre&gt;&lt;code class=&#8217;ruby&#8217;&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max_pool_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;n&quot;&gt;allowed_contexts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:max_pool_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:global_config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;vi&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:max_pool_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;min_instances&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;    &lt;span class=&quot;vi&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:min_instances&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Therefore, inside my local config file, I added these two lines:&lt;/p&gt;

&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;~/.passenger/standalone/config&lt;/span&gt;&lt;/figcaption&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class=&#8217;line&#8217;&gt;1&lt;/span&gt;
&lt;span class=&#8217;line&#8217;&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&#8217;code&#8217; width=&#8217;100%&#8217;&gt;&lt;pre&gt;&lt;code class=&#8217;ruby&#8217;&gt;&lt;div class=&#8217;line&#8217;&gt;&lt;span class=&quot;n&quot;&gt;max_pool_size&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;/div&gt;&lt;div class=&#8217;line&#8217;&gt;&lt;span class=&quot;n&quot;&gt;min_instances&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Running &lt;code&gt;passenger-memory-stats&lt;/code&gt; after restarting Passenger showed that
there were infact 2 workers up and running.  Success for real!!&lt;/p&gt;

&lt;p&gt;I definitely appreciated Passenger giving the option to configure nginx
unintrusively, and it was also nice to realize that there were no memory
leaks after all.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Copy and Pasting in Vim</title>
    <link href="http://clemensp.com/blog/2011/08/25/copy-and-pasting-in-vim/"/>
    <updated>2011-08-25T00:02:00-04:00</updated>
    <id>http://clemensp.com/blog/2011/08/25/copy-and-pasting-in-vim</id>
    <content type="html">&lt;h2&gt;How I got to learn vim registers&lt;/h2&gt;

&lt;p&gt;One of the things that bugged me the most when I was learning Vim was
copy and pasting.&lt;/p&gt;

&lt;p&gt;For example, I would copy a line with: &lt;code&gt;yy&lt;/code&gt;.  Then
I would go to the section I wanted to put the yanked line, and of
course, I would see a line that I had to delete first, so without
thinking, I would type: &lt;code&gt;dd&lt;/code&gt;.  I would then quickly realize that
I had lost the line that I copied, go up to the copied line, yank the
line again, go down to the section again, and finally paste it.&lt;/p&gt;

&lt;p&gt;Another case where copy and pasting bugged me was copying to/from the
system clipboard.  For example, I had no idea how to copy and paste
between different Vim windows.  I also had no idea how to copy from
external pages into Vim other than highlighting the text from the
external page, going into insert mode in Vim, and middle-clicking the
mouse.&lt;/p&gt;

&lt;p&gt;After feeling this limitation countless times, I finally decided to
learn how the Vim registers worked, and how I could copy and paste at
will.&lt;/p&gt;

&lt;h2&gt;Vim registers&lt;/h2&gt;

&lt;p&gt;Vim has something called registers, where various strings are stored,
depending on the context and what actions you have taken.&lt;/p&gt;

&lt;p&gt;For example, the &amp;#8221; register is Vim&amp;#8217;s default register, so when you yank
or delete lines, they go into that register by default.  The % register
holds the relative path of the current file.  You can view the contents
of these registers by typing &lt;code&gt;:reg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can perform actions with these registers by typing &amp;#8220;, followed by
the register name, then the action you would like to perform.&lt;/p&gt;

&lt;p&gt;For example, if you would like to paste the current file&amp;#8217;s relative path
twice, you would type &lt;code&gt;&quot;%2p&lt;/code&gt;.  You can achieve the effect of the
usual &lt;code&gt;p&lt;/code&gt; with &lt;code&gt;&quot;&quot;p&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;The null register&lt;/h2&gt;

&lt;p&gt;At this point, you&amp;#8217;re probably wondering how this helps with the first
issue I had with Vim, which is how I can avoid overwriting the content
that I yanked in Vim.  This is solved by using the _ register, which
is Vim&amp;#8217;s null register.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s say you&amp;#8217;ve copied a line with &lt;code&gt;yy&lt;/code&gt;,
and you have a line that you want to delete without losing the line
you&amp;#8217;ve yanked.  You can do that by typing &lt;code&gt;&quot;_dd&lt;/code&gt;.  Want to delete
lines 38 to 43 without overwriting the yanked line?  No problem with
&lt;code&gt;:38,43d_&lt;/code&gt;.  Alternatively, you can select those lines in visual
mode, and type &lt;code&gt;:d_&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Copy and pasting to and from the system register&lt;/h2&gt;

&lt;p&gt;To solve the second issue I had, I used two other special Vim registers,
namely the * and + registers.  The * register is where content that you
highlight in linux operating systems go to, and the + register is where
content that you copy/cut with &lt;code&gt;Ctrl+C&lt;/code&gt; or &lt;code&gt;Ctrl+X&lt;/code&gt; go to.&lt;/p&gt;

&lt;p&gt;Now given the knowledge acquired from using the null register, you can
safely guess that &lt;code&gt;&quot;+p&lt;/code&gt; would paste whatever you&amp;#8217;ve copied using
&lt;code&gt;Ctrl+C&lt;/code&gt;.  Copying into the clipboard is as simple(?) as &lt;code&gt;&quot;+yy&lt;/code&gt;,
which you can test by pasting into somewhere else with &lt;code&gt;Ctrl+P&lt;/code&gt;.  If
you copy with &lt;code&gt;&quot;*yy&lt;/code&gt; instead, you can paste it by middle-clicking
the mouse, just as you would do with any content you&amp;#8217;ve highlighted in
linux.&lt;/p&gt;

&lt;h2&gt;Re-mapping the default yank, delete, and paste behaviours in Vim&lt;/h2&gt;

&lt;p&gt;I personally prefer using the Vim registers directly, so that I don&amp;#8217;t
forget how to use them, but there are definitely a lot of people who
would prefer to have copy and pasting to behave like any other editors
out there.&lt;/p&gt;

&lt;p&gt;In that case, you could consider re-mapping the default Vim behaviours by adding something
like the following into your ~/.vimrc:&lt;/p&gt;

&lt;p&gt;Re-map &lt;code&gt;d&lt;/code&gt; to delete into the null register&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nnoremap d &quot;_d
vnoremap d &quot;_d
nnoremap D &quot;_D
vnoremap D &quot;_D
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Re-map &lt;code&gt;c&lt;/code&gt; to not change the default register&amp;#8217;s content&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nnoremap c &quot;_c
vnoremap c &quot;_c
nnoremap C &quot;_C
vnoremap C &quot;_C
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Re-map &lt;code&gt;y&lt;/code&gt; to copy into the system clipboard&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nnoremap y &quot;+y
vnoremap y &quot;+y
nnoremaP Y &quot;+Y
vnoremaP Y &quot;+Y
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Re-map &lt;code&gt;p&lt;/code&gt; to paste from the system clipboard&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nnoremap p &quot;+p
vnoremap p &quot;+p
nnoremaP P &quot;+P
vnoremaP P &quot;+P
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  
</feed>
