isucon10-recipe's People
isucon10-recipe's Issues
MySQL のスロークエリ解析
スロークエリログを解析すると、時間がかかってるクエリを調べることができる
セットアップ
デフォルト設定を読んで設定ファイルを置く場所を確認する
cat /etc/mysql/my.cnf | grep -v '#'
# ↓のような設定があればOK。なければ追加する
!includedir /etc/mysql/mysql.conf.d/
スロークエリログ用の設定ファイルを追加。後で簡単に消せるように別ファイルとして作る。多分rootユーザーじゃないと作れない
sudo vim /etc/mysql/mysql.conf.d/slow_query.cnf
[mysqld]
slow_query_log=1
long_query_time=0.5
log_queries_not_using_indexes=1
slow_query_log_file=/tmp/slow_query.log
log_query_time
以上の時間がかかったクエリ(↑の場合は0.5秒)が収集される。状況に応じてこの値を変えていくこと。収集結果は /tmp/slow_query.log
に保存される。
設定を追加したらMySQLサーバーを再起動する
sudo systemctl restart mysql.service
解析
ベンチマーカーを動かす前にログをきれいにしておく
sudo truncate /tmp/slow_query.log --size 0
ログを収集したら解析。詳しいオプションはこちらを参照 https://dev.mysql.com/doc/refman/5.6/ja/mysqldumpslow.html
mysqldumpslow /tmp/slow_query.log
インフラのスペック調査
今回は(多分)事前にマシンスペックや環境を知ることができないので、当日最初に調査すべき内容を列挙しておく。当日確認したらコンソールログを貼ると共にチェックボックスにチェックを入れること
チェックリスト
- OS
- ディストリビューションのバージョン
- CPUコア数
- メモリ
調査方法
OS
OSを調査。多分Debian系(Ubuntu)かRHEL系(CentOS/Amazon Linux)の2択。カーネルバージョンはヨクワカラナイけどディストリビューションがわかるだけで後の対応が変わるので調べておく
2020/08/31 Ubuntu らしいです
ディストリビューションのバージョン
cat /etc/lsb-release
CPUコア数
出てきた行数がコア数
grep processor /proc/cpuinfo
メモリ
-m
はメガバイト単位で表示するオプション
free -m
Webサーバーのアクセスログ解析
alp がド定番なので使い方をメモしておく。基本は↓を参照
https://github.com/tkuchiki/alp/blob/master/README.ja.md
事前準備
事前にalpで解析するためのログフォーマットに設定しておく必要がある
nginx
log_format ltsv "time:$time_local"
"\thost:$remote_addr"
"\tforwardedfor:$http_x_forwarded_for"
"\treq:$request"
"\tstatus:$status"
"\tmethod:$request_method"
"\turi:$request_uri"
"\tsize:$body_bytes_sent"
"\treferer:$http_referer"
"\tua:$http_user_agent"
"\treqtime:$request_time"
"\tcache:$upstream_http_x_cache"
"\truntime:$upstream_http_x_runtime"
"\tapptime:$upstream_response_time"
"\tvhost:$host";
access_log /var/log/nginx/access.log ltsv;
h2o
ISUCON8がこいつだったので一応
access-log:
format: "time:%t\thost:%h\tua:\"%{User-agent}i\"\tstatus:%s\treq:%r\turi:%U\tapptime:%{duration}x\tsize:%b\tmethod:%m"
解析
基本はパイプで渡す
cat /var/log/nginx/access.log | alp ltsv
パスパターンでまとめた秘伝のタレを作る
cat /var/log/nginx/access.log | alp ltsv --sort=avg -r -m '/hoge,/users/[0-9]*'
ログのリセット
削除してしまうとリロードが必要になってしまうので、 root 権限でファイルを空にする
sudo truncate /var/log/nginx/access.log --size 0
ミドルウェア・サービスの状況調査
インストールされているサービス一覧
主にWebサーバーとデータベースサーバーに何が使われているのか調査する目的。
sudo systemctl list-units -t service
WebサーバーがNginxなら良い。H2Oとか言われたら、、困った 🙄
データベースでよくあるのはMySQLかPostgreSQL。どちらかわかったらそのバージョンも調べる
# MySQL の場合
mysqld --version
# PostgreSQL の場合
psql --version
サービスの起動状況
次のサービスが自動起動する設定になってるかチェックする
- Webサーバー
- データベースサーバー
- Goアプリ(多分当日のマニュアルに書いてある)
sudo systemctl is-enabled <service_name>
enabled
と出ればOK。出なかったら有効にしておく
sudo systemctl enable <service_name>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.