Skip to content

Commit

Permalink
枠数調整、サムネイルやプレイリストのURLをPOSTできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
tukeJonny committed Nov 2, 2023
1 parent ea26cee commit 7a45182
Show file tree
Hide file tree
Showing 7 changed files with 13,577 additions and 5,453 deletions.
2 changes: 1 addition & 1 deletion bench/internal/config/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const BaseAt = 1711900800

// 同時配信枠数
// NOTE: ベンチマーカー調整項目
const NumSlots = 2
const NumSlots = 5

// NOTE: 初期データ予約済みの1時間分を引く必要がある
const NumHours = (24 * 365) - 1
32 changes: 14 additions & 18 deletions bench/internal/scheduler/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ func ConvertFromIntInterface(i []interval.IntInterface) ([]*Reservation, error)

type Reservation struct {
// NOTE: id は、webappで割り振られるIDではなく、ReservationSchedulerが管理する上で利用するもの
id int
Title string
Description string
Tags []int
StartAt int64
EndAt int64
id int
Title string
Description string
StartAt int64
EndAt int64
PlaylistUrl string
ThumbnailUrl string
}

// FIXME: id, UserNameなど古い引数を廃止
// 初期データ生成スクリプト側修正後実施
func mustNewReservation(id int, UserName string, title string, description string, startAtStr string, endAtStr string) *Reservation {
func mustNewReservation(id int, title string, description string, startAtStr string, endAtStr string, playlistUrl, thumbnailUrl string) *Reservation {
startAt, err := time.Parse("2006-01-02 15:04:05", startAtStr)
if err != nil {
log.Fatalln(err)
Expand All @@ -47,19 +48,14 @@ func mustNewReservation(id int, UserName string, title string, description strin
log.Fatalln(err)
}

// FIXME: タグの採番がおかしくてwebappでエラーが出る
// tagCount := rand.Intn(10)
reservation := &Reservation{
id: id,
Title: title,
Description: description,
StartAt: startAt.Unix(),
EndAt: endAt.Unix(),
Title: title,
Description: description,
StartAt: startAt.Unix(),
EndAt: endAt.Unix(),
PlaylistUrl: playlistUrl,
ThumbnailUrl: thumbnailUrl,
}
// for i := 0; i < tagCount; i++ {
// tagIdx := rand.Intn(len(tagPool))
// reservation.Tags = append(reservation.Tags, tagIdx)
// }

return reservation
}
Expand Down
18,963 changes: 13,545 additions & 5,418 deletions bench/internal/scheduler/reservation_pool.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bench/scenario/core_pretest.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func Pretest(ctx context.Context, client *isupipe.Client) error {
Tags: tags,
Title: reservation.Title,
Description: reservation.Description,
PlaylistUrl: "https://d2jpkt808jogxx.cloudfront.net/BigBuckBunny/playlist.m3u8",
ThumbnailUrl: "https://picsum.photos/200/300",
PlaylistUrl: reservation.PlaylistUrl,
ThumbnailUrl: reservation.ThumbnailUrl,
StartAt: reservation.StartAt,
EndAt: reservation.EndAt,
})
Expand Down
4 changes: 2 additions & 2 deletions bench/scenario/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func BasicStreamerColdReserveScenario(
Tags: tags,
Title: reservation.Title,
Description: reservation.Description,
PlaylistUrl: "https://d2jpkt808jogxx.cloudfront.net/BigBuckBunny/playlist.m3u8",
ThumbnailUrl: "https://picsum.photos/200/300",
PlaylistUrl: reservation.PlaylistUrl,
ThumbnailUrl: reservation.ThumbnailUrl,
StartAt: reservation.StartAt,
EndAt: reservation.EndAt,
})
Expand Down
23 changes: 12 additions & 11 deletions scripts/generate_livestream_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@

fake = Faker('ja-JP')

# FIXME: playlist_url, thumbnail_urlが固定なので、データが用意でき次第置き換えるように
# FIXME: livestream_texts、もうちょっと増やしたい

# FIXME: id, usernameを外す
GO_FORMAT="\tmustNewReservation({id}, \"{username}\", \"{title}\", \"{description}\", \"{start_at}\", \"{end_at}\"),\n"
GO_FORMAT="\tmustNewReservation({id}, \"{title}\", \"{description}\", \"{start_at}\", \"{end_at}\", \"{playlist_url}\", \"{thumbnail_url}\"),\n"

playlists = [
"https://d2jpkt808jogxx.cloudfront.net/BigBuckBunny/playlist.m3u8",
]

thumbnails = [
"https://picsum.photos/200/300",
]

livestream_texts = [
("夜のゲーム実況!新作RPG攻略中","新しいRPGゲームを実況しながら進めていきます!みんなでワイワイ攻略しよう!",),
Expand Down Expand Up @@ -105,10 +112,6 @@
("歴史講座ライブ!戦国時代の英雄たち","歴史学者が、戦国時代の英雄たちやその背景を詳しく解説します",),
]

with open('./initial-data/autogenerated_usernames.txt', 'r') as f:
usernames = f.readlines()
usernames = list(username.rstrip() for username in usernames)

## 同一枠長の採用数制限
SAME_PATTERN_LIMIT = 500
# 時間枠のパターン(hourの粒度)
Expand Down Expand Up @@ -147,17 +150,17 @@ def create_timeslice(base_time, hours):
for schedule in schedules:
cursor_time = base_time
for hours in random.sample(schedule, len(schedule)): # スケジュール要素をシャッフル
username = (usernames[schedule_idx%len(usernames)])
title, description = livestream_texts[schedule_idx%len(livestream_texts)]
start_at, end_at = create_timeslice(cursor_time, hours)

go_schedules.append(GO_FORMAT.format(
id=schedule_idx,
username=username,
title=title,
description=description,
start_at=start_at.strftime("%Y-%m-%d %H:%M:%S"),
end_at=end_at.strftime("%Y-%m-%d %H:%M:%S"),
playlist_url=random.choice(playlists),
thumbnail_url=random.choice(thumbnails),
))

cursor_time = end_at
Expand All @@ -178,9 +181,7 @@ def get_args():
# max_schedulesは生成するスケジュールの最大数。枠数と一致する
# NOTE: 枠数を設定する場合、枠数だけスケジュールを重ねがけする
# すべてきれいに敷き詰めるように書いているので、単純に複数のスケジュール分SQL生成すればよい
parser.add_argument('-n', type=int, default=2, help='生成スケジュール数(=同一時間帯の枠数)')
# Goコードを生成する
parser.add_argument('--go', action='store_true', help='season2,3,4のスケジュールパターンのGoコードを生成')
parser.add_argument('-n', type=int, default=5, help='生成スケジュール数(=同一時間帯の枠数)')
parser.add_argument('--gopath', type=str, default='/tmp/livestream.go')

return parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion webapp/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
powerDNSSubdomainAddress string
dbConn *sqlx.DB
secret = []byte("isucon13_session_cookiestore_defaultsecret")
numReservationSlot = 2
numReservationSlot = 5
)

func init() {
Expand Down

0 comments on commit 7a45182

Please sign in to comment.