Object Efficiency

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!

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.

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.

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