Code Monkey home page Code Monkey logo

isucon13's People

Contributors

namachan10777 avatar sankichi92 avatar sksat avatar

Watchers

 avatar  avatar  avatar  avatar

isucon13's Issues

やることリスト

事前準備

競技開始前

競技環境立ち上げ

  • 最初の動画を見る
  • EC2 の立ち上げまでの部分のマニュアルを読む
  • @sankichi92: CloudFormation 流し込み
  • 全員: 全ホストに SSH できるか確認
  • 一発目のベンチを回す

初手

  • @sankichi92: マニュアルを読む
  • @sankichi92: とりあえず動いてる様子を確認して問題の外観を掴む
  • @sksat: 言語切り替えの部分だけマニュアルを読んでとりあえず Rust に切り替えてベンチを回す
  • @sksat: ファイルを回収して commit & push
  • @namachan10777 : 環境構築(setup.sh を殴る)
  • @namachan10777: 現地の構成情報を確認して itamae を足し引きしておく(MySQL か,MaridDB か,SQLite か,nginx の設定など)

1発目デプロイ

最初の最適化

  • alp を眺める
  • @sankichi92: 眺めてインデックスを張る

競技終了直前

  • 計測系を止める
  • ログを止める

スロークエリ

$ sudo mysqldumpslow /tmp/slow.log -s t -t 10

Reading mysql slow query log from /tmp/slow.log
Count: 12119  Time=0.03s (340s)  Lock=0.00s (0s)  Rows=3.6 (43432), isucon[isucon]@localhost
  SELECT * FROM livestream_tags WHERE livestream_id = N

Count: 21301  Time=0.01s (125s)  Lock=0.00s (0s)  Rows=0.7 (15704), isucon[isucon]@localhost
  SELECT image FROM icons WHERE user_id = N

Count: 12269  Time=0.01s (102s)  Lock=0.00s (0s)  Rows=0.2 (2780), isudns[isudns]@localhost
  SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=N and name='S' and domain_id=N

Count: 6726  Time=0.01s (61s)  Lock=0.00s (0s)  Rows=1.0 (6726), isucon[isucon]@localhost
  SELECT IFNULL(SUM(l2.tip), N) FROM users u
  INNER JOIN livestreams l ON l.user_id = u.id
  INNER JOIN livecomments l2 ON l2.livestream_id = l.id
  WHERE u.id = N

Count: 6730  Time=0.01s (58s)  Lock=0.00s (0s)  Rows=1.0 (6730), isucon[isucon]@localhost
  SELECT COUNT(*) FROM users u
  INNER JOIN livestreams l ON l.user_id = u.id
  INNER JOIN reactions r ON r.livestream_id = l.id
  WHERE u.id = N

Count: 9162  Time=0.01s (56s)  Lock=0.00s (0s)  Rows=0.5 (4733), isudns[isudns]@localhost
  SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=N and type='S' and name='S'

Count: 17837  Time=0.00s (38s)  Lock=0.00s (0s)  Rows=1.0 (17837), isucon[isucon]@localhost
  SELECT * FROM themes WHERE user_id = N

Count: 1395  Time=0.03s (35s)  Lock=0.00s (0s)  Rows=1.0 (1395), isucon[isucon]@localhost
  SELECT slot FROM reservation_slots WHERE start_at = N AND end_at = N

Count: 76120  Time=0.00s (32s)  Lock=0.00s (0s)  Rows=0.0 (0), isucon[isucon]@localhost
  DELETE FROM livecomments
  WHERE
  id = N AND
  livestream_id = N AND
  (SELECT COUNT(*)
  FROM
  (SELECT 'S' AS text) AS texts
  INNER JOIN
  (SELECT CONCAT('S', 'S', 'S')	AS pattern) AS patterns
  ON texts.text LIKE patterns.pattern) >= N

Count: 448  Time=0.05s (23s)  Lock=0.00s (0s)  Rows=0.4 (180), isucon[isucon]@localhost
  SELECT id, user_id, livestream_id, word FROM ng_words WHERE user_id = N AND livestream_id = N

GET /api/user/:username/icon で 304 を返せるようにする

正攻法は Nginx から配信するようにするが、DB からデータ剥がすのは大変そう。

DB をそのままにやる場合は以下の手順か。

  1. icons テーブルに icon_hash カラムを追加する
  2. post_icon_handler で sha256 を計算して icon_hash に非同期で保存する(2秒以内)
  3. fill_user_response で事前計算済みの icon_hash を返すようにする
  4. get_icon_handler で If-None-Match ヘッダを見て、存在すれば icons テーブルで icon_hash との一致を確認、一致すれば 304 を返して早期リターン

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.