This commit is contained in:
Rocky Duan 2012-08-16 12:24:52 -07:00
Родитель 20a5fa915e
Коммит d76eefa324
2 изменённых файлов: 38 добавлений и 17 удалений

Просмотреть файл

@ -1,8 +1,10 @@
seed_size: seed_size:
commentables: 20 commentables: 20
users: 100 users: 100
threads: 1000 threads: 100
top_comments: 1000 top_comments: 100
sub_comments: 2000 sub_comments: 200
votes: 10000 votes: 1000
tags: 100 tags: 100
query_amount:
course_thread_query: 1000

Просмотреть файл

@ -1,32 +1,32 @@
require 'rest_client' require 'rest_client'
PREFIX = "http://localhost:4567/api/v1"
namespace :benchmark do namespace :benchmark do
task :bulk_generate => :environment do task :bulk_generate => :environment do
seed_config = YAML.load_file("config/benchmark.yml").with_indifferent_access seed_size_config = YAML.load_file("config/benchmark.yml").with_indifferent_access[:seed_size]
COMMENTABLES = seed_config[:seed_size][:commentables] COMMENTABLES = seed_size_config[:commentables]
USERS = seed_config[:seed_size][:users] USERS = seed_size_config[:users]
THREADS = seed_config[:seed_size][:threads] THREADS = seed_size_config[:threads]
TOP_COMMENTS = seed_config[:seed_size][:top_comments] TOP_COMMENTS = seed_size_config[:top_comments]
SUB_COMMENTS = seed_config[:seed_size][:sub_comments] SUB_COMMENTS = seed_size_config[:sub_comments]
VOTES = seed_config[:seed_size][:votes] VOTES = seed_size_config[:votes]
TAGS = seed_config[:seed_size][:tags] TAGS = seed_size_config[:tags]
PREFIX = "http://localhost:4567/api/v1"
Benchmark.bm(31) do |x| Benchmark.bm(31) do |x|
RestClient.get "#{PREFIX}/clean" RestClient.get "#{PREFIX}/clean"
x.report "create users via api" do x.report "create users" do
(1..USERS).each do |user_id| (1..USERS).each do |user_id|
data = { id: user_id, username: "user#{user_id}", email: "user#{user_id}@test.com" } data = { id: user_id, username: "user#{user_id}", email: "user#{user_id}@test.com" }
RestClient.post "#{PREFIX}/users", data RestClient.post "#{PREFIX}/users", data
end end
end end
x.report "create new threads via api" do x.report "create new threads" do
(1..THREADS).each do |t| (1..THREADS).each do |t|
data = {title: "Interesting question", body: "cool", anonymous: false, \ data = {title: "Interesting question", body: "cool", anonymous: false, \
course_id: "1", user_id: (rand(USERS) + 1).to_s, \ course_id: "1", user_id: (rand(USERS) + 1).to_s, \
@ -39,7 +39,7 @@ namespace :benchmark do
comment_thread_ids = CommentThread.all.to_a.map(&:id) comment_thread_ids = CommentThread.all.to_a.map(&:id)
x.report("create top comments via api") do x.report("create top comments") do
TOP_COMMENTS.times do TOP_COMMENTS.times do
data = {body: "lalala", anonymous: false, data = {body: "lalala", anonymous: false,
course_id: "1", user_id: (rand(USERS) + 1).to_s} course_id: "1", user_id: (rand(USERS) + 1).to_s}
@ -68,4 +68,23 @@ namespace :benchmark do
end end
end end
end end
task :bulk_query => :environment do
query_amount_config = YAML.load_file("config/benchmark.yml").with_indifferent_access[:query_amount]
COURSE_THREAD_QUERY = query_amount_config[:course_thread_query]
Benchmark.bm(31) do |x|
sort_keys = %w[date activity votes comments]
sort_order = "desc"
x.report("querying threads in a course") do
COURSE_THREAD_QUERY.times do
query_params = { course_id: "1", sort_key: sort_keys.sample, sort_order: sort_order, page: 1 + rand(100), per_page: 5 }
RestClient.get "#{PREFIX}/threads", params: query_params
end
end
end
end
end end