feat: better random pricision

This commit is contained in:
Minhyeok Park 2024-10-25 11:46:27 +09:00
parent bd2c08aa53
commit 80ba3890d1
Signed by: pmh_only
SSH Key Fingerprint: SHA256:g/OyGvi2pcd8ub9mqge/ohmDP0fZX/xOPWPIcM+9XpI

39
main.go
View File

@ -60,6 +60,8 @@ func main() {
log.Fatalln("DATABASE_SCHEMA_NOT_FOUND") log.Fatalln("DATABASE_SCHEMA_NOT_FOUND")
} }
_, DISABLE_LARGE_POOL := os.LookupEnv("DISABLE_LARGE_POOL")
cfg := mysql.Config{ cfg := mysql.Config{
User: DATABASE_USER, User: DATABASE_USER,
Passwd: DATABASE_PASS, Passwd: DATABASE_PASS,
@ -79,26 +81,28 @@ func main() {
log.Fatalln("DATABASE_CONNECTION_FAILED") log.Fatalln("DATABASE_CONNECTION_FAILED")
} }
stopConn := false if !DISABLE_LARGE_POOL {
log.Println("Creating large DB connection pool... Please wait...") stopConn := false
for i := 0; i < 7000; i++ { log.Println("Creating large DB connection pool... Please wait...")
db, err := sql.Open("mysql", cfg.FormatDSN()) for i := 0; i < 7000; i++ {
if err != nil { db, err := sql.Open("mysql", cfg.FormatDSN())
log.Println("DATABASE_OPEN_FAILED") if err != nil {
log.Println("DATABASE_OPEN_FAILED")
}
_, err = db.Query("SELECT 1")
if err != nil {
stopConn = true
}
} }
_, err = db.Query("SELECT 1") if stopConn {
if err != nil { log.Println("DATABASE_CONNECTION_FAILED")
stopConn = true log.Println("Ctrl+C to terminate DB connection pool")
<-make(chan int)
} }
} }
if stopConn {
log.Println("DATABASE_CONNECTION_FAILED")
log.Println("Ctrl+C to terminate DB connection pool")
<-make(chan int)
}
app := fiber.New(fiber.Config{ app := fiber.New(fiber.Config{
DisableStartupMessage: true, DisableStartupMessage: true,
}) })
@ -270,7 +274,6 @@ func main() {
go func() { go func() {
for { for {
is_anon := gofakeit.IntN(10) > 3
preferred_categories, _ := weightedrand.NewChooser( preferred_categories, _ := weightedrand.NewChooser(
weightedrand.Choice{Item: "Development", Weight: gofakeit.UintN(10) + 1}, weightedrand.Choice{Item: "Development", Weight: gofakeit.UintN(10) + 1},
weightedrand.Choice{Item: "Novel", Weight: gofakeit.UintN(10) + 1}, weightedrand.Choice{Item: "Novel", Weight: gofakeit.UintN(10) + 1},
@ -281,9 +284,11 @@ func main() {
weightedrand.Choice{Item: "Science", Weight: gofakeit.UintN(10) + 1}, weightedrand.Choice{Item: "Science", Weight: gofakeit.UintN(10) + 1},
) )
for i := 1; i <= 100*60*5; i++ { for i := 1; i <= 10*60*5; i++ {
click_events := []string{} click_events := []string{}
click_event_count := gofakeit.IntRange(1, 5) click_event_count := gofakeit.IntRange(1, 5)
is_anon := gofakeit.IntN(10) > 3
if is_anon { if is_anon {
for j := 0; j < click_event_count; j++ { for j := 0; j < click_event_count; j++ {
click_events = append(click_events, fmt.Sprintf("{\"type\":\"click\",\"details\":{\"element\":\".%s\",\"content\":{\"item_name\":\"%s\",\"item_category\":\"%s\",\"item_location\":\"%s\"}},\"credentials\":{\"session_id\":null,\"session_issuer\":null,\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}", click_events = append(click_events, fmt.Sprintf("{\"type\":\"click\",\"details\":{\"element\":\".%s\",\"content\":{\"item_name\":\"%s\",\"item_category\":\"%s\",\"item_location\":\"%s\"}},\"credentials\":{\"session_id\":null,\"session_issuer\":null,\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}",