isucon7-qualify

module
v0.0.0-...-d16ab3d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2019 License: MIT

README

isucon7-qualifyやったこと

デフォルトのEditorをVimに変更
sudo update-alternatives --config editor
shからbashに変更
$ echo $SHELL
/bin/sh
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/tmux
/usr/bin/screen
$ sudo chsh -s /bin/bash isucon
$ grep isucon /etc/passwd
isucon:x:1002:1002::/home/isucon:/bin/bash
systemdを確認
ll /etc/systemd/system/
sudo systemctl enable isuda.go isutar.go

サーバー、mysql

  • alpインストール
  • slowquery設定

mysql_config_editor

mysql_config_editor set --login-path=local --host=localhost --user=isucon --password
mysql_config_editor print --all
[local]
user = isucon
password = *****
host = localhost
$ mysql --login-path=local

doc

mysqlの確認

table, index確認

mysql> show tables;
mysql> show index from channel;
mysql> show index from haveread;
mysql> show index from image;
mysql> show index from message;
mysql> show index from user;

index追加

mysqldumpslowsで確認した遅いクエリにindex追加

ALTER TABLE message ADD INDEX idx__channnel_id__id(channel_id, id);
ALTER TABLE image ADD INDEX idx__name(name);
ALTER TABLE haveread ADD INDEX idx__channel_id(channel_id);
ALTER TABLE user ADD INDEX idx__name(name);

score: 19053

DB画像書き出し

nodeでDBからディレクトリに画像を活気出すスクリプトを用意

node output_image.js

nginxで304を返す

server {
        ...
        root /home/isucon/isubata/webapp/public;

        location /favicon.ico {
                add_header Cache-Control "public max-age=86400";
        }
        location /fonts/ {
                add_header Cache-Control "public max-age=86400";
        }
        location /js/ {
                add_header Cache-Control "public max-age=86400";
        }
        location /css/ {
                add_header Cache-Control "public max-age=86400";
        }
        location /icons {
                add_header Cache-Control "public max-age=86400";
        }

        location / {
                proxy_set_header Host $http_host;
                proxy_pass http://127.0.0.1:5000;
        }

}

余分なカラム取得をしない

- SELECT *
+ SELECT message_id

N+1解消

Redisを導入しカウントを保存する

nodeではioredisを利用

messageのcountをredisに保存

200822

ioredis利用 スコア倍増20000

redisでCOUNT(*)を保持

haveread, messageのCOUNT(*)をmysqlからredisに保存

score: 10000 -> 9000 なぜか下がった mysqlでサマリーテーブルでも良い?

redisをunixsocketへ

cp /etc/redis/redis.conf /etc/redis/redis.conf.org
vim /etc/redis/redis.conf
cp /etc/redis/redis.conf /home/isucon/isubata/webapp/
# reload.shにredisを追加
./reload.sh

socketファイルにアクセスできずエラー

socketのパーミッションを777に変更

[ioredis] Unhandled error event: Error: connect EACCES /var/run/redis/redis.sock

score: 208910

TODO

  • redisをinix socketに変更
  • tmuxまとめる
  • mysql, nginxをどうgit管理するか
  • どうやって302確認する
  • 帯域が足りないのはどうやって気づく
  • 3台構成を試す
  • innodbのチューニング
  • fetchのレスポンスタイムを調整

予選通過の実装を見て

tearm score
588,107 †空中庭園†《ガーデンプレイス》
522,461 スギャブロエックス
481,024 fujiwara組
383,085 予算ZERO
368,444 MSA
314,995 白金動物園
268,588 チーム新卒
266,585 takedashi
262,143 円山町
256,120 都営三田線東急目黒線直通急行日吉行[学生]
228,772 negainoido
221,823 ソン・モテメン・マサヨシ

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL