Project

General

Profile

Actions

Feature #3322

closed

Simple Patch to make ruby copy-on-write-friendly

Added by Dan42 (Daniel DeLorme) over 14 years ago. Updated over 12 years ago.

Status:
Rejected
Target version:
-
[ruby-core:30323]

Description

=begin
A lot has been said about ruby's lack of COW-friendliness; a full solution like REE has a performance impact, but I think I've come up with a simple trick that solves the problem of pre-forking servers. Basically, this patch implements GC.leak which marks all existing objects as ineligible for GC, and existing heaps as ineligible for allocation of new objects. It may sound hacky, but it's exactly the point of pre-forking in most cases: load a bunch of code & data and then keep it in memory forever.

Compare the memory usage of these:
./ruby -e 'x=(1..40_000_000).map{""}; Process.fork; x=[]; GC.start; sleep 10'
./ruby -e 'x=(1..40_000_000).map{""}; GC.leak; Process.fork; x=[]; GC.start; sleep 10'

This patch has the advantage of being

  1. simple
  2. free of negative performance impact
  3. implemented and available now

PS: As far as I can tell the patch works fine, but I'm not terribly well-versed about the innards of ruby so I'd appreciate some code review. Thanks.
=end


Files

cow.patch (2.41 KB) cow.patch Dan42 (Daniel DeLorme), 05/20/2010 05:58 PM
cow2.patch (2.46 KB) cow2.patch Dan42 (Daniel DeLorme), 05/21/2010 08:55 AM
Actions #1

Updated by rkh (Konstantin Haase) over 14 years ago

=begin
You might want to run the GC first.
=end

Actions #2

Updated by Dan42 (Daniel DeLorme) over 14 years ago

=begin
Adding garbage_collect() before leak and after unleak
=end

Actions #3

Updated by rogerdpack (Roger Pack) over 14 years ago

=begin
Good idea. Unfortunately it needs to traverse (and mark) all the "old" heaps during GC, so that it can see which items are still accessible in the namespace. Unless you can guarantee that no new objects will be pointed to by members of the old heap, you still have to traverse everything. At least AFAIK.
-rp
=end

Actions #4

Updated by akr (Akira Tanaka) over 13 years ago

  • Project changed from Ruby to Ruby master
  • Category changed from core to core

Updated by nahi (Hiroshi Nakamura) almost 13 years ago

  • Description updated (diff)
  • Assignee set to authorNari (Narihiro Nakamura)
Actions #6

Updated by shyouhei (Shyouhei Urabe) almost 13 years ago

  • Status changed from Open to Assigned

Updated by authorNari (Narihiro Nakamura) over 12 years ago

  • Status changed from Assigned to Rejected
  • % Done changed from 0 to 100

Sorry for the late relpy.
We already have Bitmap Marking GC in Ruby2.0 so I reject it.

Thanks.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0