Giter Club home page Giter Club logo

isucon-kit's People

Contributors

shellingford330 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

isucon-kit's Issues

アクセスログ解析

手順

  1. /etc/nginx/nginx.confファイルでlog_formatをalpが解析できるようなformatを指定
http {
    log_format json escape=json '{"time":"$time_local",'
                                '"host":"$remote_addr",'
                                '"forwardedfor":"$http_x_forwarded_for",'
                                '"req":"$request",'
                                '"status":"$status",'
                                '"method":"$request_method",'
                                '"uri":"$request_uri",'
                                '"body_bytes":$body_bytes_sent,'
                                '"referer":"$http_referer",'
                                '"ua":"$http_user_agent",'
                                '"request_time":$request_time,'
                                '"cache":"$upstream_http_x_cache",'
                                '"runtime":"$upstream_http_x_runtime",'
                                '"response_time":"$upstream_response_time",'
                                '"vhost":"$host"}';

    access_log /var/log/nginx/access.log json
}
  1. configが正しいかチェック
$ nginx -t
  1. nginxを再起動
$ nginx -s reload 
// or
$ systemctl reload nginx

プリペアドステートメント

クライアントから、まず変数を埋め込み可能な形のSQLを発行し、データベース側でそれを解析しキャッシュしておく。
そして、クライアントから変数のみを送ってSQLを実行する。同じSQLを何度も発行する場合、実行計画をキャッシュが効率があがり、SQLインジェクションも防ぐ。
しかし、Webアプリケーションでは発行するクエリの種類が多く、キャッシュが効率よく利用されない。

db, err := sql.Open("mysql", "isucon:@tcp(127.0.0.1:3306)/isuconp?interpolateParams=true")

スロークエリログ解析

手順

  1. スロークエリログの設定を追加

/etc/mysql/my.cnfに以下の設定を追加

[mysqld]
slow_query_log=1
slow_query_log_file=/var/log/mysql/mysql-slow.log
long_query_time=0
log_queries_not_using_indexes=1
  1. mysqlを再起動
$ systemctl restart mysql
  1. スロークエリログ解析
$ mysqldumpslow /var/log/mysql/mysql-slow.log

静的ファイル配信

  • ファイルが存在しない場合、サーバーへリバースプロキシする
location /image/ {
  root /home/isucon/private_isu/webapp/public/;
  expires 1d;
  try_files $uri @app;
}

location @app {
  internal;
  proxy_pass http://localhost:8080;
}
  • 静的ファイルを配信
location ~ /(favicon\.ico|css/|js/|img/) {
    root /home/isucon/private_isu/webapp/public/;
    expires 1d;
}

GAでCI/CDをできるようにする

  • PRを作成、PushしたらDeployが走るようにする
    • rsyncでファイルを同期
  • mainの最新をrebaseしていない場合、CIが落ちるようにする

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.