Professional Web Applications Themes

Memory consumption of Ruby/mod_ruby combo on Apache [memory leak] - Ruby

> I don't think so - I think all the modules are loaded when Apache is > started, and each child process will have everything in the parent > process. In fact, when I put a LoadModule directive inside a > VirtualHost section, apachectl configtest reported an error. It didn't have anything to do with IfModules or even Apache. I had a static constructor method as follows: def self.run request = CGI.new self.new(request, request.session(Session_parameters)) end Can you spot the instance variable reference? That caused a massive memory leak of a couple of hundred kb on each run. I wonder why ...

  1. #1

    Default Re: Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]

    > I don't think so - I think all the modules are loaded when Apache is
    > started, and each child process will have everything in the parent
    > process. In fact, when I put a LoadModule directive inside a
    > VirtualHost section, apachectl configtest reported an error.
    It didn't have anything to do with IfModules or even Apache. I had a
    static constructor method as follows:

    def self.run
    request = CGI.new
    self.new(request, request.session(Session_parameters))
    end

    Can you spot the instance variable reference? That caused a massive
    memory leak of a couple of hundred kb on each run.

    I wonder why Ruby didn't alert me to the presence of a instance
    reference in a static context? Java does that.

    / David


    David Heinemeier Hansson Guest

  2. #2

    Default Re: Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]

    On Wednesday, September 10, 2003, 3:09:20 AM, David wrote:
    >> I don't think so - I think all the modules are loaded when Apache is
    >> started, and each child process will have everything in the parent
    >> process. In fact, when I put a LoadModule directive inside a
    >> VirtualHost section, apachectl configtest reported an error.
    > It didn't have anything to do with IfModules or even Apache. I had a
    > static constructor method as follows:
    > def self.run
    > request = CGI.new
    > self.new(request, request.session(Session_parameters))
    > end
    > Can you spot the instance variable reference? That caused a massive
    > memory leak of a couple of hundred kb on each run.
    > I wonder why Ruby didn't alert me to the presence of a instance
    > reference in a static context? Java does that.

    You've tripped on a funny feature of Ruby which some people have
    grasped and I ... well, haven't. Sorry I can't think of a reference
    right now.

    But basically,

    class Example
    x = "class instance variable"
    x = "class variable"

    def initialize
    x = "instance variable"
    end

    def run
    puts x
    puts x
    end

    def self.run
    puts x
    puts x
    end
    end

    Example.run
    Example.new.run


    Run this code yourself to see the (predictable) output.

    I just created [url]http://www.rubygarden.org/ruby?ClassInstanceVaribles[/url].
    If anyone knows of links to other information about them, that would
    be a good place to gather them.

    Gavin


    Gavin Sinclair Guest

  3. #3

    Default Re: Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]

    Hi --

    On Wed, 10 Sep 2003, Gavin Sinclair wrote:
    > I just created [url]http://www.rubygarden.org/ruby?ClassInstanceVaribles[/url].
    ^^^^^^^^
    You owe us an 'a' :-)

    (I've put a link from ClassInstanceVariables to
    ClassInstanceVaribles.)


    David

    --
    David Alan Black
    home: [email]dblacksuperlink.net[/email]
    work: [email]blackdavshu.edu[/email]
    Web: [url]http://pirate.shu.edu/~blackdav[/url]


    dblack@superlink.net Guest

  4. #4

    Default Re: Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]

    Hi --

    On Wed, 10 Sep 2003, David Heinemeier Hansson wrote:
    > > I don't think so - I think all the modules are loaded when Apache is
    > > started, and each child process will have everything in the parent
    > > process. In fact, when I put a LoadModule directive inside a
    > > VirtualHost section, apachectl configtest reported an error.
    >
    > It didn't have anything to do with IfModules or even Apache. I had a
    > static constructor method as follows:
    >
    > def self.run
    > request = CGI.new
    > self.new(request, request.session(Session_parameters))
    > end
    >
    > Can you spot the instance variable reference? That caused a massive
    > memory leak of a couple of hundred kb on each run.
    >
    > I wonder why Ruby didn't alert me to the presence of a instance
    > reference in a static context? Java does that.
    Because the Class object in whose context you're coding is, itself, an
    instance (of Class). So there's nothing to warn about; any object can
    have instance variables, including Class objects. What you've done is
    to create an instance variable for your Class object.

    This is actually a very handy technique; it's the best way to preserve
    state on a true per-class basis. (Class variables don't do that
    because they're shared through inheritance.)

    If you search on ruby-talk.org or Google groups for "class variables",
    "class instance variables", and related things, you'll find a lot of
    threads on all the permutations of this.


    David

    --
    David Alan Black
    home: [email]dblacksuperlink.net[/email]
    work: [email]blackdavshu.edu[/email]
    Web: [url]http://pirate.shu.edu/~blackdav[/url]


    dblack@superlink.net Guest

  5. #5

    Default Re: Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]

    > Hi --
    >
    > On Wed, 10 Sep 2003, Gavin Sinclair wrote:
    >
    >> I just created [url]http://www.rubygarden.org/ruby?ClassInstanceVaribles[/url].
    > ^^^^^^^^
    > You owe us an 'a' :-)
    >
    > (I've put a link from ClassInstanceVariables to
    > ClassInstanceVaribles.)
    >
    I didn't see the link. I marked the erroneous page with "DeletedPage" and
    moved the content to the correct one, and added a comment, to boot.

    Gavin



    Gavin Sinclair Guest

Similar Threads

  1. #39438 [NEW]: Memory leak PHP Fatal error: Out of memory
    By nikolas dot hagelstein at gmail dot com in forum PHP Bugs
    Replies: 11
    Last Post: December 1st, 08:08 PM
  2. memory problem/memory leak
    By Tron Juan Del Marco webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 1
    Last Post: January 20th, 06:02 PM
  3. Memory consumption
    By Gary in forum Macromedia Director Lingo
    Replies: 2
    Last Post: October 16th, 02:32 PM
  4. Memory consumption of Ruby/mod_ruby combo on Apache
    By David Heinemeier Hansson in forum Ruby
    Replies: 6
    Last Post: September 10th, 05:59 AM
  5. How to get the memory consumption of an object
    By Steve C. Orr, MCSD in forum ASP.NET General
    Replies: 0
    Last Post: July 20th, 12:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139