kavo’s diary

備忘録

ISUCON練習 private-isu[3] ~13148点 Nginxログ解析、pprof、無効ユーザの除外とpost20個制限

Nginxログ解析

ログフォーマットを設定。

apt update && apt install -y vim

vi /etc/nginx/nginx.conf

# nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

alpの集約を調整。

../../../alp.exe json --file access.log -r --sort=sum -m "/image/\d+.(jpg|png|gif), @[a-zA-Z]+, /posts/\d+" | head -n 30

GET /、getIndexが支配的。

プロファイラ

GitHub - felixge/fgprof: 🚀 fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together.

を使う。 コード修正

fgprof導入 · shimodatkh/private-isu@93f42fe · GitHub

docker compose up -d --force-recreate app

go tool pprof --http=:6061 http://localhost:6060/debug/fgprof?seconds=120

を仕掛けてベンチ実行。

getIndexに絞るとこうなった。

コード読み解き

まずはgetIndexを読む。処理を箇条書きで書いてみる。

とりあえず無効ユーザは無駄なこと、Postは20個、コメントは3個まででよいことはわかった。

一旦簡単なところから、無効ユーザの除外とpost20個制限をつけてみる。

getIndex 無効ユーザの除外とpost20個制限 · shimodatkh/private-isu@9c47086 · GitHub

docker compose build app docker compose up -d --force-recreate app

{"pass":true,"score":13148,"success":10431,"fail":0,"messages":[]}

real 1m12.421s

GET /のAVGが0.133から0.030と減っている。