# Slow-down when creating many records in the console

**URL:** <https://www.ruby-forum.com/t/slow-down-when-creating-many-records-in-the-console/106902>\
**Category:** Rails\
**Created:** [June 15, 2007, 6:14am UTC](https://www.ruby-forum.com/t/slow-down-when-creating-many-records-in-the-console/106902 "2007-06-15T06:14:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 15, 2007, 6:14am UTC](https://www.ruby-forum.com/t/slow-down-when-creating-many-records-in-the-console/106902/1 "2007-06-15T06:14:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 15, 2007, 12:26pm UTC](https://www.ruby-forum.com/t/slow-down-when-creating-many-records-in-the-console/106902/2 "2007-06-15T12:26:22Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 15, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/slow-down-when-creating-many-records-in-the-console/106902/3 "2007-06-15T19:38:45Z")

</div>

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
