From ff918dda69ab11722ce3ec0a4142eeeeb158eb2b Mon Sep 17 00:00:00 2001 From: mickamy Date: Wed, 3 Jan 2024 11:00:34 +0900 Subject: [PATCH] =?UTF-8?q?DB=20=E3=81=AA=E3=81=A9=E8=89=B2=E3=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/config/my.server.cnf | 4 ++-- note.md | 45 ++++++++++++++++++++++++++++++++++++++ run.sh | 2 +- webapp/ruby/app.rb | 27 +++++++++++++++-------- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/admin/config/my.server.cnf b/admin/config/my.server.cnf index 84ad4238..4a6a6a9c 100644 --- a/admin/config/my.server.cnf +++ b/admin/config/my.server.cnf @@ -73,8 +73,8 @@ query_cache_size = 16M log_error = /var/log/mysql/error.log # # Here you can see queries with especially long duration -slow_query_log = 1 -slow_query_log_file = /var/log/mysql/mysql-slow.log +#slow_query_log = 1 +#slow_query_log_file = /var/log/mysql/mysql-slow.log #long_query_time = 2 #log-queries-not-using-indexes # diff --git a/note.md b/note.md index 1a208817..ac08152d 100644 --- a/note.md +++ b/note.md @@ -663,3 +663,48 @@ docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 4" 2024/01/03 01:19:25 投票者の感心がなくなりました 2024/01/03 01:19:25 {"score": 193855, "success": 121527, "failure": 0} ``` + +- slow query log を disable 185457 + +``` +❯ make bench +docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 4" +2024/01/03 01:23:30 Start GET /initialize +2024/01/03 01:23:30 期日前投票を開始します +2024/01/03 01:23:31 期日前投票が終了しました +2024/01/03 01:23:31 投票を開始します Workload: 4 +2024/01/03 01:24:16 投票が終了しました +2024/01/03 01:24:16 投票者が結果を確認しています +2024/01/03 01:24:31 投票者の感心がなくなりました +2024/01/03 01:24:31 {"score": 185457, "success": 115553, "failure": 0} +``` + +- ALTER TABLE users ADD INDEX (name, address, mynumber) 198013 + +``` +❯ make bench +docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 4" +2024/01/03 01:25:36 Start GET /initialize +2024/01/03 01:25:46 期日前投票を開始します +2024/01/03 01:25:47 期日前投票が終了しました +2024/01/03 01:25:47 投票を開始します Workload: 4 +2024/01/03 01:26:32 投票が終了しました +2024/01/03 01:26:32 投票者が結果を確認しています +2024/01/03 01:26:34 Get https://app:443/css/bootstrap.min.css: http2: client connection force closed via ClientConn.Close +2024/01/03 01:26:34 Get https://app:443/css/bootstrap.min.css: write tcp 172.18.0.3:44244->172.18.0.2:443: write: connection reset by peer +2024/01/03 01:26:34 Get https://app:443/: http2: client connection force closed via ClientConn.Close +2024/01/03 01:26:41 Get https://app:443/css/bootstrap.min.css: write tcp 172.18.0.3:48946->172.18.0.2:443: write: broken pipe +2024/01/03 01:26:41 Get https://app:443/css/bootstrap.min.css: http2: client connection force closed via ClientConn.Close +2024/01/03 01:26:47 投票者の感心がなくなりました +2024/01/03 01:26:47 {"score": 198013, "success": 122806, "failure": 5} +``` + +- posts の時のクエリをまとめる + +``` +``` + + + + + diff --git a/run.sh b/run.sh index a231ff2d..1e76f9b8 100755 --- a/run.sh +++ b/run.sh @@ -23,7 +23,7 @@ function run_ruby() { cd "/home/ishocon/webapp/$app_lang" sudo rm -rf /tmp/unicorn.pid make_tmp_file - unicorn -c unicorn_config.rb + unicorn -c unicorn_config.rb -E production } function run_python() { diff --git a/webapp/ruby/app.rb b/webapp/ruby/app.rb index 5b911569..bd88340a 100644 --- a/webapp/ruby/app.rb +++ b/webapp/ruby/app.rb @@ -102,6 +102,8 @@ def db_initialize db.query('ALTER TABLE votes ADD CONSTRAINT FOREIGN KEY (candidate_id) REFERENCES candidates (id)') db.query('ALTER TABLE votes ADD INDEX (candidate_id, count DESC)') # db.query('ALTER TABLE votes DROP COLUMN keyword') + db.query('ALTER TABLE users ADD INDEX (name, address, mynumber)') + db.query('ALTER TABLE votes ADD CONSTRAINT FOREIGN KEY (user_id) REFERENCES users (id)') end end @@ -165,18 +167,25 @@ def db_initialize end post '/vote' do - user = db.xquery('SELECT id, votes FROM users WHERE name = ? AND address = ? AND mynumber = ?', - params[:name], - params[:address], - params[:mynumber]).first + query = <