Skip to content

Commit 11009e2

Browse files
committed
Поправил заполнение базы:
- уменьшил деградацию при содзании постов; - увеличил количество постов, тредов и голосования.
1 parent 42dadca commit 11009e2

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

tests/check_forum_get_threads.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func PerfForumGetThreadsSuccess(p *Perf, f *Factory) {
175175
limit := GetRandomLimit()
176176
var since *strfmt.DateTime
177177
if rand.Int()&1 == 0 {
178-
since = &p.data.GetThread(-1, 1).Created
178+
since = &p.data.GetThread(-1, 1, 0.5).Created
179179
}
180180
desc := GetRandomDesc()
181181
s := p.Session()
@@ -211,7 +211,7 @@ func PerfForumGetThreadsNotFound(p *Perf, f *Factory) {
211211
limit := GetRandomLimit()
212212
var since *strfmt.DateTime
213213
if rand.Int()&1 == 0 {
214-
since = &p.data.GetThread(-1, 1).Created
214+
since = &p.data.GetThread(-1, 1, 0.5).Created
215215
}
216216
desc := GetRandomDesc()
217217
_, err := p.c.Operations.ForumGetThreads(operations.NewForumGetThreadsParams().

tests/check_post_get_one.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
RELATED_USER = "user"
1414
RELATED_THREAD = "thread"
1515

16-
POST_PASSES = 10
16+
POST_PASSES = 16
1717
)
1818

1919
func init() {

tests/check_thread_get_one.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (self *PThread) Validate(v PerfValidator, thread *models.Thread, version PV
7878
}
7979

8080
func PerfThreadGetOneSuccess(p *Perf, f *Factory) {
81-
thread := p.data.GetThread(-1, POST_PASSES)
81+
thread := p.data.GetThread(-1, POST_PASSES, 0.5)
8282
version := thread.Version
8383
slugOrId := GetSlugOrId(thread.Slug, int64(thread.ID))
8484
s := p.Session()

tests/check_thread_get_posts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func CheckThreadGetPostsNotFound(c *client.Forum, f *Factory) {
347347
}
348348

349349
func PerfThreadGetPostsSuccess(p *Perf, f *Factory) {
350-
thread := p.data.GetThread(-1, POST_PASSES)
350+
thread := p.data.GetThread(-1, POST_PASSES, 0.5)
351351
version := thread.Version
352352

353353
slugOrId := GetSlugOrId(thread.Slug, int64(thread.ID))

tests/filler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func NewPerfConfig() *PerfConfig {
2727
return &PerfConfig{
2828
UserCount: 1000,
2929
ForumCount: 20,
30-
ThreadCount: 1000,
31-
PostCount: 1000000,
30+
ThreadCount: 10000,
31+
PostCount: 2000000,
3232
PostBatch: 100,
33-
VoteCount: 25000,
33+
VoteCount: 100000,
3434
Validate: 1.0,
3535
}
3636
}
@@ -115,9 +115,9 @@ func FillPosts(perf *Perf, parallel int, timeout time.Time, count int, batchSize
115115
go func() {
116116
f := NewFactory()
117117
for atomic.AddInt32(&need, -int32(batchSize)) >= 0 {
118-
118+
offset := float64(int32(count)-atomic.LoadInt32(&need)) / float64(count)
119119
batch := make([]*models.Post, 0, batchSize)
120-
thread := data.GetThread(-1, 1)
120+
thread := data.GetThread(-1, POST_PASSES, offset)
121121
thread.mutex.Lock() // todo: Потом исправить
122122

123123
parents := data.GetThreadPostsFlat(thread)
@@ -169,7 +169,7 @@ func VoteThreads(perf *Perf, parallel int, timeout time.Time, count int) {
169169
for atomic.AddInt32(&need, -1) >= 0 {
170170
user := data.GetUser(-1)
171171

172-
thread := data.GetThread(-1, 1)
172+
thread := data.GetThread(-1, 1, 0.5)
173173
thread.mutex.Lock() // todo: Потом исправить
174174

175175
old_voice := thread.Voices[user]

tests/perf_data.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,18 @@ func (self *PerfData) AddThread(thread *PThread) {
201201
self.Status.Thread++
202202
}
203203

204-
func (self *PerfData) GetThread(index int, passes int) *PThread {
204+
func (self *PerfData) GetThread(index int, passes int, offset float64) *PThread {
205205
self.mutex.RLock()
206206
defer self.mutex.RUnlock()
207-
208207
if index < 0 {
209-
index = getRandomIndex(len(self.threads), passes)
208+
length := len(self.threads)
209+
delta := int((offset+0.5)*float64(length)) % length
210+
if delta < 0 {
211+
delta = length - delta
212+
}
213+
214+
index = getRandomIndex(length, passes)
215+
index = (index + delta) % length
210216
}
211217
return self.threads[index]
212218
}

0 commit comments

Comments
 (0)