Greating All, I have had to solve the following problem enough in the last month that I''m sure it has a name and a body of research behind it but I''m having trouble finding it. The general problem is this: I have a Site Model. Each Site has many Consumers and Producers. Producers make some amount of a "resource" available at the Site, while Consumers use these "resources." The program''s goal is to manage changes in Consumers and Producers to keep them in balance. Questions: 1) When is it better to try to maintain a "resources" column in Site, and when is it better to reproduce the data every time. In other words is there a good way of "cashing" the resource calculation? 2) When a controller makes a change to a Consumer or Producer should the model or the controller be responsible for asking the changed items Site to rebalance its resources? 3) Is there a common name for this kind of problem that I can google/wikipedia for more information? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 15, 6:31 pm, John Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Greating All, > > I have had to solve the following problem enough in the last month that > I''m sure it has a name and a body of research behind it but I''m having > trouble finding it. > > The general problem is this: > I have a Site Model. Each Site has many Consumers and Producers. > Producers make some amount of a "resource" available at the Site, while > Consumers use these "resources." The program''s goal is to manage > changes in Consumers and Producers to keep them in balance. > > Questions: > 1) When is it better to try to maintain a "resources" column in Site, > and when is it better to reproduce the data every time. In other words > is there a good way of "cashing" the resource calculation?As a general rule, do not store redundant information in a database, or anywhere else, until you have a known performance problem.> > 2) When a controller makes a change to a Consumer or Producer should the > model or the controller be responsible for asking the changed items Site > to rebalance its resources?This one is easy. The model should be responsible. Keep the controllers as thin as possible. Ideally a controller action should fetch a model, call one method on the model, and then call a view to render that one model. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
kevin cline wrote:> On Dec 15, 6:31 pm, John Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> changes in Consumers and Producers to keep them in balance. >> >> Questions: >> 1) When is it better to try to maintain a "resources" column in Site, >> and when is it better to reproduce the data every time. In other words >> is there a good way of "cashing" the resource calculation? > > As a general rule, do not store redundant information in a database, > or anywhere else, until you have a known performance problem. >A little testing over the weekend reveled that i have at least two cases where changing a single Producers output ended up hitting the database 302 times and performing a sum across all producers or consumers 1437 times taking 8.34s on my SQLite :memory: database. 82% of the run time was spent in one of the adding up resources either used or consumed, 11% in data access. Given the above, I think the question becomes where and how to cache data. The concept of not storing redundant data seems prudent, but it looks like a need to do some kind of memory/processing time trade off, even it is not stored in the database. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What is involved in rebalancing resources? Maybe the algorithm could be improved. ///ark --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Check out the counter cache in Rails: http://railscasts.com/episodes/23 On Dec 17, 2007 11:39 AM, John Miller <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > kevin cline wrote: > > On Dec 15, 6:31 pm, John Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> changes in Consumers and Producers to keep them in balance. > >> > >> Questions: > >> 1) When is it better to try to maintain a "resources" column in Site, > >> and when is it better to reproduce the data every time. In other words > >> is there a good way of "cashing" the resource calculation? > > > > As a general rule, do not store redundant information in a database, > > or anywhere else, until you have a known performance problem. > > > > A little testing over the weekend reveled that i have at least two cases > where changing a single Producers output ended up hitting the database > 302 times and performing a sum across all producers or consumers 1437 > times taking 8.34s on my SQLite :memory: database. 82% of the run time > was spent in one of the adding up resources either used or consumed, 11% > in data access. > > Given the above, I think the question becomes where and how to cache > data. The concept of not storing redundant data seems prudent, but it > looks like a need to do some kind of memory/processing time trade off, > even it is not stored in the database. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---