Skip to main content

concurrent_load_testing.md

🚀 Leveraging Faker in High-Concurrency Performance and Load Testing​

For realistic load testing or seeding, integrate Faker into multi-threaded or parallel workflows. Use a thread-safe pool (e.g., concurrent-ruby) and clear Faker’s unique generator per thread to avoid collisions and memory bloat. This approach scales data generation under stress tests.

require 'concurrent'

# Define generator for a user record
def generate_user
Faker::UniqueGenerator.clear # Reset per-thread unique registry
{
email: Faker::Internet.unique.email,
name: Faker::Name.name,
bio: Faker::Quote.famous_last_words
}
end

# Spawn a fixed thread pool for parallel seeding
pool = Concurrent::FixedThreadPool.new(10)
1000.times do
pool.post do
User.create!(generate_user)
end
end
pool.shutdown
pool.wait_for_termination

# Verify count
puts "Seeded ", User.count, "users"