v0.0.0-...-fb07e6d Latest Latest

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

Go to latest
Published: Dec 6, 2019 License: MIT Imports: 38 Imported by: 0




View Source
const (
	ExpectedIndexHash = 888931047
	ExpectedAdminHash = 3940591906
View Source
const TorbAppHost = ""


View Source
var (
	RedirectAttemptedError = fmt.Errorf("redirect attempted")
	RequestTimeoutError    = fmt.Errorf("リクエストがタイムアウトしました")
	UserAgent              = "isucon8q-benchmarker"
	GetTimeout             = parameter.GetTimeout
	PostTimeout            = parameter.PostTimeout
	DeleteTimeout          = parameter.DeleteTimeout
	InitializeTimeout      = parameter.InitializeTimeout
	SlowThreshold          = parameter.SlowThreshold
	MaxCheckerRequest      = parameter.MaxCheckerRequest
	DebugMode              = false
View Source
var (
	DataPath = "./data"
	DataSet  BenchDataSet
	Rng      = rand.New(rand.NewSource(42))
	JST      = time.FixedZone("Asia/Tokyo", 9*60*60)
View Source
var NonReservedNum = uint(0)
View Source
var (
	StaticFiles = []*StaticFile{
		&StaticFile{"/css/admin.css", 684, "af8ea54a6883660979ab6e9d3b041a41"},
		&StaticFile{"/css/bootstrap.min.css", 140930, "a7022c6fa83d91db67738d6e3cd3252d"},
		&StaticFile{"/css/layout.css", 707, "25d20a88af77ba832e0d25a99ebe67c3"},
		&StaticFile{"/favicon.ico", 1092, "07b21a6c8984e04d108064c585411601"},
		&StaticFile{"/js/admin.js", 8454, "f3739b2c9ba150e2a2c4f53d7194fea2"},
		&StaticFile{"/js/app.js", 10204, "43f9dccae02a8dab134b20c053e41f7b"},
		&StaticFile{"/js/bootstrap-waitingfor.min.js", 2074, "c6167b2ec19dc56b16aa94511a15964c"},
		&StaticFile{"/js/bootstrap.bundle.min.js", 70682, "d70c474886678aebe3e9d91965dc8b62"},
		&StaticFile{"/js/fetch.min.js", 7337, "b72077f7f0fa3fc8f79a2fc57c15d827"},
		&StaticFile{"/js/jquery-3.3.1.slim.min.js", 69917, "99b0a83cf1b0b1e2cb16041520e87641"},
		&StaticFile{"/js/vue.min.js", 86452, "5283b86cbf48a538ee3cbebac633ccd4"},


func CheckAdminLogin

func CheckAdminLogin(ctx context.Context, state *State) error

func CheckAdminTopPage

func CheckAdminTopPage(ctx context.Context, state *State) error

func CheckCancelReserveSheet

func CheckCancelReserveSheet(ctx context.Context, state *State) error

たまには売り切れイベントをキャンセルさせて、キャッシュしにくくさせる キャンセルを待ってイベントページをF5しているユーザもいる想定なのでキャンセルしてあげる (簡単のため)キャンセルしたら別のユーザですぐに予約する (簡単のため)Check関数にして1並列でしか動かないようにする (簡単のため)Check関数にして sold_out 状態に戻らなかったら fail

func CheckCreateEvent

func CheckCreateEvent(ctx context.Context, state *State) error

func CheckCreateUser

func CheckCreateUser(ctx context.Context, state *State) error

func CheckEventReport

func CheckEventReport(ctx context.Context, state *State) error

func CheckGetEvent

func CheckGetEvent(ctx context.Context, state *State) error

func CheckLogin

func CheckLogin(ctx context.Context, state *State) error

func CheckMyPage

func CheckMyPage(ctx context.Context, state *State) error

func CheckReport

func CheckReport(ctx context.Context, state *State) error

func CheckReserveSheet

func CheckReserveSheet(ctx context.Context, state *State) error

func CheckSheetReservationEntropy

func CheckSheetReservationEntropy(ctx context.Context, state *State) error

func CheckStaticFiles

func CheckStaticFiles(ctx context.Context, state *State) error

func CheckTopPage

func CheckTopPage(ctx context.Context, state *State) error

func FilterReservationsByUserID

func FilterReservationsByUserID(src map[uint]*Reservation, userID uint) (filtered map[uint]*Reservation)

func FilterReservationsToAllowDelay

func FilterReservationsToAllowDelay(src map[uint]*Reservation, timeBefore time.Time) (filtered map[uint]*Reservation)

func GenerateInitialDataSetSQL

func GenerateInitialDataSetSQL(outputPath string)

func GetBuffer

func GetBuffer() *bytes.Buffer

func GetCheckerErrors

func GetCheckerErrors() []error

func GetLastCheckerError

func GetLastCheckerError() (err error, t time.Time)

func GetLastSlowPath

func GetLastSlowPath() (path string, t time.Time)

func GetRandomSheetNum

func GetRandomSheetNum(sheetRank string) uint

func GetRandomSheetRank

func GetRandomSheetRank() string

func GetRandomTargetHost

func GetRandomTargetHost() string

func GetTargetHosts

func GetTargetHosts() []string

func GuardCheckerError

func GuardCheckerError(guard bool)

func IsCheckerFatal

func IsCheckerFatal(err error) bool

func IsCheckerTimeout

func IsCheckerTimeout(err error) bool

func IsFatal

func IsFatal(err error) bool

func JoinCrc32

func JoinCrc32(crcSum []byte) uint32

func LoadAdminTopPage

func LoadAdminTopPage(ctx context.Context, state *State) error

func LoadCreateUser

func LoadCreateUser(ctx context.Context, state *State) error

func LoadEventReport

func LoadEventReport(ctx context.Context, state *State) error

func LoadGetEvent

func LoadGetEvent(ctx context.Context, state *State) error


func LoadMyPage

func LoadMyPage(ctx context.Context, state *State) error

func LoadReport

func LoadReport(ctx context.Context, state *State) error

func LoadReserveCancelSheet

func LoadReserveCancelSheet(ctx context.Context, state *State) error

席は(rank 内で)ランダムに割り当てられるため、良い席に当たるまで予約連打して、キャンセルする悪質ユーザがいる

func LoadReserveSheet

func LoadReserveSheet(ctx context.Context, state *State) error

func LoadTopPage

func LoadTopPage(ctx context.Context, state *State) error

イベントが公開されるのを待ってトップページをF5連打するユーザがいる イベント一覧はログインしていてもしていなくても取れる

func PrepareDataSet

func PrepareDataSet()

func PutBuffer

func PutBuffer(buf *bytes.Buffer)

func RandomAlphabetString

func RandomAlphabetString(n int) string

func SetTargetHosts

func SetTargetHosts(target []string)


type Administrator

type Administrator struct {
	ID        uint
	Nickname  string
	LoginName string
	Password  string

	Status struct {
		Online bool

type AppUser

type AppUser struct {
	ID        uint
	Nickname  string
	LoginName string
	Password  string

	Status AppUserStatus

type AppUserStatus

type AppUserStatus struct {
	Online bool

	PositiveTotalPrice uint
	NegativeTotalPrice uint

	LastReservedEvent      idWithUpdatedAt
	LastMaybeReservedEvent idWithUpdatedAt
	LastReservation        idWithUpdatedAt
	LastMaybeReservation   idWithUpdatedAt

func (*AppUserStatus) TotalPriceString

func (s *AppUserStatus) TotalPriceString() string

type BenchDataSet

type BenchDataSet struct {
	Users    []*AppUser
	NewUsers []*AppUser

	Administrators []*Administrator

	Events       []*Event
	ClosedEvents []*Event

	SheetTotal   uint
	SheetKinds   []*SheetKind
	SheetKindMap map[string]*SheetKind
	Sheets       []*Sheet

	Reservations []*Reservation

type CheckAction

type CheckAction struct {
	Method string
	Path   string

	ContentType string
	PostData    map[string]string // for "application/x-www-form-urlencoded"
	PostJSON    interface{}       // for "application/json"
	PostBody    io.Reader         // for others
	Headers     map[string]string

	ExpectedStatusCode int
	ExpectedLocation   *regexp.Regexp
	ExpectedHeaders    map[string]string
	Description        string
	CheckFunc          func(*http.Response, *bytes.Buffer) error

	EnableCache         bool
	DisableSlowChecking bool

	Timeout time.Duration

type Checker

type Checker struct {
	Client *http.Client
	Cache  *urlcache.CacheStore
	// contains filtered or unexported fields

func NewChecker

func NewChecker() *Checker

func (*Checker) NewRequest

func (c *Checker) NewRequest(method, uri string, body io.Reader) (*http.Request, error)

func (*Checker) OnError

func (c *Checker) OnError(a *CheckAction, req *http.Request, err error) error

func (*Checker) Play

func (c *Checker) Play(ctx context.Context, a *CheckAction) error

func (*Checker) ResetCookie

func (c *Checker) ResetCookie()

type CheckerError

type CheckerError struct {
	// contains filtered or unexported fields

func (*CheckerError) Error

func (e *CheckerError) Error() string

func (*CheckerError) IsFatal

func (e *CheckerError) IsFatal() bool

func (*CheckerError) IsTimeout

func (e *CheckerError) IsTimeout() bool

type CheckerTransport

type CheckerTransport struct {
	// contains filtered or unexported fields

func (*CheckerTransport) RoundTrip

func (ct *CheckerTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Event

type Event struct {
	ID        uint
	Title     string
	PublicFg  bool
	ClosedFg  bool
	Price     uint
	CreatedAt time.Time

	ReserveRequestedCount uint
	ReserveCompletedCount uint
	CancelRequestedCount  uint
	CancelCompletedCount  uint
	ReserveRequestedRT    ReservationTickets
	ReserveCompletedRT    ReservationTickets
	CancelRequestedRT     ReservationTickets
	CancelCompletedRT     ReservationTickets
	// contains filtered or unexported fields

func CopyEvent

func CopyEvent(src *Event) *Event

func FilterEventsToAllowDelay

func FilterEventsToAllowDelay(src []*Event, timeBefore time.Time) (filtered []*Event)

func FilterPublicEvents

func FilterPublicEvents(src []*Event) (filtered []*Event)

func FilterSoldOutEvents

func FilterSoldOutEvents(src []*Event) (filtered []*Event)

func (*Event) GetReserveRequestedCount

func (e *Event) GetReserveRequestedCount() uint

func (*Event) IsSoldOut

func (e *Event) IsSoldOut() bool

Returns an optimistic sold-out prediction, I mean that, returns true even if a few sheets are actually remained when some timeout occurs.

type EventSheet

type EventSheet struct {
	EventID uint
	Rank    string
	Num     uint
	Price   uint

Represents a sheet within an event

type JsonAdministrator

type JsonAdministrator struct {
	ID       uint   `json:"id"`
	Nickname string `json:"nickname"`

type JsonError

type JsonError struct {
	Error string `json:"error"`

type JsonEvent

type JsonEvent struct {
	ID      uint                 `json:"id"`
	Title   string               `json:"title"`
	Total   uint                 `json:"total"`
	Remains uint                 `json:"remains"`
	Sheets  map[string]JsonSheet `json:"sheets"`

type JsonEventInFullReservation

type JsonEventInFullReservation struct {
	ID     uint   `json:"id"`
	Title  string `json:"title"`
	Public bool   `json:"public"`
	Closed bool   `json:"closed"`

type JsonFullEvent

type JsonFullEvent struct {

	Price  uint `json:"price"`
	Public bool `json:"public"`
	Closed bool `json:"closed"`

type JsonFullReservation

type JsonFullReservation struct {

	Event      *JsonEventInFullReservation `json:"event"`
	Price      uint                        `json:"price"`
	ReservedAt uint                        `json:"reserved_at"`
	CanceledAt uint                        `json:"canceled_at"`

type JsonFullUser

type JsonFullUser struct {

	TotalPrice         uint                   `json:"total_price"`
	RecentEvents       []*JsonFullEvent       `json:"recent_events"`
	RecentReservations []*JsonFullReservation `json:"recent_reservations"`


type JsonReservation

type JsonReservation struct {
	ReservationID uint   `json:"id"`
	SheetRank     string `json:"sheet_rank"`
	SheetNum      uint   `json:"sheet_num"`

type JsonSheet

type JsonSheet struct {
	Price   uint              `json:"price"`
	Total   uint              `json:"total"`
	Remains uint              `json:"remains"`
	Details []JsonSheetDetail `json:"detail"`

type JsonSheetDetail

type JsonSheetDetail struct {
	Num        uint `json:"num"`
	Mine       bool `json:"mine"`
	Reserved   bool `json:"reserved"`
	ReservedAt uint `json:"reserved_at"`

type JsonUser

type JsonUser struct {
	ID       uint   `json:"id"`
	Nickname string `json:"nickname"`


type ReportRecord

type ReportRecord struct {
	ReservationID uint
	EventID       uint
	SheetRank     string
	SheetNum      uint
	SheetPrice    uint
	UserID        uint
	CanceledAt    time.Time

type Reservation

type Reservation struct {
	ID         uint
	EventID    uint
	UserID     uint
	SheetID    uint // Used only in initial reservations. 0 is set for rest because reserve API does not return it
	SheetRank  string
	SheetNum   uint
	Price      uint
	ReservedAt int64 // Used only in initial reservations. 0 is set for rest because reserve API does not return it
	CanceledAt int64 // Used only in initial reservations. 0 is set for rest because reserve API does not return it

	// ReserveRequestedAt time.Time
	ReserveCompletedAt time.Time

	CancelRequestedAt time.Time
	CancelCompletedAt time.Time
	// contains filtered or unexported fields

func (Reservation) CancelMtx

func (r Reservation) CancelMtx() trylock.Mutex

func (Reservation) Canceled

func (r Reservation) Canceled(timeBefore time.Time) bool

func (Reservation) LastMaybeUpdatedAt

func (r Reservation) LastMaybeUpdatedAt() time.Time

func (Reservation) LastUpdatedAt

func (r Reservation) LastUpdatedAt() time.Time

func (Reservation) MaybeCanceled

func (r Reservation) MaybeCanceled(timeBefore time.Time) bool

type ReservationTickets

type ReservationTickets struct {
	S, A, B, C uint

func (*ReservationTickets) Get

func (rt *ReservationTickets) Get(rank string) uint

type Sheet

type Sheet struct {
	ID    uint
	Rank  string
	Num   uint // ID within a rank
	Price uint

type SheetKind

type SheetKind struct {
	Rank  string
	Total uint
	Price uint

func GetSheetKindByRank

func GetSheetKindByRank(rank string) *SheetKind

type State

type State struct {
	// contains filtered or unexported fields

func (*State) BeginCancelation

func (s *State) BeginCancelation(lockedUser *AppUser, reservation *Reservation) (logID uint64)

func (*State) BeginReservation

func (s *State) BeginReservation(lockedUser *AppUser, reservation *Reservation) (logID uint64)

func (*State) CommitCancelation

func (s *State) CommitCancelation(logID uint64, lockedUser *AppUser, reservation *Reservation)

func (*State) CommitReservation

func (s *State) CommitReservation(logID uint64, lockedUser *AppUser, reservation *Reservation) error

func (*State) CreateNewEvent

func (s *State) CreateNewEvent() (*Event, func(caller string))

func (*State) FindEventByID

func (s *State) FindEventByID(id uint) *Event

func (*State) FindReservationByID

func (s *State) FindReservationByID(reservationID uint) *Reservation

func (*State) GetAdminChecker

func (s *State) GetAdminChecker(u *Administrator) *Checker

func (*State) GetChecker

func (s *State) GetChecker(u *AppUser) *Checker

func (*State) GetCopiedEvents

func (s *State) GetCopiedEvents() (events []*Event)

Returns a deep copy of

func (*State) GetCopiedReservations

func (s *State) GetCopiedReservations() map[uint]*Reservation

Returns a deep copy of s.reservations NOTE: This could be slow if s.reservations are large, but we assume that len(s.reservations) are less than 10,000 even in very fast webapp implementation.

func (*State) GetCopiedReservationsInEventID

func (s *State) GetCopiedReservationsInEventID(eventID uint) map[uint]*Reservation

Returns a filtered deep copy

func (*State) GetEventByID

func (s *State) GetEventByID(eventID uint) *Event


func (*State) GetEvents

func (s *State) GetEvents() (events []*Event)

Returns a shallow copy of

func (*State) GetRandomNonCanceledReservationInEventID

func (s *State) GetRandomNonCanceledReservationInEventID(eventID uint) *Reservation

func (*State) GetRandomPublicEvent

func (s *State) GetRandomPublicEvent() *Event

func (*State) GetRandomPublicSoldOutEvent

func (s *State) GetRandomPublicSoldOutEvent() *Event

func (*State) GetReservations

func (s *State) GetReservations() map[uint]*Reservation

Returns a shallow copy of s.reservations

func (*State) GetReservationsInEventID

func (s *State) GetReservationsInEventID(eventID uint) map[uint]*Reservation

Returns a filtered shallow copy

func (*State) GetReserveRequestedCount

func (s *State) GetReserveRequestedCount() uint

func (*State) Init

func (s *State) Init()

func (*State) PopEventSheet

func (s *State) PopEventSheet() (*EventSheet, func())

func (*State) PopNewUser

func (s *State) PopNewUser() (*AppUser, *Checker, func())

func (*State) PopRandomAdministrator

func (s *State) PopRandomAdministrator() (*Administrator, *Checker, func())

func (*State) PopRandomUser

func (s *State) PopRandomUser() (*AppUser, *Checker, func())

func (*State) PopUserByID

func (s *State) PopUserByID(userID uint) (*AppUser, *Checker, func())

func (*State) PushAdministrator

func (s *State) PushAdministrator(u *Administrator)

func (*State) PushEventSheet

func (s *State) PushEventSheet(eventSheet *EventSheet)

func (*State) PushNewEvent

func (s *State) PushNewEvent(event *Event, createdAt time.Time, caller string)

func (*State) PushNewUser

func (s *State) PushNewUser(u *AppUser)

func (*State) PushUser

func (s *State) PushUser(u *AppUser)

type StaticFile

type StaticFile struct {
	Path string
	Size int64
	Hash string


Path Synopsis

Jump to

Keyboard shortcuts

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