Skip to content

Commit

Permalink
Merge pull request #402 from isucon/bench-dns-attack-para
Browse files Browse the repository at this point in the history
cookieなしsearchのテスト。DNS水責め調整
  • Loading branch information
kazeburo authored Nov 24, 2023
2 parents db94374 + e2bdbeb commit df43a2e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions bench/cmd/bench/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ var run = cli.Command{
numResolves := benchscore.GetByTag(benchscore.DNSResolve)
numDNSFailed := benchscore.GetByTag(benchscore.DNSFailed)
msgs = append(msgs, fmt.Sprintf("名前解決成功数 %d", numResolves))
lgr.Infof("DNSAttacker並列数: %d", benchmarker.attackParallelis)
lgr.Infof("名前解決成功数: %d", numResolves)
lgr.Infof("名前解決失敗数: %d", numDNSFailed)

Expand Down
21 changes: 11 additions & 10 deletions bench/cmd/bench/benchmarker.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,25 @@ func (b *benchmarker) loadAttack(ctx context.Context, asize int64, httpClient *h
return nil
}

var prevNumResolved = int64(0)

func (b *benchmarker) loadAttackCoordinator(ctx context.Context) {
ticker := time.NewTicker(1 * time.Second)
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
loop:
for {
select {
case <-ticker.C:
failRate := float64(benchscore.NumDNSFailed()) / float64(benchscore.NumResolves()+benchscore.NumDNSFailed()+1)
if failRate < 0.01 {
now := time.Now()
d := now.Sub(b.startAt) / time.Second
new := int(2.0 * (1.0 + float64(d)/8.0))
if new > 16 {
new = 16
avg := float64(benchscore.NumResolves()-prevNumResolved) / 2.0
prevNumResolved = benchscore.NumResolves()
if failRate < 0.01 && avg/float64(b.attackParallelis) > 50.0 {
new := int(float64(b.attackParallelis) * 1.5)
if new > 15 {
new = 15
}
if new != b.attackParallelis {
b.contestantLogger.Info("DNS水責め負荷が上昇します")
b.contestantLogger.Info("DNS水責め負荷が上昇します", zap.Int("parallelis", new))
b.attackParallelis = new
}
}
Expand Down Expand Up @@ -354,8 +356,7 @@ func (b *benchmarker) run(ctx context.Context) error {
violateCh := make(chan error) // とめておく bencherror.RunViolationChecker(ctx)

loadAttackHTTPClient := b.loadAttackHTTPClient()
// FIXME: LIMITは負荷をみて調整したい
loadAttackLimiter := rate.NewLimiter(rate.Limit(1500), 1)
loadAttackLimiter := rate.NewLimiter(rate.Limit(3000), 1)
go func() { b.loadAttackCoordinator(ctx) }()

for {
Expand Down
41 changes: 40 additions & 1 deletion bench/scenario/core_pretest_normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ func NormalLivestreamPretest(ctx context.Context, contestantLogger *zap.Logger,
return err
}

clientNoSession, err := isupipe.NewCustomResolverClient(
contestantLogger,
dnsResolver,
agent.WithTimeout(config.PretestTimeout),
)
if err != nil {
return err
}

if err := client.Login(ctx, &isupipe.LoginRequest{
Username: testUser.Name,
Password: defaultPasswordOrPretest(testUser.Name),
Expand Down Expand Up @@ -192,6 +201,20 @@ func NormalLivestreamPretest(ctx context.Context, contestantLogger *zap.Logger,
}
}

{
tagr, err := clientNoSession.GetTags(ctx)
if err != nil {
return err
}
tagn := map[int64]string{}
for _, tag := range tagr.Tags {
tagn[tag.ID] = tag.Name
}
if !reflect.DeepEqual(tagn, poolTags) {
return fmt.Errorf("取得した tag 一覧が正しくありません。過不足があります")
}
}

tags := []int64{1, 103}
for len(tags) <= 10 {
t := rand.Intn(len(tagResponse.Tags))
Expand Down Expand Up @@ -322,7 +345,7 @@ func NormalLivestreamPretest(ctx context.Context, contestantLogger *zap.Logger,

{
//検索2回目
searchedStream, err := client.SearchLivestreams(ctx, isupipe.WithSearchTagQueryParam("ライブ配信")) // ID:1
searchedStream, err := clientNoSession.SearchLivestreams(ctx, isupipe.WithSearchTagQueryParam("ライブ配信")) // ID:1
if err != nil {
return err
}
Expand Down Expand Up @@ -410,6 +433,22 @@ func NormalLivestreamPretest(ctx context.Context, contestantLogger *zap.Logger,
return fmt.Errorf("タグ指定なし検索結果の%d番目のlivestream.idが一致しません (expected:%d actual:%d)", randNumber+1, reserveStreams[randNumber], searchedStream[randNumber].ID)
}
}
}
{
// タグ指定なし検索
searchedStream, err := clientNoSession.SearchLivestreams(ctx, isupipe.WithLimitQueryParam(config.NumSearchLivestreams))
if err != nil {
return err
}
if len(searchedStream) != config.NumSearchLivestreams {
return fmt.Errorf("タグ指定なし検索結果の数が想定外です (expected:%d actual:%d)", config.NumSearchLivestreams, len(searchedStream))
}
for i := 0; i < 5; i++ {
randNumber := rand.Intn(20)
if searchedStream[randNumber].ID != reserveStreams[randNumber] {
return fmt.Errorf("タグ指定なし検索結果の%d番目のlivestream.idが一致しません (expected:%d actual:%d)", randNumber+1, reserveStreams[randNumber], searchedStream[randNumber].ID)
}
}
for i := 0; i < 5; i++ {
randNumber := rand.Intn(20) + 25
livestreamID := int64(scheduler.GetLivestreamLength() + len(reserveStreams) - randNumber)
Expand Down

0 comments on commit df43a2e

Please sign in to comment.