Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAdminLogin(ctx context.Context, state *State) error
- func CheckAdminTopPage(ctx context.Context, state *State) error
- func CheckCancelReserveSheet(ctx context.Context, state *State) error
- func CheckCreateEvent(ctx context.Context, state *State) error
- func CheckCreateUser(ctx context.Context, state *State) error
- func CheckEventReport(ctx context.Context, state *State) error
- func CheckGetEvent(ctx context.Context, state *State) error
- func CheckLogin(ctx context.Context, state *State) error
- func CheckMyPage(ctx context.Context, state *State) error
- func CheckReport(ctx context.Context, state *State) error
- func CheckReserveSheet(ctx context.Context, state *State) error
- func CheckSheetReservationEntropy(ctx context.Context, state *State) error
- func CheckStaticFiles(ctx context.Context, state *State) error
- func CheckTopPage(ctx context.Context, state *State) error
- func FilterReservationsByUserID(src map[uint]*Reservation, userID uint) (filtered map[uint]*Reservation)
- func FilterReservationsToAllowDelay(src map[uint]*Reservation, timeBefore time.Time) (filtered map[uint]*Reservation)
- func GenerateInitialDataSetSQL(outputPath string)
- func GetBuffer() *bytes.Buffer
- func GetCheckerErrors() []error
- func GetLastCheckerError() (err error, t time.Time)
- func GetLastSlowPath() (path string, t time.Time)
- func GetRandomSheetNum(sheetRank string) uint
- func GetRandomSheetRank() string
- func GetRandomTargetHost() string
- func GetTargetHosts() []string
- func GuardCheckerError(guard bool)
- func IsCheckerFatal(err error) bool
- func IsCheckerTimeout(err error) bool
- func IsFatal(err error) bool
- func JoinCrc32(crcSum []byte) uint32
- func LoadAdminTopPage(ctx context.Context, state *State) error
- func LoadCreateUser(ctx context.Context, state *State) error
- func LoadEventReport(ctx context.Context, state *State) error
- func LoadGetEvent(ctx context.Context, state *State) error
- func LoadMyPage(ctx context.Context, state *State) error
- func LoadReport(ctx context.Context, state *State) error
- func LoadReserveCancelSheet(ctx context.Context, state *State) error
- func LoadReserveSheet(ctx context.Context, state *State) error
- func LoadTopPage(ctx context.Context, state *State) error
- func PrepareDataSet()
- func PutBuffer(buf *bytes.Buffer)
- func RandomAlphabetString(n int) string
- func SetTargetHosts(target []string)
- type Administrator
- type AppUser
- type AppUserStatus
- type BenchDataSet
- type CheckAction
- type Checker
- type CheckerError
- type CheckerTransport
- type Event
- type EventSheet
- type JsonAdministrator
- type JsonError
- type JsonEvent
- type JsonEventInFullReservation
- type JsonFullEvent
- type JsonFullReservation
- type JsonFullUser
- type JsonReservation
- type JsonSheet
- type JsonSheetDetail
- type JsonUser
- type ReportRecord
- type Reservation
- type ReservationTickets
- type Sheet
- type SheetKind
- type State
- func (s *State) BeginCancelation(lockedUser *AppUser, reservation *Reservation) (logID uint64)
- func (s *State) BeginReservation(lockedUser *AppUser, reservation *Reservation) (logID uint64)
- func (s *State) CommitCancelation(logID uint64, lockedUser *AppUser, reservation *Reservation)
- func (s *State) CommitReservation(logID uint64, lockedUser *AppUser, reservation *Reservation) error
- func (s *State) CreateNewEvent() (*Event, func(caller string))
- func (s *State) FindEventByID(id uint) *Event
- func (s *State) FindReservationByID(reservationID uint) *Reservation
- func (s *State) GetAdminChecker(u *Administrator) *Checker
- func (s *State) GetChecker(u *AppUser) *Checker
- func (s *State) GetCopiedEvents() (events []*Event)
- func (s *State) GetCopiedReservations() map[uint]*Reservation
- func (s *State) GetCopiedReservationsInEventID(eventID uint) map[uint]*Reservation
- func (s *State) GetEventByID(eventID uint) *Event
- func (s *State) GetEvents() (events []*Event)
- func (s *State) GetRandomNonCanceledReservationInEventID(eventID uint) *Reservation
- func (s *State) GetRandomPublicEvent() *Event
- func (s *State) GetRandomPublicSoldOutEvent() *Event
- func (s *State) GetReservations() map[uint]*Reservation
- func (s *State) GetReservationsInEventID(eventID uint) map[uint]*Reservation
- func (s *State) GetReserveRequestedCount() uint
- func (s *State) Init()
- func (s *State) PopEventSheet() (*EventSheet, func())
- func (s *State) PopNewUser() (*AppUser, *Checker, func())
- func (s *State) PopRandomAdministrator() (*Administrator, *Checker, func())
- func (s *State) PopRandomUser() (*AppUser, *Checker, func())
- func (s *State) PopUserByID(userID uint) (*AppUser, *Checker, func())
- func (s *State) PushAdministrator(u *Administrator)
- func (s *State) PushEventSheet(eventSheet *EventSheet)
- func (s *State) PushNewEvent(event *Event, createdAt time.Time, caller string)
- func (s *State) PushNewUser(u *AppUser)
- func (s *State) PushUser(u *AppUser)
- type StaticFile
Constants ¶
const ( ExpectedIndexHash = 888931047 ExpectedAdminHash = 3940591906 )
const TorbAppHost = "torb.example.com"
Variables ¶
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 )
var ( DataPath = "./data" DataSet BenchDataSet Rng = rand.New(rand.NewSource(42)) JST = time.FixedZone("Asia/Tokyo", 9*60*60) )
var NonReservedNum = uint(0)
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"}, } )
Functions ¶
func CheckCancelReserveSheet ¶
たまには売り切れイベントをキャンセルさせて、キャッシュしにくくさせる キャンセルを待ってイベントページをF5しているユーザもいる想定なのでキャンセルしてあげる (簡単のため)キャンセルしたら別のユーザですぐに予約する (簡単のため)Check関数にして1並列でしか動かないようにする (簡単のため)Check関数にして sold_out 状態に戻らなかったら fail
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 GetCheckerErrors ¶
func GetCheckerErrors() []error
func GetLastCheckerError ¶
func GetLastSlowPath ¶
func GetRandomSheetNum ¶
func GetRandomSheetRank ¶
func GetRandomSheetRank() string
func GetRandomTargetHost ¶
func GetRandomTargetHost() string
func GetTargetHosts ¶
func GetTargetHosts() []string
func GuardCheckerError ¶
func GuardCheckerError(guard bool)
func IsCheckerFatal ¶
func IsCheckerTimeout ¶
func LoadGetEvent ¶
売り切れたイベントをひたすらF5してキャンセルが出るのを待つユーザがいる
func LoadReserveCancelSheet ¶
席は(rank 内で)ランダムに割り当てられるため、良い席に当たるまで予約連打して、キャンセルする悪質ユーザがいる
func LoadTopPage ¶
イベントが公開されるのを待ってトップページをF5連打するユーザがいる イベント一覧はログインしていてもしていなくても取れる
func PrepareDataSet ¶
func PrepareDataSet()
func RandomAlphabetString ¶
func SetTargetHosts ¶
func SetTargetHosts(target []string)
Types ¶
type Administrator ¶
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 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 (*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
}
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 FilterPublicEvents ¶
func FilterSoldOutEvents ¶
func (*Event) GetReserveRequestedCount ¶
type EventSheet ¶
Represents a sheet within an event
type JsonAdministrator ¶
type JsonFullEvent ¶
type JsonFullReservation ¶
type JsonFullReservation struct { JsonReservation Event *JsonEventInFullReservation `json:"event"` Price uint `json:"price"` ReservedAt uint `json:"reserved_at"` CanceledAt uint `json:"canceled_at"` }
type JsonFullUser ¶
type JsonFullUser struct { JsonUser TotalPrice uint `json:"total_price"` RecentEvents []*JsonFullEvent `json:"recent_events"` RecentReservations []*JsonFullReservation `json:"recent_reservations"` }
{"nickname":"sonots","id":1001};
type JsonReservation ¶
type JsonSheet ¶
type JsonSheet struct { Price uint `json:"price"` Total uint `json:"total"` Remains uint `json:"remains"` Details []JsonSheetDetail `json:"detail"` }
type JsonSheetDetail ¶
type ReportRecord ¶
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) 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 SheetKind ¶
func GetSheetKindByRank ¶
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 (*State) FindEventByID ¶
func (*State) FindReservationByID ¶
func (s *State) FindReservationByID(reservationID uint) *Reservation
func (*State) GetAdminChecker ¶
func (s *State) GetAdminChecker(u *Administrator) *Checker
func (*State) GetChecker ¶
func (*State) GetCopiedEvents ¶
Returns a deep copy of s.events
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) GetRandomNonCanceledReservationInEventID ¶
func (s *State) GetRandomNonCanceledReservationInEventID(eventID uint) *Reservation
func (*State) GetRandomPublicEvent ¶
func (*State) GetRandomPublicSoldOutEvent ¶
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 (*State) PopEventSheet ¶
func (s *State) PopEventSheet() (*EventSheet, func())
func (*State) PopNewUser ¶
func (*State) PopRandomAdministrator ¶
func (s *State) PopRandomAdministrator() (*Administrator, *Checker, func())
func (*State) PopRandomUser ¶
func (*State) PushAdministrator ¶
func (s *State) PushAdministrator(u *Administrator)
func (*State) PushEventSheet ¶
func (s *State) PushEventSheet(eventSheet *EventSheet)