ISUCONの勝ち方 YAPC::Asia Tokyo 2015
- 29. 私とISUCON
• 2011年 出題、サーバセットアップ担当
• 2012年 出題、サーバセットアップ担当
事前に出題に挑戦し、ベンチマークの問題を洗い出す
急性胃腸炎になる
• 2013年 初出場 優勝
メンバー: tagomoris sugyan kazeburo
• 2014年 2年連続優勝
メンバー: tagomoris sugyan kazeburo
- 32. パフォーマンスの重要性
• UX
• Jakob Nielsen - Response Times: The 3 Important Limits
“1.0 second is about the limit for the user's flow of
thought to stay uninterrupted”
• KPI
• Google: Using site speed in web search ranking
• Aberdeen Group: study showed that a one second delay
in page load time equals 11% fewer page views, a 16%
decrease in customer satisfaction, and 7% loss in
conversions.
http://www.nngroup.com/articles/response-times-3-important-limits/
http://googlewebmastercentral.blogspot.jp/2010/04/using-site-speed-in-web-search-ranking.html
http://www.aberdeen.com/research/5136/ra-performance-web-application/content.aspx
- 33. パフォーマンスの重要性
• インフラコスト
• 30% 負荷を削減できると
• c4.2xlarge 30台だと
$9843 => $6890
• c4.2xlarge 100台だと
$32,810 => $22,967
• 管理コストや障害対応のコストも減らせる。
大規模なインフラでは嬉しい
- 40. 事前準備
• Private Git Repository
• Wiki
• メンバーのSSH公開
• 秘伝のタレを集める
• Chat room
• 技術選択についての簡単な打ち合わせ
• 過去問を解く
• ISUCON予選突破の は過去問を解くことなので無料で試
せるようにした(Vagrant+Ansible) - Dマイナー志向
http://d.hatena.ne.jp/tmatsuu/20150815/1439643715
- 47. アクセスログ解析
# vim httpd.conf
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%
{User-Agent}i" "%v" "%{cookie}n" %D" combined
$ rm /var/log/httpd/access_log
$ service httpd restart
# ベンチマーク実行
$ cat access_log | analyze_apache_logs
- 50. MySQL SlowLog解析
# mysqlのコンソールにて
> set global slow_query_log = 1;
> set global long_query_time = 0;
> set global slow_query_log_file = "/tmp/slow.log";
# ベンチマーク実行
$ pt-query-digest /tmp/slow.log > /tmp/digest.txt
$ rm /tmp/slow.log
# 戻すときは
$ service mysqld restart
- 52. サーバの負荷をみる
• top - 全体の負荷
• iftop - ネットワーク
• iotop - disk io
• dstat
• などなど。使い慣れた物を使う
- 59. コンテキストスイッチング
CPU CPU CPU CPU
process process process process process process process
process process process process process process process
process process process process process process process
OSによりスケジュール実行
- 60. コンテキストスイッチング
CPU CPU CPU CPU
process process
process
process process process process
process process process process process process process
process process process process process process process
OSによりスケジュール実行
- 61. コンテキストスイッチング
CPU CPU CPU CPU
process process process process process process process
process process process process process
process
process
process process process process process process process
OSによりスケジュール実行
- 67. Apache vs. Nginx
worker worker worker
worker worker worker
worker worker worker
リクエスト
コンテキストスイッチが
大量発生
リクエスト
worker
1個のプロセスで
効率よく通信を処理
- 68. Nginx vs. h2o
リクエスト
process process
process
リクエスト
thread thread
thread
h2oはプロセスではなくスレッド。スレッドの方がコンテキスト
スイッチのコストが低い。スレッド間の情報の共有がしやすい
複数のworkerプロセスを
起動し大量のアクセスを
捌く
- 74. MySQL の B+Tree
SECONDARY KEY
primary keyじゃないkey
リーフノードに
PRIMARYKEYが含まれ、
データはCLUSTEREDINDEX
から取得
id id id id id id id id
is_private
created_at
older newer older newer
- 80. MySQLのOFFSET処理
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
1 2 3 4
5 6 7 8
9 10 11 12
13
10000
10001 10002 10003 10004
- 81. MySQLのOFFSET処理
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
1 2 3 4
5 6 7 8
9 10 11 12
13
10000
10001 10002 10003 10004
頑張ってソート
必要な個数まで到達
- 82. MySQLのOFFSET処理
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
id title user ... . id title user ... . id title user ... . id title user ... .
id title user ... .
1 2 3 4
5 6 7 8
9 10 11 12
13
10000
10001 10002 10003 10004
頑張ってソート
必要な個数まで到達
廃棄