bulk course threads query
This commit is contained in:
Родитель
20a5fa915e
Коммит
d76eefa324
|
@ -1,8 +1,10 @@
|
|||
seed_size:
|
||||
commentables: 20
|
||||
users: 100
|
||||
threads: 1000
|
||||
top_comments: 1000
|
||||
sub_comments: 2000
|
||||
votes: 10000
|
||||
threads: 100
|
||||
top_comments: 100
|
||||
sub_comments: 200
|
||||
votes: 1000
|
||||
tags: 100
|
||||
query_amount:
|
||||
course_thread_query: 1000
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
require 'rest_client'
|
||||
|
||||
PREFIX = "http://localhost:4567/api/v1"
|
||||
|
||||
namespace :benchmark 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]
|
||||
USERS = seed_config[:seed_size][:users]
|
||||
THREADS = seed_config[:seed_size][:threads]
|
||||
TOP_COMMENTS = seed_config[:seed_size][:top_comments]
|
||||
SUB_COMMENTS = seed_config[:seed_size][:sub_comments]
|
||||
VOTES = seed_config[:seed_size][:votes]
|
||||
TAGS = seed_config[:seed_size][:tags]
|
||||
|
||||
PREFIX = "http://localhost:4567/api/v1"
|
||||
COMMENTABLES = seed_size_config[:commentables]
|
||||
USERS = seed_size_config[:users]
|
||||
THREADS = seed_size_config[:threads]
|
||||
TOP_COMMENTS = seed_size_config[:top_comments]
|
||||
SUB_COMMENTS = seed_size_config[:sub_comments]
|
||||
VOTES = seed_size_config[:votes]
|
||||
TAGS = seed_size_config[:tags]
|
||||
|
||||
Benchmark.bm(31) do |x|
|
||||
|
||||
RestClient.get "#{PREFIX}/clean"
|
||||
|
||||
x.report "create users via api" do
|
||||
x.report "create users" do
|
||||
(1..USERS).each do |user_id|
|
||||
data = { id: user_id, username: "user#{user_id}", email: "user#{user_id}@test.com" }
|
||||
RestClient.post "#{PREFIX}/users", data
|
||||
end
|
||||
end
|
||||
|
||||
x.report "create new threads via api" do
|
||||
x.report "create new threads" do
|
||||
(1..THREADS).each do |t|
|
||||
data = {title: "Interesting question", body: "cool", anonymous: false, \
|
||||
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)
|
||||
|
||||
x.report("create top comments via api") do
|
||||
x.report("create top comments") do
|
||||
TOP_COMMENTS.times do
|
||||
data = {body: "lalala", anonymous: false,
|
||||
course_id: "1", user_id: (rand(USERS) + 1).to_s}
|
||||
|
@ -68,4 +68,23 @@ namespace :benchmark do
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче