Skip to content

Commit 7312c8d

Browse files
committed
初回ベンチ(DB index などは ruby から引き継ぎ) 357969
1 parent 8ed3d03 commit 7312c8d

File tree

7 files changed

+36
-13
lines changed

7 files changed

+36
-13
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
make pull || true
4242
make build
4343
timeout-minutes: 20
44-
- run: make up bench-with-db-init WORKLOAD=4
44+
- run: make up bench-with-db-init
4545
timeout-minutes: 10
4646
- name: Dump docker logs
4747
uses: jwalton/gh-docker-logs@v2

docker/app/go/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
RUN sudo apt-get update && \
5-
sudo apt-get install -y percona-toolkit && \
5+
sudo apt-get install -y zip percona-toolkit && \
66
sudo apt-get clean
77

88
# Go のインストール
@@ -15,6 +15,13 @@ ENV GOROOT /usr/local/go
1515
ENV GOPATH /home/ishocon/.local/go
1616
ENV PATH $PATH:$GOROOT/bin
1717

18+
# install alp
19+
RUN sudo curl -L -O https://github.com/tkuchiki/alp/releases/download/v1.0.21/alp_linux_${TARGETARCH}.zip && \
20+
sudo unzip alp_linux_${TARGETARCH}.zip && \
21+
sudo rm -rf unzip alp_linux_${TARGETARCH}.zip && \
22+
sudo mv alp /usr/local/bin/ && \
23+
alp --version
24+
1825
# アプリケーション
1926
COPY --chown=ishocon:ishocon webapp/ /home/ishocon/webapp
2027
RUN cd ~/webapp/go && \

note.go.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
初回ベンチ(DB index などは ruby から引き継ぎ) 357969
2+
3+
```
4+
❯ make bench
5+
docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 7"
6+
2024/01/09 09:42:23 Start GET /initialize
7+
2024/01/09 09:42:23 期日前投票を開始します
8+
2024/01/09 09:42:24 期日前投票が終了しました
9+
2024/01/09 09:42:24 投票を開始します Workload: 7
10+
2024/01/09 09:43:09 投票が終了しました
11+
2024/01/09 09:43:09 投票者が結果を確認しています
12+
2024/01/09 09:43:24 投票者の感心がなくなりました
13+
2024/01/09 09:43:24 {"score": 357969, "success": 234209, "failure": 0}
14+
```
15+

scripts/modify_db_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ALTER TABLE users ADD INDEX (name, address, mynumber);
22
ALTER TABLE candidates ADD INDEX (political_party);
33
ALTER TABLE votes ADD COLUMN count int(4) NOT NULL;
44
ALTER TABLE votes ADD INDEX (candidate_id, count);
5-
CREATE TABLE candidate_keywords
5+
CREATE TABLE IF NOT EXISTS candidate_keywords
66
(
77
id int(11) NOT NULL AUTO_INCREMENT,
88
candidate_id int(11) NOT NULL,

webapp/go/candidate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func getElectionResult() (result []CandidateElectionResult) {
9494
SELECT c.id, c.name, c.political_party, c.sex, IFNULL(v.count, 0)
9595
FROM candidates AS c
9696
LEFT OUTER JOIN
97-
(SELECT candidate_id, COUNT(*) AS count
97+
(SELECT candidate_id, IFNULL(SUM(count), 0) AS count
9898
FROM votes
9999
GROUP BY candidate_id) AS v
100100
ON c.id = v.candidate_id

webapp/go/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ func main() {
168168
} else if c.PostForm("keyword") == "" {
169169
message = "投票理由を記入してください"
170170
} else {
171-
for i := 1; i <= voteCount; i++ {
172-
createVote(user.ID, candidate.ID, c.PostForm("keyword"))
173-
}
171+
//for i := 1; i <= voteCount; i++ {
172+
// createVote(user.ID, candidate.ID, c.PostForm("keyword"))
173+
//}
174+
createVote(user.ID, candidate.ID, c.PostForm("keyword"), voteCount)
174175
message = "投票に成功しました"
175176
}
176177
c.HTML(http.StatusOK, "base", gin.H{

webapp/go/vote.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ type Vote struct {
1111
}
1212

1313
func getVoteCountByCandidateID(candidateID int) (count int) {
14-
row := db.QueryRow("SELECT COUNT(*) AS count FROM votes WHERE candidate_id = ?", candidateID)
14+
row := db.QueryRow("SELECT IFNULL(SUM(count), 0) AS count FROM votes WHERE candidate_id = ?", candidateID)
1515
row.Scan(&count)
1616
return
1717
}
1818

1919
func getUserVotedCount(userID int) (count int) {
20-
row := db.QueryRow("SELECT COUNT(*) AS count FROM votes WHERE user_id = ?", userID)
20+
row := db.QueryRow("SELECT count FROM votes WHERE user_id = ?", userID)
2121
row.Scan(&count)
2222
return
2323
}
2424

25-
func createVote(userID int, candidateID int, keyword string) {
26-
db.Exec("INSERT INTO votes (user_id, candidate_id, keyword) VALUES (?, ?, ?)",
27-
userID, candidateID, keyword)
25+
func createVote(userID int, candidateID int, keyword string, count int) {
26+
db.Exec("INSERT INTO votes (user_id, candidate_id, keyword, count) VALUES (?, ?, ?, ?)",
27+
userID, candidateID, keyword, count)
2828
}
2929

3030
func getVoiceOfSupporter(candidateIDs []int) (voices []string) {
@@ -37,7 +37,7 @@ func getVoiceOfSupporter(candidateIDs []int) (voices []string) {
3737
FROM votes
3838
WHERE candidate_id IN (`+strings.Join(strings.Split(strings.Repeat("?", len(candidateIDs)), ""), ",")+`)
3939
GROUP BY keyword
40-
ORDER BY COUNT(*) DESC
40+
ORDER BY IFNULL(SUM(count), 0) DESC
4141
LIMIT 10`, args...)
4242
if err != nil {
4343
return nil

0 commit comments

Comments
 (0)