andrewdmason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-15 04:13 UTC
Slow-down when creating many records in the console
Hi there, I have a script I run through console to populate my forum application with random test data. It is supposed to create thousands of forum posts with several comments per post. The method essentially looks like this: forum = Forums.create 2000.times do forum.posts.create end I''ve found that it slows to a near halt after it adds a few hundred messages. What is happening here? Is there something I can do to keep the thing moving quickly? Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Jun-15 10:22 UTC
Re: Slow-down when creating many records in the console
andrewdmason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I have a script I run through console to populate my forum application > with random test data. It is supposed to create thousands of forum > posts with several comments per post. The method essentially looks > like this: > > forum = Forums.create > 2000.times do > forum.posts.create > end > > I''ve found that it slows to a near halt after it adds a few hundred > messages. What is happening here? Is there something I can do to > keep the thing moving quickly?Perhaps 2000.times do |i| forum.posts.create GC.start if i % 100 == 99 end -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can you be more specific as to what your code is doing? ''essentially'' doesn''t help to debug as I can write a quick test to do what you posted and it takes not time at all to insert 2000 records. Chris On 6/15/07, andrewdmason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <andrewdmason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi there, > > I have a script I run through console to populate my forum application > with random test data. It is supposed to create thousands of forum > posts with several comments per post. The method essentially looks > like this: > > forum = Forums.create > 2000.times do > forum.posts.create > end > > I''ve found that it slows to a near halt after it adds a few hundred > messages. What is happening here? Is there something I can do to > keep the thing moving quickly? > > Thanks, > > Andrew > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---