So I am using rufus-scheduler to call a controller which in turn calls an email receiver to check emails... In my controller, I have an instance method called checkEmail In my rufus config file, I have to call MyController.new.checkEmail. Now I set it to run every 5 minutes. So the system creates a new MyController instance every 5 minutes. That''s very inefficient right? I guess I can change the instance method to a class method. That would solve the efficiency problem right? What else can I do? Are there some advanced features in rails to mange object instance more efficiently? Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BNA6O24VyHkJ. For more options, visit https://groups.google.com/groups/opt_out.
On 10 September 2012 05:03, rails2012 <dereklin-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> In my rufus config file, I have to call MyController.new.checkEmail. Now I > set it to run every 5 minutes. So the system creates a new MyController > instance every 5 minutes. That''s very inefficient right?Normally it would be worth worrying about ten and hundreds of requests a second... I don''t think one every five minutes is going to cook the processor.> What else can I do? Are there some advanced features in rails to mange > object instance more efficiently?What problems are you suffering? Have you measured the degradation in performance on your system? PS I would suggest that if Rufus is polling a method, that method should not be on a controller. It should be on a model, or as a stand-alone lib class. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Just want to know the best practices to make sure I get off on the right foot. I think on a general rule, creating fewer instances of an object is ideal for performance right? (I am not suffering any real problems yet) In Java, there is Inversion of Control/Dependency Injection. I have read some blog saying that Rails''s way is using Modules. I have to look into more on Modules -- for example, are they equivalent to global functions?> From: pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > Date: Mon, 10 Sep 2012 07:58:23 +0100 > Subject: Re: [Rails] Object Efficiency > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > On 10 September 2012 05:03, rails2012 <dereklin-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > In my rufus config file, I have to call MyController.new.checkEmail. Now I > > set it to run every 5 minutes. So the system creates a new MyController > > instance every 5 minutes. That''s very inefficient right? > > Normally it would be worth worrying about ten and hundreds of requests > a second... I don''t think one every five minutes is going to cook the > processor. > > > What else can I do? Are there some advanced features in rails to mange > > object instance more efficiently? > > What problems are you suffering? Have you measured the degradation in > performance on your system? > > > PS I would suggest that if Rufus is polling a method, that method > should not be on a controller. It should be on a model, or as a > stand-alone lib class. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Mon, Sep 10, 2012 at 11:59 AM, Derek Lin <dereklin-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Just want to know the best practices to make sure I get off on the right > foot. I think on a general rule, creating fewer instances of an object is > ideal for performance right? (I am not suffering any real problems yet) > In Java, there is Inversion of Control/Dependency Injection. I have read > some blog saying that Rails''s way is using Modules. I have to look into > more on Modules -- for example, are they equivalent to global functions?People really need to use Modules more and classes less, for example people often use a singleton class where they should be using a Module... why should they be using a module? Because that class is never going to initialized and it''s not meant to be... IMO the only time you use a singleton class is when you are mixing the way ActiveRecord does when you inherit from it. You wouldn''t believe how many people I see /only/ use a Module when they plan to inherit from it, and it''s kind intriguing they do that because the way I see it, Modules are (in simplistic terms) organized groups of code that can run independently or be inherited from. There are of course technical differences that make Modules better than Classes in some cases and Classes better than modules in some cases but I''m not here to write a book for you. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Monday, 10 September 2012 12:59:22 UTC-4, rails2012 wrote:> > Just want to know the best practices to make sure I get off on the right > foot. I think on a general rule, creating fewer instances of an object is > ideal for performance right? (I am not suffering any real problems yet) >Running less code in general is good for performance, but there''s enough churn (from the rest of the stack) of objects being created and discarded that unless your code is doing A LOT of creation it''s not likely to be relevant. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Jid5XlIibfEJ. For more options, visit https://groups.google.com/groups/opt_out.