Skip to content

Commit

Permalink
Merge pull request #338 from isucon/bench/initialize-timeout-injectable
Browse files Browse the repository at this point in the history
fix(bench): POST /initialize のタイムアウト値を実行時オプションで指定できるようにした
  • Loading branch information
Nagarei committed Jul 9, 2021
2 parents 55dfbd9 + c681046 commit a68ea0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
13 changes: 13 additions & 0 deletions bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
promOut string
showVersion bool

initializeTimeout time.Duration
// TODO: isucon11-portal に差し替え
//reporter benchrun.Reporter
)
Expand Down Expand Up @@ -78,7 +79,9 @@ func init() {
flag.BoolVar(&showVersion, "version", false, "show version and exit 1")

timeoutDuration := ""
initializeTimeoutDuration := ""
flag.StringVar(&timeoutDuration, "timeout", "10s", "request timeout duration")
flag.StringVar(&initializeTimeoutDuration, "initialize-timeout", "20s", "request timeout duration of POST /initialize")

flag.Parse()

Expand All @@ -87,6 +90,12 @@ func init() {
panic(err)
}
agent.DefaultRequestTimeout = timeout

initializeTimeout, err = time.ParseDuration(initializeTimeoutDuration)
if err != nil {
panic(err)
}

}

func checkError(err error) (critical bool, timeout bool, deduction bool) {
Expand Down Expand Up @@ -216,6 +225,10 @@ func main() {
defer cancel()

s, err := scenario.NewScenario(jiaServiceURL)
if err != nil {
panic(err)
}
s = s.WithInitilizeTimeout(initializeTimeout)
scheme := "http"
if useTLS {
scheme = "https"
Expand Down
2 changes: 1 addition & 1 deletion bench/scenario/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Scenario) Prepare(ctx context.Context, step *isucandar.BenchmarkStep) e

//initialize
initializer, err := s.NewAgent(
agent.WithNoCache(), agent.WithNoCookie(), agent.WithTimeout(20*time.Second),
agent.WithNoCache(), agent.WithNoCookie(), agent.WithTimeout(s.initializeTimeout),
)
if err != nil {
return failure.NewError(ErrCritical, err)
Expand Down
19 changes: 14 additions & 5 deletions bench/scenario/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Scenario struct {
virtualTimeMulti time.Duration //時間が何倍速になっているか
jiaServiceURL string

// POST /initialize の猶予時間
initializeTimeout time.Duration

// 競技者の実装言語
Language string

Expand All @@ -46,14 +49,20 @@ func NewScenario(jiaServiceURL string) (*Scenario, error) {
return &Scenario{
// TODO: シナリオを初期化する
//realTimeStart: time.Now()
virtualTimeStart: time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local), //TODO: ちゃんと決める
virtualTimeMulti: 3000, //5分=300秒に一回 => 1秒に10回
jiaServiceURL: jiaServiceURL,
normalUsers: []*model.User{},
companyUsers: []*model.User{},
virtualTimeStart: time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local), //TODO: ちゃんと決める
virtualTimeMulti: 3000, //5分=300秒に一回 => 1秒に10回
jiaServiceURL: jiaServiceURL,
initializeTimeout: 20 * time.Second,
normalUsers: []*model.User{},
companyUsers: []*model.User{},
}, nil
}

func (s *Scenario) WithInitilizeTimeout(t time.Duration) *Scenario {
s.initializeTimeout = t
return s
}

func (s *Scenario) NewAgent(opts ...agent.AgentOption) (*agent.Agent, error) {
opts = append(opts, agent.WithBaseURL(s.BaseURL))
return agent.NewAgent(opts...)
Expand Down

0 comments on commit a68ea0d

Please sign in to comment.