55 views
# ISUCON13 当日用 初動まとめ 転記 ## リンク集 - Grafana メトリクス http://g.isucon.ikura-hamu.work/d/aaee4b4e-1317-4d73-895f-59c4fed3bcb0/isucon?orgId=1&refresh=5s - user: `admin` - password: `reactive` - Grafana systemdのログ http://g.isucon.ikura-hamu.work/d/d8a18ab6-d6c8-4778-8fb8-d1919d2c6fb9/log?orgId=1&refresh=5s - adminer http://a.isucon.ikura-hamu.work/?server=s1&username=isucon - user: `reactive` - password: `reactive` - Prometheus http://pro.isucon.ikura-hamu.work/graph?g0.expr=&g0.tab=1&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h - スプレッドシート https://docs.google.com/spreadsheets/d/1E7EnZRK4FkVZg6ZHqu7c2T5xCQ0KonsBqf34Ea2hc3Y/edit?usp=sharing - pprotein http://p.isucon.ikura-hamu.work/#/group/ - github https://github.com/reactive-futakotamagawa/isucon13 --- - もしもの時のMD https://hackmd.io/p8WueKggSQmcBsGtA9GciA?view - oribeさんの講習会 https://hackmd.io/@oribe/BkGXfhKj5 - NaruseJunチートシート https://hackmd.io/Gc1eohcqS4SRNglveyjkbA - ことしの講習会 https://isucon-workshop.trap.show/?ref=trap.jp --- ## 初動 :::spoiler **Goのバージョンを上げる** :::success ```bash which go wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz rm -rf /home/isucon/local/go tar -C /home/isucon/local -xzf go1.21.4.linux-amd64.tar.gz rm go1.21.4.linux-amd64.tar.gz sudo nano .profile export PATH=$PATH:$HOME/local/go/bin ``` ::: - H1rono pproteinをコードに仕込む。 - https://github.com/reactive-futakotamagawa/private-isu/commit/8a0dafcbbaec7c51378fb78f03a2f293835b6fc4 - ↑initializeのURLは、http://p.isucon.ikura-hamu.work からコピーしたやつ - `go mod tidy` - `go build -o {ファイル名}` - `sudo systemctl restart {サービス名}` - ベンチマークを回す **pikachu サーバーに入って、設定を読む** :::success **絶対パスで** 注意: systemctlでCGroupの親プロセスを確認しておく、Dockerかどうかも確かめる。 - Git管理するリポジトリの絶対パス - `/home/isucon` - nginxのサービス名 - `sudo systemctl status nginx.service` - `nginx` - dbのサービス名 - `sudo systemctl status mysql.service` - `` - アプリのサービス名 - `sudo systemctl list-units -t service | grep -e go -e isu` を参考に。 - `isupipe-go` - プログラムが置かれてるディレクトリ - `/home/isucon/webapp/go` - バイナリのパス - `/home/isucon/webapp/go/isupipe` - Goのパス - `/home/isucon/local/golang/bin/go` - 環境変数のファイルのパス - `/home/isucon/env.sh` ::: - ikura-hamu がansible(init)の設定を入力し実行 - 実行待ちの間に計測機器にIPアドレス入れる --- - H1rono 暇な時間が出来たら 問題設定/マニュアル/コード を読む :::spoiler **pikachu Git管理を始める** :::success ``` # Go追加 # Sql追加 # マニュアル追加 # Public追加 git add webapp/sql/initdb.d git add webapp/go git add s1/etc/nginx/nginx.conf git add s1/etc/nginx/sites-available/* git add s1/etc/mysql/mysql.conf.d/mysqld.cnf git add s1/env.sh git commit -m ":tada: init s1" git push git fetch git reset --hard 09cd6d0308f5b4bc4f336b78e6cc2fac363e24c8 git add s2/etc/nginx/nginx.conf git add s2/etc/nginx/sites-available/* git add s2/etc/mysql/mysql.conf.d/mysqld.cnf git add s2/env.sh git commit -m "s2" git push git fetch git reset --hard b4a0d15873dc9e72d292a98ee3b7323a6fe12fdf git add s3/etc/nginx/nginx.conf git add s3/etc/nginx/sites-available/* git add s3/etc/mysql/mysql.conf.d/mysqld.cnf git add s3/env.sh git commit -m "s3" git push ``` - (MariaDBなら) `s*/etc/mysql/mariadb.conf.d/50-server.cnf` - `s*/環境変数ファイル` - systemdのファイル類(`s*/etc/systmed/system`)は必要になったとき? ::: - ikura-hamu 今回の問題用の設定を反映したansibleを配る --- - ikura-hamu エンドポイントごとにデーターベースの操作をまとめる :::spoiler **pikachu nginx MySQL ログ出力と秘伝のタレ** :::success MySQL ``` slow_query_log = 1 slow_query_log_file = /var/log/mysql/mysql-slow.log long_query_time = 0 log-queries-not-using-indexes skip-log-bin skip-innodb-doublewrite max_allowed_packet = 200M max_connections = 5000 # ディスクイメージをメモリ上にバッファさせる値をきめる設定値 (別鯖なら搭載メモリの80%くらい) innodb_buffer_pool_size = 3000MB # InnoDBの更新ログを記録するディスク上のファイルサイズ(innodb_buffer_pool_sizeの4分の1程度) innodb_log_file_size = 500MB # innoDBの更新ログを保持するメモリ(default: 8MB)、大量のデータの更新に効く innodb_log_buffer_size = 100MB # 1に設定するとトランザクション単位でログを出力するが 2 を指定すると1秒間に1回ログファイルに出力するようになる innodb_flush_log_at_trx_commit = 0 # データファイル、ログファイルの読み書き方式を指定する (OSによるディスクキャッシュとの2重キャッシュを防ぐ) innodb_flush_method = O_DIRECT # ORDER BYやGROUP BYのときに使われるメモリ量 innodb_sort_buffer_size = 100MB ``` nginx ``` # nginx worker の設定 worker_rlimit_nofile 8192; events { worker_connections 4096; # 128より大きくするなら、 max connection 数を増やす必要あり。さらに大きくするなら worker_rlimit_nofile も大きくする(file descriptor数の制限を緩める) # multi_accept on; # error が出るリスクあり。defaultはoff。 # accept_mutex_delay 100ms; use epoll; # 待受の利用メソッドを指定(基本は自動指定されてるはず) } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; error_log /var/log/nginx/error.log; # 基本設定 sendfile on; tcp_nopush on; tcp_nodelay on; types_hash_max_size 2048; server_tokens off; open_file_cache max=100 inactive=20s; # file descriptor のキャッシュ。入れた方が良い。 # proxy buffer の設定。白金動物園が設定してた。 proxy_buffers 100 32k; proxy_buffer_size 8k; # Keepalive 設定 # ベンチマークとの相性次第ではkeepalive off;にしたほうがいい # keepalive off; keepalive_requests 20000; keepalive_timeout 600s; http2_max_requests 20000; http2_recv_timeout 600s; lingering_close always; lingering_time 600s; lingering_timeout 600s; # Proxy cache 設定。使いどころがあれば。1mでkey8,000個。1gまでcache。 # proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=zone1:1m max_size=1g inactive=1h; # proxy_temp_path /var/cache/nginx/tmp; ```