# Reducing Heap Fragmentation - Any Thoughts?

**URL:** <https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964>\
**Category:** Rails\
**Created:** [May 7, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964 "2008-05-07T19:33:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [May 7, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964/1 "2008-05-07T19:33:54Z")

</div>

My mongrels slowly grow as my application runs, and I have to restart  
them every few days (not as bad as some, I know). I used bleak\_house  
and had the following conversation with Evan:

[http://rubyforge.org/forum/forum.php?thread\_id=24104&forum\_id=13983](http://rubyforge.org/forum/forum.php?thread_id=24104&forum_id=13983)

Essentially, it looks like I have no leaks, but Evan suggested that I  
may be suffering from heap fragmentation. I have found a theoretical  
method to overcome this here…

[http://www.brpreiss.com/books/opus8/html/page428.html](http://www.brpreiss.com/books/opus8/html/page428.html)

…but am not sure how it can be implemented.

Does anybody have any suggestions or experience dealing with  
overcoming heap fragmentation? Perhaps something else could be  
causing the memory growth that I should look into? I’m glad that my  
app doesn’t have memory leaks, but I’m not sure what to do to keep the  
mongrels from steadily growing until I run out of RAM…

Thanks!

-Kyle

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [May 12, 2008, 2:17pm UTC](https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964/2 "2008-05-12T14:17:30Z")

</div>

Does anybody think that Passenger/mod\_rails might help? I’d just give  
it a try, but the app is already in production, and I’d hate to  
reconfigure it and take it down for nothing…

-Kyle

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [May 12, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964/3 "2008-05-12T14:54:40Z")

</div>

Kyle wrote the following on 07.05.2008 19:32 :

> [brpreiss.com](http://www.brpreiss.com/books/opus8/html/page428.html)
> 
> …but am not sure how it can be implemented.
> 
> Does anybody have any suggestions or experience dealing with  
> overcoming heap fragmentation? Perhaps something else could be  
> causing the memory growth that I should look into? I’m glad that my  
> app doesn’t have memory leaks, but I’m not sure what to do to keep the  
> mongrels from steadily growing until I run out of RAM…

Some ideas :

I use seesaw ([http://rubyforge.org/projects/rails-oceania](http://rubyforge.org/projects/rails-oceania)) to restart  
mongrels without impacting the users. I don’t use it for saving memory  
(although at a point I did) but to restart mongrels after log rotation.

I had some pages that accessed a lot of ActiveRecord objects and used  
too much memory, I rewrote some code to get at the info I needed without  
creating as much model instances, it helped a lot.

One of the selling points of Jruby for me is that it is supposed to use  
less memory than MRI. You might want to test it.

I don’t think passenger will save you much. It removes a lot of memory  
usage associated with the initial Rails and Ruby loading but not with  
the actual “run” where your problem is. They have a tuned MRI in the  
works that would certainly help there tough.

Lionel

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [May 12, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/reducing-heap-fragmentation-any-thoughts/136964/4 "2008-05-12T20:52:36Z")

</div>

Thank you for the suggestions! I’ll work on my code and check out  
Jruby.

-Kyle

On May 12, 7:53 am, Lionel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
