How to create 10000 pseudo data for Testing in RoR

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.

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

Or one of these http://watirmelon.com/2012/06/15/three-ways-to-generate-test-data-for-your-ruby-automated-tests/

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

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

As far as cloning development DB into test DB, check out http://stackoverflow.com/questions/2645022/rails-populate-test-database-with-development-data

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

Maybe, I don’t know :slight_smile: you just got to investigate stuff, that’s part of learning something new process :slight_smile:

Though just simple db:seed and then exporting development DB and importing it into test DB should do the trick.

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.

Thank Gintautas,Greg Akins very much I will do with instruction of you. Thank you vey much again!!!

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.

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. :slight_smile: Then we could just point them to it, and say hey, do this! :slight_smile:

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

Julian

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.

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

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

Colin

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.

Write a Ruby script to do it, invoke it via a rake task.

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.