bench

package module
v0.0.0-...-ea15bc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 24 Imported by: 0

README

bench

How to run

前提

  • repo root にいる状態
  • docker-compose で起動している状態
    • nginx が port 80
    • mysql が port 13306
$ gh release download dummydata/20220421_0056-prod # もしくはreleaseからisucon_listen80_dump_prod.tar.gzをダウンロード
$ tar xvf isucon_listen80_dump_prod.tar.gz
$ mysql -uroot -proot --host 127.0.0.1 --port 13306 < isucon_listen80_dump.sql
$ cd bench
$ make
$ ./bench -target-url http://localhost  # nginxのportを変えている場合はportを合わせる

Documentation

Index

Constants

View Source
const (
	ErrFailedLoadJSON failure.StringCode = "load-json"
	ErrCannotNewAgent failure.StringCode = "agent"
	ErrInvalidRequest failure.StringCode = "request"
)
View Source
const (
	ScoreGETRoot             score.ScoreTag = "GET /"
	ScoreSignup              score.ScoreTag = "POST /api/signup"
	ScoreLogin               score.ScoreTag = "POST /api/login"
	ScoreLogout              score.ScoreTag = "POST /api/logout"
	ScoreGetPlaylist         score.ScoreTag = "GET /api/playlist/{}"
	ScoreGetPlaylists        score.ScoreTag = "GET /api/playlists"
	ScoreGetRecentPlaylists  score.ScoreTag = "GET /api/recent_playlists"
	ScoreGetPopularPlaylists score.ScoreTag = "GET /api/popular_playlists"
	ScoreAddPlaylist         score.ScoreTag = "POST /api/playlist/{}/add"
	ScoreUpdatePlaylist      score.ScoreTag = "POST /api/playlist/{}/update"
	ScoreFavoritePlaylist    score.ScoreTag = "POST /api/playlist/favorite"
	ScoreAdminBan            score.ScoreTag = "POST /api/admin/user/ban"

	ScoreGetRecentPlaylistsLogin  score.ScoreTag = "GET /api/recent_playlists (login)"
	ScoreGetPopularPlaylistsLogin score.ScoreTag = "GET /api/popular_playlists (login)"
)

シナリオで発生するスコアのタグ

View Source
const (
	ErrInvalidStatusCode   failure.StringCode = "status-code"
	ErrInvalidCacheControl failure.StringCode = "cache-control"
	ErrInvalidJSON         failure.StringCode = "broken-json"
	ErrInvalidPath         failure.StringCode = "path"
	ErrFailed              failure.StringCode = "failed"
	ErrValidation          failure.StringCode = "validation"
)

failure.NewError で用いるエラーコード定義

Variables

View Source
var (
	// 選手向け情報を出力するロガー
	ContestantLogger = log.New(os.Stdout, "", log.Ltime|log.Lmicroseconds)
	// 大会運営向け情報を出力するロガー
	AdminLogger = log.New(os.Stderr, "[ADMIN] ", log.Ltime|log.Lmicroseconds)
)
View Source
var (
	Debug     = false
	MaxErrors = 30
)

Functions

func AddPlayistAction

func AddPlayistAction(ctx context.Context, name string, ag *agent.Agent) (*http.Response, error)

func AdminBanAction

func AdminBanAction(ctx context.Context, user *User, isBan bool, ag *agent.Agent) (*http.Response, error)

func DeletePlaylistAction

func DeletePlaylistAction(ctx context.Context, p *Playlist, ag *agent.Agent) (*http.Response, error)

func DisplayName

func DisplayName() string

func FavoritePlaylistAction

func FavoritePlaylistAction(ctx context.Context, p *Playlist, ag *agent.Agent) (*http.Response, error)

func GenerateUserAccount

func GenerateUserAccount() string

func GetInitializeAction

func GetInitializeAction(ctx context.Context, ag *agent.Agent) (*http.Response, error)

func GetPlaylistAction

func GetPlaylistAction(ctx context.Context, id string, ag *agent.Agent) (*http.Response, error)

func GetPlaylistsAction

func GetPlaylistsAction(ctx context.Context, ag *agent.Agent) (*http.Response, error)

func GetPopularPlaylistsAction

func GetPopularPlaylistsAction(ctx context.Context, ag *agent.Agent) (*http.Response, error)

func GetRecentPlaylistsAction

func GetRecentPlaylistsAction(ctx context.Context, ag *agent.Agent) (*http.Response, error)

func GetRootAction

func GetRootAction(ctx context.Context, ag *agent.Agent) (*http.Response, error)

func LoadFromJSONFile

func LoadFromJSONFile[T Model](jsonFile string) ([]*T, error)

func LoginAction

func LoginAction(ctx context.Context, user *User, ag *agent.Agent) (*http.Response, error)

func LogoutAction

func LogoutAction(ctx context.Context, user *User, ag *agent.Agent) (*http.Response, error)

func RandomString

func RandomString(n int) string

func UpdatePlayistAction

func UpdatePlayistAction(ctx context.Context, p *Playlist, ag *agent.Agent) (*http.Response, error)

Types

type Model

type Model interface {
	User | Song
}

type Option

type Option struct {
	TargetURL                string
	RequestTimeout           time.Duration
	InitializeRequestTimeout time.Duration
	ExitErrorOnFail          bool
	Duration                 time.Duration
	PrepareOnly              bool
	SkipPrepare              bool
	DataDir                  string
	Debug                    bool
}

func (Option) NewAgent

func (o Option) NewAgent(forInitialize bool) (*agent.Agent, error)

func (Option) String

func (o Option) String() string

type Playlist

type Playlist struct {
	ULID            string    `json:"ulid"`
	Name            string    `json:"name"`
	UserDisplayName string    `json:"user_display_name"`
	UserAccount     string    `json:"user_account"`
	SongCount       int       `json:"song_count"`
	Songs           Songs     `json:"-"`
	FavoriteCount   int       `json:"favorite_count"`
	IsFavorited     bool      `json:"is_favorited"`
	IsPublic        bool      `json:"is_public"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

type ResponseAPIAddPlaylist

type ResponseAPIAddPlaylist struct {
	ResponseAPIBase
	PlaylistULID string `json:"playlist_ulid"`
}

type ResponseAPIBase

type ResponseAPIBase struct {
	Result bool   `json:"result"`
	Status int    `json:"status"`
	Error  string `json:"error"`
}

func (ResponseAPIBase) ErrorMessage

func (r ResponseAPIBase) ErrorMessage() string

func (ResponseAPIBase) IsSuccess

func (r ResponseAPIBase) IsSuccess() bool

type ResponseAPIGetPlaylist

type ResponseAPIGetPlaylist struct {
	ResponseAPIBase
	Playlist Playlist `json:"playlist"`
}

type ResponseAPIGetPlaylists

type ResponseAPIGetPlaylists struct {
	ResponseAPIBase
	CreatedPlaylists   []Playlist `json:"created_playlists"`
	FavoritedPlaylists []Playlist `json:"favorited_playlists"`
}

type ResponseAPIGetPopularPlaylists

type ResponseAPIGetPopularPlaylists struct {
	ResponseAPIBase
	Playlists []Playlist `json:"playlists"`
}

type ResponseAPIGetRecentPlaylists

type ResponseAPIGetRecentPlaylists struct {
	ResponseAPIBase
	Playlists []Playlist `json:"playlists"`
}

type ResponseAdminBan

type ResponseAdminBan struct {
	ResponseAPIBase
	UserAccount string `json:"user_account"`
	DisplayName string `json:"display_name"`
	IsBan       bool   `json:"is_ban"`
}

type ResponseValidator

type ResponseValidator func(*http.Response) error

レスポンスを検証するバリデータ関数の型

func WithCacheControlPrivate

func WithCacheControlPrivate() ResponseValidator

func WithErrorResponse

func WithErrorResponse[T ResponseAPI]() ResponseValidator

func WithStatusCode

func WithStatusCode(statusCodes ...int) ResponseValidator

ステータスコードコードを検証するバリデータ関数を返す高階関数 例: ValidateResponse(res, WithStatusCode(200, 304))

func WithSuccessResponse

func WithSuccessResponse[T ResponseAPI](validates ...func(res T) error) ResponseValidator

type ResposeUpdatePlaylist

type ResposeUpdatePlaylist struct {
	ResponseAPIBase
	Name      string   `json:"name"`
	IsPublic  bool     `json:"is_public"`
	SongUILDs []string `json:"song_ulids"`
}

type Scenario

type Scenario struct {
	Option Option

	NormalUsers mapset.Set
	HeavyUsers  mapset.Set
	BannedUsers mapset.Set
	Songs       Songs
	AdminUser   *User

	Errors failure.Errors
	// contains filtered or unexported fields
}

オプションと全データを持つシナリオ構造体

func (*Scenario) AdminScenario

func (s *Scenario) AdminScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

AdminUserのシナリオ

func (*Scenario) AdminWorker

func (s *Scenario) AdminWorker(step *isucandar.BenchmarkStep, _ int32) (*worker.Worker, error)

func (*Scenario) AnonScenario

func (s *Scenario) AnonScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

匿名User

func (*Scenario) AnonWorker

func (s *Scenario) AnonWorker(step *isucandar.BenchmarkStep, p int32) (*worker.Worker, error)

ログインしないユーザーのシナリオ

func (*Scenario) BannedScenario

func (s *Scenario) BannedScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

Ban済みUserのシナリオ

func (*Scenario) BannedWorker

func (s *Scenario) BannedWorker(step *isucandar.BenchmarkStep, p int32) (*worker.Worker, error)

func (*Scenario) ChoiceUser

func (s *Scenario) ChoiceUser(ctx context.Context, pool mapset.Set) (*User, func())

func (*Scenario) FavoriteScenario

func (s *Scenario) FavoriteScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

新着Playlistにfav/add爆撃をするシナリオ

func (*Scenario) FavoriteWorker

func (s *Scenario) FavoriteWorker(step *isucandar.BenchmarkStep, p int32) (*worker.Worker, error)

func (*Scenario) LastPublicPlaylistCreatedAt

func (s *Scenario) LastPublicPlaylistCreatedAt() time.Time

func (*Scenario) Load

func (s *Scenario) Load(ctx context.Context, step *isucandar.BenchmarkStep) error

isucandar.PrepeareScenario を満たすメソッド isucandar.Benchmark の Load ステップで実行される

func (*Scenario) NormalScenario

func (s *Scenario) NormalScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

普通のUser

func (*Scenario) NormalWorker

func (s *Scenario) NormalWorker(step *isucandar.BenchmarkStep, p int32) (*worker.Worker, error)

func (*Scenario) Prepare

func (s *Scenario) Prepare(ctx context.Context, step *isucandar.BenchmarkStep) error

isucandar.PrepeareScenario を満たすメソッド isucandar.Benchmark の Prepare ステップで実行される

func (*Scenario) RateGetPopularPlaylists

func (s *Scenario) RateGetPopularPlaylists() int32

func (*Scenario) SetLastPublicPlaylistCreatedAt

func (s *Scenario) SetLastPublicPlaylistCreatedAt(t time.Time)

func (*Scenario) SetRateGetPopularPlaylists

func (s *Scenario) SetRateGetPopularPlaylists(rate int32)

func (*Scenario) ValidationScenario

func (s *Scenario) ValidationScenario(ctx context.Context, step *isucandar.BenchmarkStep) error

整合性検証シナリオ 自分で作ったplaylistを直後に削除したりするので、並列で実行するとfavした他人のplaylistが削除されて壊れる可能性がある 負荷テスト中には実行してはいけない

type Song

type Song struct {
	ULID       string `json:"ulid"`
	Title      string `json:"title"`
	ArtistName string `json:"artist_name"`
	ArtistID   int64  `json:"artist_id"`
}

type Songs

type Songs []*Song

func (Songs) ULIDs

func (ss Songs) ULIDs() []string

type User

type User struct {
	Account     string `json:"account"`
	Password    string `json:"password"`
	DisplayName string `json:"display_name"`
	IsBan       bool   `json:"is_ban"`
	IsHeavy     bool   `json:"is_heavy"`

	Agent *agent.Agent
	// contains filtered or unexported fields
}

func SignupAction

func SignupAction(ctx context.Context, ag *agent.Agent) (*User, *http.Response, error)

func (*User) GetAgent

func (u *User) GetAgent(o Option) (*agent.Agent, error)

type Users

type Users []*User

func (Users) Choice

func (us Users) Choice() *User

type ValidationError

type ValidationError struct {
	Errors []error
	Title  string
}

func ValidateResponse

func ValidateResponse(title string, step *isucandar.BenchmarkStep, res *http.Response, err error, validators ...ResponseValidator) ValidationError

レスポンスを検証する関数 複数のバリデータ関数を受け取ってすべてでレスポンスを検証し、 ValidationError を返す

func (ValidationError) Add

func (ValidationError) Error

func (v ValidationError) Error() string

error インターフェースを満たす Error メソッド

func (ValidationError) IsEmpty

func (v ValidationError) IsEmpty() bool

ValidationError が空かを判定

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL