Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
c08c9294
Commit
c08c9294
authored
Aug 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bulk generate benchmark
parent
c1b96347
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
1 deletions
+104
-1
Rakefile
+28
-1
spec/benchmark/bulk_generate_spec.rb
+76
-0
No files found.
Rakefile
View file @
c08c9294
...
...
@@ -30,6 +30,8 @@ def create_test_user(id)
User
.
create!
(
external_id:
id
,
username:
"user
#{
id
}
"
,
email:
"user
#{
id
}
@test.com"
)
end
Dir
.
glob
(
'lib/tasks/*.rake'
).
each
{
|
r
|
import
r
}
task
:console
=>
:environment
do
binding
.
pry
end
...
...
@@ -130,10 +132,35 @@ namespace :db do
end
task
:bulk_seed
,
[
:num
]
=>
:environment
do
|
t
,
args
|
Mongoid
.
configure
do
|
config
|
config
.
connect_to
(
"cs_comments_service_bulk_test"
)
end
connnection
=
Mongo
::
Connection
.
new
(
"127.0.0.1"
,
"27017"
)
db
=
Mongo
::
Connection
.
new
.
db
(
"cs_comments_service_bulk_test"
)
CommentThread
.
create_indexes
Comment
.
create_indexes
Content
.
delete_all
coll
=
db
.
collection
(
"contents"
)
args
[
:num
].
to_i
.
times
do
doc
=
{
"_type"
=>
"CommentThread"
,
"anonymous"
=>
[
true
,
false
].
sample
,
"at_position_list"
=>
[],
"tags_array"
=>
[],
"comment_count"
=>
0
,
"title"
=>
Faker
::
Lorem
.
sentence
(
6
),
"author_id"
=>
rand
(
1
..
10
).
to_s
,
"body"
=>
Faker
::
Lorem
.
paragraphs
.
join
(
"
\n\n
"
),
"course_id"
=>
COURSE_ID
,
"created_at"
=>
Time
.
now
,
"commentable_id"
=>
COURSE_ID
,
"closed"
=>
[
true
,
false
].
sample
,
"updated_at"
=>
Time
.
now
,
"last_activity_at"
=>
Time
.
now
,
"votes"
=>
{
"count"
=>
0
,
"down"
=>
[],
"down_count"
=>
0
,
"point"
=>
0
,
"up"
=>
[],
"up_count"
=>
[]}}
coll
.
insert
(
doc
)
end
binding
.
pry
Tire
.
index
(
'comment_threads'
).
delete
CommentThread
.
create_elasticsearch_index
Tire
.
index
(
'comment_threads'
)
{
import
CommentThread
.
all
}
end
task
:seed_fast
=>
:environment
do
ADDITIONAL_COMMENTS_PER_THREAD
=
20
config
=
YAML
.
load_file
(
"config/mongoid.yml"
)[
Sinatra
::
Base
.
environment
][
"sessions"
][
"default"
]
connnection
=
Mongo
::
Connection
.
new
(
config
[
"hosts"
][
0
].
split
(
":"
)[
0
],
config
[
"hosts"
][
0
].
split
(
":"
)[
1
])
db
=
Mongo
::
Connection
.
new
.
db
(
config
[
"database"
])
...
...
spec/benchmark/bulk_generate_spec.rb
0 → 100644
View file @
c08c9294
require
'spec_helper'
Mongoid
.
configure
do
|
config
|
config
.
connect_to
"cs_comments_service_bulk_test"
end
describe
"app"
do
describe
"benchmark"
do
it
"bulk generate"
do
Comment
.
delete_all
CommentThread
.
delete_all
CommentThread
.
recalculate_all_context_tag_weights!
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Comment
.
create_indexes
CommentThread
.
create_indexes
User
.
create_indexes
Notification
.
create_indexes
Subscription
.
create_indexes
Delayed
::
Backend
::
Mongoid
::
Job
.
create_indexes
COMMENTABLES
=
20
USERS
=
20
THREADS
=
200
TOP_COMMENTS
=
1000
SUB_COMMENTS
=
1000
VOTES
=
10000
TAGS
=
1000
Benchmark
.
bm
(
31
)
do
|
x
|
x
.
report
"create users"
do
(
1
..
USERS
).
each
do
|
user_id
|
post
"/api/v1/users"
,
id:
user_id
,
username:
"user
#{
user_id
}
"
,
email:
"user
#{
user_id
}
@test.com"
end
end
x
.
report
"create new threads"
do
THREADS
.
times
do
post
"/api/v1/question_
#{
rand
(
COMMENTABLES
).
to_s
}
/threads"
,
\
title:
"Interesting question"
,
body:
"cool"
,
anonymous:
false
,
\
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
\
tags:
(
1
..
5
).
map
{
|
x
|
"tag
#{
rand
(
TAGS
)
}
"
}.
join
(
","
)
end
end
comment_thread_ids
=
CommentThread
.
all
.
to_a
.
map
(
&
:id
)
x
.
report
(
"create top comments"
)
do
TOP_COMMENTS
.
times
do
post
"/api/v1/threads/
#{
comment_thread_ids
.
sample
}
/comments"
,
\
body:
"lalala"
,
anonymous:
false
,
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
end
end
top_comment_ids
=
Comment
.
all
.
to_a
.
map
(
&
:id
)
x
.
report
(
"create sub comments"
)
do
SUB_COMMENTS
.
times
do
post
"/api/v1/comments/
#{
top_comment_ids
.
sample
}
"
,
\
body:
"lalala"
,
anonymous:
false
,
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
end
end
x
.
report
(
"create votes"
)
do
VOTES
.
times
do
put
"/api/v1/threads/
#{
comment_thread_ids
.
sample
}
"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
value:
[
:up
,
:down
].
sample
put
"/api/v1/threads/
#{
top_comment_ids
.
sample
}
"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
value:
[
:up
,
:down
].
sample
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment