How to create 10000 pseudo data for Testing in RoR

79 views
Skip to first unread message

haxuan lac

unread,
Apr 5, 2013, 11:08:04 AM4/5/13
to rubyonra...@googlegroups.com
I want to test performance of project.
So i want make 10000 record of table for testing.
I don't know how to ganerate record.
Who can help me? Thanks.

--
Posted via http://www.ruby-forum.com/.

Greg Akins

unread,
Apr 5, 2013, 11:13:30 AM4/5/13
to rubyonra...@googlegroups.com
Depends on what you're trying to test.

If it's a single table and the values in the database don't matter, you can just add a [0..10000].each loop in seed.rb

Or copy production data

Or use a sql script to load your database


On Fri, Apr 5, 2013 at 11:08 AM, haxuan lac <li...@ruby-forum.com> wrote:
I want to test performance of project.
So i want make 10000 record of table for testing.
I don't know how to ganerate record.
Who can help me? Thanks.



haxuan lac

unread,
Apr 5, 2013, 11:26:46 AM4/5/13
to rubyonra...@googlegroups.com
Thanks Greg Akins
I'm using MongoDB and in Mongodb has some table as:
user,comment,photo,relationship
And tables have ralationship(user relationship with photos..) ....
Could you give me some advice for this problem?Thanks

Gintautas Šimkus

unread,
Apr 5, 2013, 11:50:19 AM4/5/13
to rubyonra...@googlegroups.com
You can add data via Rails models, like

User.create({ <your attributes for user goes there })

Just use rails code inside seed.rb to generate whatever you like and then run rake task which is something like `rake db:seed`


2013/4/5 haxuan lac <li...@ruby-forum.com>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Pagarbiai,
Gintautas

Gintautas Šimkus

unread,
Apr 5, 2013, 12:04:03 PM4/5/13
to rubyonra...@googlegroups.com


2013/4/5 Gintautas Šimkus <dihi...@gmail.com>



--
Pagarbiai,
Gintautas

haxuan lac

unread,
Apr 5, 2013, 12:08:34 PM4/5/13
to rubyonra...@googlegroups.com
Yes ,Thanks Gintautas
If I want create 1000000(1 million) pseudo data,i can this way for it?
And i hear a gem with called "faker" http://faker.rubyforge.org/
can i using this gem for solve my problem ( create 1000000 pseudo data)?
Thanks very much

Gintautas Šimkus

unread,
Apr 5, 2013, 12:11:03 PM4/5/13
to rubyonra...@googlegroups.com
Maybe, I don't know :) you just got to investigate stuff, that's part of learning something new process :)


2013/4/5 haxuan lac <li...@ruby-forum.com>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Pagarbiai,
Gintautas

Gintautas Šimkus

unread,
Apr 5, 2013, 12:12:33 PM4/5/13
to rubyonra...@googlegroups.com
Though just simple db:seed and then exporting development DB and importing it into test DB should do the trick.


2013/4/5 Gintautas Šimkus <dihi...@gmail.com>



--
Pagarbiai,
Gintautas

Greg Akins

unread,
Apr 5, 2013, 12:14:48 PM4/5/13
to rubyonra...@googlegroups.com
huxuan

Faker might be overkill.. or might not.  Try both approaches and let us know which works best.

If you have ActiveRecord model defined (say User.rb)

Then just include this in the db/seed.rb

[0..1000000].each do |i|
User.create(:name => "name#{i}", etc...)
end

A problem with this approach is distribution of data.  If you need the names to be distributed across an alphanumeric range (to mimic real world data) then you might want to modify the mechanism for creating the User.

haxuan lac

unread,
Apr 5, 2013, 12:22:34 PM4/5/13
to rubyonra...@googlegroups.com
Thank Gintautas,Greg Akins very much
I will do with instruction of you.
Thank you vey much again!!!

Sean L.

unread,
Apr 5, 2013, 12:39:11 PM4/5/13
to rubyonra...@googlegroups.com
haxuan lac wrote in post #1104574:
> I want to test performance of project.
> So i want make 10000 record of table for testing.
> I don't know how to ganerate record.
> Who can help me? Thanks.

Look at rails cast #179.
this has a tutorial on using seed.rub to create test data.

http://railscasts.com/episodes/179-seed-data?view=comments

Julian Leviston

unread,
Apr 5, 2013, 7:37:09 PM4/5/13
to rubyonra...@googlegroups.com
-- 

Props, Greg! I'm impressed with your response. I saw the question, and these kinds of questions really bother me because they lack specificity. I was thinking maybe we should have a noob web form app that could help them build their questions properly for submitting, by asking THEM lots of questions. :) Then we could just point them to it, and say hey, do this! :)

But yeah, "more information please, as much as possible" is such a common thing to say.

Julian

Jordon Bedwell

unread,
Apr 5, 2013, 7:43:18 PM4/5/13
to rubyonra...@googlegroups.com
On Fri, Apr 5, 2013 at 6:37 PM, Julian Leviston <jul...@coretech.net.au> wrote:
Props, Greg! I'm impressed with your response. I saw the question, and these kinds of questions really bother me because they lack specificity. I was thinking maybe we should have a noob web form app that could help them build their questions properly for submitting, by asking THEM lots of questions. :) Then we could just point them to it, and say hey, do this! :)

But yeah, "more information please, as much as possible" is such a common thing to say.


Maybe we should also have a big ass sign on-top of it for people who make worthless comments, all it needs to say is "don't make worthless comments." And yes, I realize the irony.

haxuan lac

unread,
Apr 5, 2013, 10:18:46 PM4/5/13
to rubyonra...@googlegroups.com
I tried create 10000 pseudo by Faker but it's very slow.
I fake 1000 record about 20 minutes.
And 10000 record take me 2-3 hours.
please give me some advice about this time I had done with fake pseudo
data(1000 and 10000 pseudo).
Thanks..............

Colin Law

unread,
Apr 6, 2013, 4:20:52 AM4/6/13
to rubyonra...@googlegroups.com
On 6 April 2013 03:18, haxuan lac <li...@ruby-forum.com> wrote:
> I tried create 10000 pseudo by Faker but it's very slow.
> I fake 1000 record about 20 minutes.
> And 10000 record take me 2-3 hours.
> please give me some advice about this time I had done with fake pseudo
> data(1000 and 10000 pseudo).

I think it has been suggested several times that you use rake db:seed
with seed.rb. Have you investigated that route?

Colin

tamouse mailing lists

unread,
Apr 6, 2013, 5:25:57 AM4/6/13
to rubyonra...@googlegroups.com


On Apr 5, 2013 9:18 PM, "haxuan lac" <li...@ruby-forum.com> wrote:
>
> I tried create 10000 pseudo by Faker but it's very slow.
> I fake 1000 record about 20 minutes.
> And 10000 record take me 2-3 hours.
> please give me some advice about this time I had done with fake pseudo
> data(1000 and 10000 pseudo).
> Thanks..............

anytime you use the ORM to insert 10_000 records it's going to be slow as it does them one at a time. i suggest gong the direct sql route in this case.

Manish Chakravarty

unread,
Apr 8, 2013, 11:34:17 AM4/8/13
to rubyonra...@googlegroups.com
Write a Ruby script to do it, invoke it via a rake task.
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Best,
Manish Chakravarty

Blog | Twitter | LinkedIn

tonypm

unread,
Apr 14, 2013, 12:35:17 PM4/14/13
to rubyonra...@googlegroups.com
One approach may be to build the data as a large csv.  Which you could do from ruby if you wished and you can then keep as a file.  Then either import directly to the db with sql or workbench etc. or if you want to stay ruby, load the csv and use ar_extension import to  dump the data into the db.
Reply all
Reply to author
Forward
0 new messages