From 80ba3890d119fbc9c9672654bab648c3b5198017 Mon Sep 17 00:00:00 2001 From: Minhyeok Park Date: Fri, 25 Oct 2024 11:46:27 +0900 Subject: [PATCH] feat: better random pricision --- main.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 2a1b817..d569ea3 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,8 @@ func main() { log.Fatalln("DATABASE_SCHEMA_NOT_FOUND") } + _, DISABLE_LARGE_POOL := os.LookupEnv("DISABLE_LARGE_POOL") + cfg := mysql.Config{ User: DATABASE_USER, Passwd: DATABASE_PASS, @@ -79,26 +81,28 @@ func main() { log.Fatalln("DATABASE_CONNECTION_FAILED") } - stopConn := false - log.Println("Creating large DB connection pool... Please wait...") - for i := 0; i < 7000; i++ { - db, err := sql.Open("mysql", cfg.FormatDSN()) - if err != nil { - log.Println("DATABASE_OPEN_FAILED") + if !DISABLE_LARGE_POOL { + stopConn := false + log.Println("Creating large DB connection pool... Please wait...") + for i := 0; i < 7000; i++ { + db, err := sql.Open("mysql", cfg.FormatDSN()) + if err != nil { + log.Println("DATABASE_OPEN_FAILED") + } + + _, err = db.Query("SELECT 1") + if err != nil { + stopConn = true + } } - _, err = db.Query("SELECT 1") - if err != nil { - stopConn = true + if stopConn { + log.Println("DATABASE_CONNECTION_FAILED") + 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{ DisableStartupMessage: true, }) @@ -270,7 +274,6 @@ func main() { go func() { for { - is_anon := gofakeit.IntN(10) > 3 preferred_categories, _ := weightedrand.NewChooser( weightedrand.Choice{Item: "Development", 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}, ) - for i := 1; i <= 100*60*5; i++ { + for i := 1; i <= 10*60*5; i++ { click_events := []string{} click_event_count := gofakeit.IntRange(1, 5) + is_anon := gofakeit.IntN(10) > 3 + if is_anon { 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\"}",