Skip to content

Instantly share code, notes, and snippets.

@omuomugin
Created February 15, 2021 00:05
Show Gist options
  • Save omuomugin/d237751dd7b6494a6ec984b0437d34d6 to your computer and use it in GitHub Desktop.
Save omuomugin/d237751dd7b6494a6ec984b0437d34d6 to your computer and use it in GitHub Desktop.
ISUCONの準備用

mysqlのクエリ分析

set global slow_query_log = 1; # スロークエリのみ抽出
set global slow_query_log_file = '/path/to/mysql-slow.log';
set global long_query_time = 0; # 全てのクエリが出力される
set global log_queries_not_using_indexes = 1 # インデックスを利用してないクエリ (ログの出力先は、スロークエリと同じ)

long_query_time は、MySQL 5.1から1秒未満の値も設定できるようになったらしい

mysqldumpslow

https://dev.mysql.com/doc/refman/5.6/ja/mysqldumpslow.html

# 合計時間のソート
mysqldumpslow -s t /path/to/mysql-slow.log

# 1つのクエリの平均処理時間のソート
mysqldumpslow -s at /path/to/mysql-slow.log

リクエストの分析

https://github.com/matsuu/kataribe

バイナリ https://github.com/matsuu/kataribe/releases

Apache

Add %D to LogFormat.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D" with_time
CustomLog logs/access_log with_time

Nginx

Add $request_time to log_format.

log_format with_time '$remote_addr - $remote_user [$time_local] '
                     '"$request" $status $body_bytes_sent '
                     '"$http_referer" "$http_user_agent" $request_time';
access_log /var/log/nginx/access.log with_time;

VSCodeでSSH接続

https://qiita.com/nlog2n2/items/1d1358f6913249f3e186

VSCodeのプラグインの "Remote SSH" をインストール

SSH Key 作成

ssh-keygen -t rsa -b 2048 -f ~/.ssh/isucon_2021_omuomugin

SSH でマシンに入って、

touch ~/.ssh/authorized_key
chmode 700 ~/.ssh/authorized_key
vi ~/.ssh/authorized_key # SSH key を入力
cat ~/.ssh/authorized_key # 確認

ssh configの追加

ssh-agent
ssh-add -K /Users/<USERNAME>/.ssh/isucon_2021_omuomugin
ssh-add -l
# Host <YOUR USEAGE COMMENT>
Host <HOSTNAME>
  HostName 127.0.0.1
  User <USERNAME>
  Port 2222
  UserKnownHostsFile /dev/null
  PreferredAuthentications publickey
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/omuomugin/.ssh/isucon_2021_omuomugin
  IdentitiesOnly yes
  LogLevel FATAL
@mactkg
Copy link

mactkg commented Feb 15, 2021

pt-query-digest

curl --silent -L http://percona.com/get/pt-query-digest > /tmp/pt-query-digest &&
    sudo mv /tmp/pt-query-digest /usr/bin/pt-query-digest &&
    sudo chmod +x /usr/bin/pt-query-digest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment