<br><br><div class="gmail_quote">On Fri, Mar 21, 2008 at 1:19 PM, Kirk Haines &lt;<a href="mailto:wyhaines@gmail.com">wyhaines@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Fri, Mar 21, 2008 at 1:23 PM, Scott Windsor &lt;<a href="mailto:swindsor@gmail.com">swindsor@gmail.com</a>&gt; wrote:<br>
<br>
&gt; I understand that the GC is quite knowledgeable about when to run garbage<br>
&gt; collection when examining the heap. &nbsp;But, the GC doesn&#39;t know anything about<br>
&gt; my application or it&#39;s state. &nbsp;The fact that when the GC runs everything<br>
&gt; stops is why I&#39;d prefer to limit when the GC will run. &nbsp;I&#39;d rather it run<br>
&gt; outside of serving a web request rather then when it&#39;s right in the middle<br>
&gt; of serving requests.<br>
<br>
</div>It doesn&#39;t matter, if one is looking at overall throughput. &nbsp;And how<br>
long do your GC runs take? &nbsp;If you have a GC invocation that is<br>
noticable on a single request, your processes must be gigantic, which<br>
would suggest to me that there&#39;s a more fundamental problem with the<br>
app.</blockquote><div><br>Right now, my processes aren&#39;t gigantic... I&#39;m preparing for a &#39;worst case&#39; scenario when I have a extremely large processes or memory usage.&nbsp; This can easily happen on specific applications such as an image server (using image magick) or parsing/creating large xml payloads (a large REST server).&nbsp; For those applications, I may have a large amount of memory used for each request, which will increase until the GC is run.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><div class="Ih2E3d">
&gt; I know that the ideal situation is to not need to run the GC, but the<br>
&gt; reality is that I&#39;m using various gems and plugins and not all are well<br>
&gt; behaved and free of memory leaks. &nbsp;Rails itself may also have regular leaks<br>
<br>
</div>No, it&#39;s impractical to never run the GC. &nbsp;The ideal situation, at<br>
least where execution performance and throughput on a high performance<br>
app is concerned, is to just intelligently reduce how often it needs<br>
to run by paying attention to your object creation. &nbsp;In particular,<br>
pay attention to the throwaway object creation.<br>
<div class="Ih2E3d"></div></blockquote><div><br>There may be perfectly good reasons to have intermediate object creation (good encapsulation, usage of a another library/gem you can&#39;t modify, large operations that you need to keep atomic).&nbsp; While ideally you&#39;d fix the memory usage problem, this doesn&#39;t solve all cases.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d"><br>
&gt; from time to time and I&#39;d prefer to have my application consistently be slow<br>
&gt; than randomly (and unexpectedly) be slow. &nbsp;The alternative is to terminate<br>
&gt; your application after N number of requests and never run the GC, which I&#39;m<br>
&gt; not a fan of.<br>
<br>
</div>If your goal is to deal with memory leaks, then you really need to<br>
define what that means in a GC&#39;d language like Ruby.<br>
To me, a leak is something that consumes memory in a way that eludes<br>
the GC&#39;s ability to track it and reuse it. &nbsp;The fundamental nature of<br>
that sort of thing is that the GC can&#39;t help you with it.<br>
</blockquote><div><br>Yes, for Ruby (and other GC&#39;d languages), it&#39;s much harder to leak memory such that the GC can never clean it up - but it does (and has) happened.&nbsp; This case I&#39;m less concerned about as a leak of this magnitude should be considered a bug and fixed. <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
If by leaks, you mean code that just creates a lot of objects that the<br>
GC needs to clean up, then those aren&#39;t leaks. &nbsp;It may be inefficient<br>
code, but it&#39;s not a memory leak.<br>
</blockquote><div><br>Inefficient it may be - but it might be just optimizing for a different problem.&nbsp; For example, take ActiveRecord&#39;s association cache and it&#39;s query cache.&nbsp; If you&#39;re doing a large number of queries each page load, ActiveRecord is still going to cache them for each request - this is far better than further round trips to the database, but may lead to a large amount of memory consumed per each request.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
And in the end, while disabling GC over the course of a request may<br>
result in processing that one request more quickly than it would have<br>
been processed otherwise, the disable/enable dance is going to cost<br>
you something.<br>
</blockquote><div><br>Agreed.&nbsp; But again, I&#39;d rather it be a constant cost outside of processing a request than a variable cost inside of processing a request.<br>&nbsp;<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
You&#39;ll likely either end up using more RAM than you otherwise would<br>
have in between GC calls, resulting in bigger processes, or you end up<br>
calling GC more often than you otherwise would have, reducing your<br>
high performance app&#39;s throughput.<br>
<br>
And for the general cases, that&#39;s not an advantageous situation.<br>
</blockquote><div><br>This can vary from application to application - all the more reason to make this a configurable option (and not the default). <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
To be more specific, if excessive RAM usage and GC costs that are<br>
noticable to the user during requests is a common thing for Rails<br>
apps, and the reason for that is bad code in Rails and not just bad<br>
user code, then the Rails folks should be the targets of a<br>
conversation on the matter. &nbsp;Mongrel itself, though, does not need to<br>
be, and should not be playing manual memory management games on the<br>
behalf of a web framework.<br>
<div><div class="Wj3C7c"><br>
<br>
Kirk Haines<br></div></div></blockquote><div><br>I still disagree on this point - I doubt that Rails is the only web framework that would benefit from being able to control when the GC is run.&nbsp; This is going to be a common problem across frameworks whenever web applications are consuming then releasing large amounts of memory - I&#39;d say it can be a pretty common use case for certain types of web applications.<br>
</div></div><br>- scott<br>