SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loading of application.rb

    My requirement.
    I want to know, if the application.rb is loaded only once when the application is started. Is it that all the methods, variables and constants defined in the application.rb wll be loaded at the start of the application?

    class ApplicationController < ActionController::Base
    @@views = Views.findall)

    def get_views
    return @@views
    end

    end


    To make things clear, just have a look at the abov example. Suppose I am quierying for all the records in the views table in the application.rb and storing it in a class variable(@@views). In the views controller, I am calling the method get_views. Now will the whole application.rb e called or only the method called get_views be caled and the @@views will be returned.

    If only the get_views method is called(and not the whole application.rb), will this happen irrespective of whereever I am calling this method from(i.e., any controller, any helper, any model). right??

    Comming back to "Square one", will the application.rb be loaded only once throughut the application(when the application is started)?? or will it be executed each time a request come to it??

    Thanks in advance
    Anand

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All classes in Rails are reloaded in development mode. In production mode, classes are loaded into memory just the once. Because you are using a class variable, that value will persist throughout.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Luke Redpath
    All classes in Rails are reloaded in development mode. In production mode, classes are loaded into memory just the once. Because you are using a class variable, that value will persist throughout.
    Just once PER persistent server. So if you're running Apache/SCGI/FastCGI/mongrel, etc, it will load once for each scgi/fastcgi listener/child process.

  4. #4
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    more specific

    Hi Sgarissta

    Can u be a little bit clear???

    Not totally confused, but mmmm confused a little bit

    Anand

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What Luke was saying is essentially true, that in production mode, and because you use a class variable, it will only be loaded once. What he didn't mention was that in most production environments you have more than one interpreter open at a time. If you look at an Apache/FastCGI setup for instance, you'll have it spawn a certain number (let's say 5) FastCGI listener processes. Each of these starts its own Ruby interpreter, and will load that data once. So in effect you have it loaded 5 times, in 5 different Ruby interpreters, not "just once".

  6. #6
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A small doubt

    Thanks for explaining...

    I have a small doubt.

    U have told that more than one interpreter will be running in the production mode. Can u tell me what what reason more than one Interpreter is required. If so under what conditions do we require it???

    Can I get some material on the web regarding this???

    Regards,
    Anand

  7. #7
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A general rule of thumb is the more traffic you expect, the more handlers you'll require although that simplifies things a bit.

    Most apps shouldn't need more than 1 or 2.

  8. #8
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wanna know more about this,

    How do u know how many interpreters are open??? Is there a way to limit the number of Interpreters open?

    Please excuse me if the questiio is a little bit konkey..
    Is there any web site or book which tells about the interpreter and all these things??

    Anand


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
  •