diff --git a/note.go.md b/note.go.md index d0917f3..eeea59f 100644 --- a/note.go.md +++ b/note.go.md @@ -13,3 +13,81 @@ docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 7" 2024/01/09 09:43:24 {"score": 357969, "success": 234209, "failure": 0} ``` +alp の結果。go が速すぎて笑う + +``` +ishocon@2ee24875c3fc:~/scripts$ run_pt-query.sh ++ rm -rf sloq-query.log.analyzed ++ pt-query-digest --type slowlog /var/log/mysql/slow-query.log +^C# Caught SIGINT. +^C# Exiting on SIGINT. +ishocon@2ee24875c3fc:~/scripts$ exit + +~/ghq/github.com/mickamy/ISHOCON2 try-with-go-lang* 4m 18s +❯ docker exec -it ishocon2-app-1 bash +ishocon@420e599cf577:~$ htop +ishocon@420e599cf577:~$ cd scripts/ +ishocon@420e599cf577:~/scripts$ ls +modify_db_schema.sql run_alp.sh run_pt-query.sh +ishocon@420e599cf577:~/scripts$ ./run_alp.sh ++ sudo cat /var/log/nginx/access.log ++ alp ltsv --sort sum -o count,2xx,3xx,4xx,5xx,method,uri,avg,sum ++--------+--------+-----+-----+-----+--------+--------------------------------------------------------------------------------------+-------+---------+ +| COUNT | 2XX | 3XX | 4XX | 5XX | METHOD | URI | AVG | SUM | ++--------+--------+-----+-----+-----+--------+--------------------------------------------------------------------------------------+-------+---------+ +| 1000 | 1000 | 0 | 0 | 0 | GET | /candidates/20 | 0.000 | 0.001 | +| 976 | 976 | 0 | 0 | 0 | GET | /candidates/23 | 0.000 | 0.001 | +| 6970 | 6970 | 0 | 0 | 0 | GET | /political_parties/%E5%9B%BD%E6%B0%91%E5%85%83%E6%B0%97%E5%85%9A | 0.000 | 0.001 | +| 920 | 920 | 0 | 0 | 0 | GET | /candidates/24 | 0.000 | 0.003 | +| 1 | 1 | 0 | 0 | 0 | GET | /initialize | 0.004 | 0.004 | +| 961 | 961 | 0 | 0 | 0 | GET | /candidates/13 | 0.000 | 0.004 | +| 903 | 903 | 0 | 0 | 0 | GET | /candidates/29 | 0.000 | 0.004 | +| 937 | 937 | 0 | 0 | 0 | GET | /candidates/8 | 0.000 | 0.005 | +| 929 | 929 | 0 | 0 | 0 | GET | /candidates/10 | 0.000 | 0.005 | +| 933 | 933 | 0 | 0 | 0 | GET | /candidates/14 | 0.000 | 0.006 | +| 930 | 930 | 0 | 0 | 0 | GET | /candidates/30 | 0.000 | 0.006 | +| 965 | 965 | 0 | 0 | 0 | GET | /candidates/25 | 0.000 | 0.007 | +| 913 | 913 | 0 | 0 | 0 | GET | /candidates/17 | 0.000 | 0.007 | +| 926 | 926 | 0 | 0 | 0 | GET | /candidates/12 | 0.000 | 0.007 | +| 943 | 943 | 0 | 0 | 0 | GET | /candidates/9 | 0.000 | 0.009 | +| 947 | 947 | 0 | 0 | 0 | GET | /candidates/5 | 0.000 | 0.010 | +| 897 | 897 | 0 | 0 | 0 | GET | /candidates/27 | 0.000 | 0.010 | +| 905 | 905 | 0 | 0 | 0 | GET | /candidates/22 | 0.000 | 0.011 | +| 959 | 959 | 0 | 0 | 0 | GET | /candidates/26 | 0.000 | 0.012 | +| 940 | 940 | 0 | 0 | 0 | GET | /candidates/6 | 0.000 | 0.014 | +| 894 | 894 | 0 | 0 | 0 | GET | /candidates/15 | 0.000 | 0.014 | +| 933 | 933 | 0 | 0 | 0 | GET | /candidates/7 | 0.000 | 0.015 | +| 931 | 931 | 0 | 0 | 0 | GET | /candidates/2 | 0.000 | 0.015 | +| 928 | 928 | 0 | 0 | 0 | GET | /candidates/1 | 0.000 | 0.016 | +| 876 | 876 | 0 | 0 | 0 | GET | /candidates/18 | 0.000 | 0.017 | +| 956 | 956 | 0 | 0 | 0 | GET | /candidates/11 | 0.000 | 0.017 | +| 897 | 897 | 0 | 0 | 0 | GET | /candidates/19 | 0.000 | 0.017 | +| 994 | 994 | 0 | 0 | 0 | GET | /candidates/3 | 0.000 | 0.019 | +| 921 | 921 | 0 | 0 | 0 | GET | /candidates/16 | 0.000 | 0.022 | +| 917 | 917 | 0 | 0 | 0 | GET | /candidates/28 | 0.000 | 0.023 | +| 925 | 925 | 0 | 0 | 0 | GET | /candidates/21 | 0.000 | 0.030 | +| 6874 | 6874 | 0 | 0 | 0 | GET | /political_parties/%E5%9B%BD%E6%B0%91%E5%B9%B3%E5%92%8C%E5%85%9A | 0.000 | 0.058 | +| 910 | 910 | 0 | 0 | 0 | GET | /candidates/4 | 0.000 | 0.073 | +| 7155 | 7155 | 0 | 0 | 0 | GET | /political_parties/%E5%A4%A2%E5%AE%9F%E7%8F%BE%E5%85%9A | 0.000 | 0.122 | +| 7066 | 7066 | 0 | 0 | 0 | GET | /political_parties/%E5%9B%BD%E6%B0%9110%E4%BA%BA%E5%A4%A7%E6%B4%BB%E8%BA%8D%E5%85%9A | 0.000 | 0.228 | +| 60344 | 60344 | 0 | 0 | 0 | GET | /css/bootstrap.min.css | 0.000 | 0.342 | +| 4317 | 4317 | 0 | 0 | 0 | GET | / | 0.016 | 70.004 | +| 102955 | 102955 | 0 | 0 | 0 | POST | /vote | 0.003 | 314.879 | ++--------+--------+-----+-----+-----+--------+--------------------------------------------------------------------------------------+-------+---------+ +``` + +candidates のキャッシュをしようとする 358429 + +``` +❯ make bench +docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 7" +2024/01/09 10:48:10 Start GET /initialize +2024/01/09 10:48:10 期日前投票を開始します +2024/01/09 10:48:10 期日前投票が終了しました +2024/01/09 10:48:10 投票を開始します Workload: 7 +2024/01/09 10:48:55 投票が終了しました +2024/01/09 10:48:55 投票者が結果を確認しています +2024/01/09 10:49:10 投票者の感心がなくなりました +2024/01/09 10:49:10 {"score": 358429, "success": 236589, "failure": 0} +``` + diff --git a/webapp/go/main.go b/webapp/go/main.go index 715680f..6324898 100644 --- a/webapp/go/main.go +++ b/webapp/go/main.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "html/template" + "log" "net/http" "os" "sort" @@ -41,6 +42,8 @@ func main() { store.Options(sessions.Options{HttpOnly: true}) r.Use(sessions.Sessions("showwin_happy", store)) + candidates := getAllCandidate() + // GET / r.GET("/", func(c *gin.Context) { electionResults := getElectionResult() @@ -51,7 +54,23 @@ func main() { candidates := tmp[:10] candidates = append(candidates, tmp[len(tmp)-1]) - partyNames := getAllPartyName() + partyNameMap := make(map[string]bool) + partyNames := []string{} + for _, can := range candidates { + partyName := can.PoliticalParty + if _, value := partyNameMap[partyName]; !value { + partyNameMap[partyName] = true + partyNames = append(partyNames, partyName) + } + } + + // Sort partyNames + sort.Strings(partyNames) + + // log partyNames value for debug + log.Println(partyNames) + + //partyNames := getAllPartyName() partyResultMap := map[string]int{} for _, name := range partyNames { partyResultMap[name] = 0 @@ -93,6 +112,15 @@ func main() { // GET /candidates/:candidateID(int) r.GET("/candidates/:candidateID", func(c *gin.Context) { candidateID, _ := strconv.Atoi(c.Param("candidateID")) + //var candidate *Candidate + //for _, can := range candidates { + // if can.ID == candidateID { + // candidate = &can + // } + //} + //if candidate == nil { + // c.Redirect(http.StatusFound, "/") + //} candidate, err := getCandidate(candidateID) if err != nil { c.Redirect(http.StatusFound, "/") @@ -120,10 +148,16 @@ func main() { } } - candidates := getCandidatesByPoliticalParty(partyName) + var candidatesByParty []Candidate + for _, can := range candidates { + if can.PoliticalParty == partyName { + candidatesByParty = append(candidatesByParty, can) + } + } + //candidatesByParty := getCandidatesByPoliticalParty(partyName) candidateIDs := []int{} - for _, c := range candidates { - candidateIDs = append(candidateIDs, c.ID) + for _, can := range candidatesByParty { + candidateIDs = append(candidateIDs, can.ID) } keywords := getVoiceOfSupporter(candidateIDs) @@ -131,15 +165,13 @@ func main() { c.HTML(http.StatusOK, "base", gin.H{ "politicalParty": partyName, "votes": votes, - "candidates": candidates, + "candidates": candidatesByParty, "keywords": keywords, }) }) // GET /vote r.GET("/vote", func(c *gin.Context) { - candidates := getAllCandidate() - r.SetHTMLTemplate(template.Must(template.ParseFiles(layout, "templates/vote.tmpl"))) c.HTML(http.StatusOK, "base", gin.H{ "candidates": candidates, @@ -150,9 +182,15 @@ func main() { // POST /vote r.POST("/vote", func(c *gin.Context) { user, userErr := getUser(c.PostForm("name"), c.PostForm("address"), c.PostForm("mynumber")) + //var candidate *Candidate + //for _, can := range candidates { + // if can.Name == c.PostForm("candidate") { + // candidate = &can + // } + //} candidate, cndErr := getCandidateByName(c.PostForm("candidate")) + votedCount := getUserVotedCount(user.ID) - candidates := getAllCandidate() voteCount, _ := strconv.Atoi(c.PostForm("vote_count")) var message string @@ -163,6 +201,7 @@ func main() { message = "投票数が上限を超えています" } else if c.PostForm("candidate") == "" { message = "候補者を記入してください" + //} else if candidate == nil { } else if cndErr != nil { message = "候補者を正しく記入してください" } else if c.PostForm("keyword") == "" {