# ISUCON9 Practice ## インスタンス情報 - AWS EC2 t3.xlarge 4 vCPUs, mem 16 GB 2台 - 1台目(こっちで作業):18.183.95.23 - 2台目:18.183.43.224 - Open ports: 80, 8000, 22, 5555, 19999, 7000, 443, 5001 ## 初期化 ```bash $ sudo apt -y update $ sudo apt -y upgrade $ wget https://golang.org/dl/go1.15.linux-amd64.tar.gz $ sudo tar -xvf go1.15.linux-amd64.tar.gz $ sudo mv go /usr/local $ vim .profile export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$GOPATH/bin:$GOROOT/bin:$PATH $ source ~/.profile $ go get -d github.com/isucon/isucon9-qualify $ cd $GOPATH/src/github.com/isucon/isucon9-qualify $ cd initial-data # Install make $ sudo apt install make # Install docker $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io # Enable docker to run without sudo $ sudo groupadd docker $ sudo usermod -aG docker $USER $ newgrp docker $ make # 画像データの展開 $ cd $GOPATH/src/github.com/isucon/isucon9-qualify/webapp/public $ wget https://github.com/isucon/isucon9-qualify/releases/download/v2/initial.zip $ sudo apt install unzip $ unzip initial.zip $ rm -rf upload $ mv v3_initial_data upload $ cd initial-data $ wget https://github.com/isucon/isucon9-qualify/releases/download/v2/bench1.zip unzip bench1.zip $ mv v3_bench1 images # Database Initialization $ cd webapp/sql $ sudo apt install mysql-client-core-5.7 $ sudo apt install mysql-server $ sudo mysql > SELECT user,authentication_string,plugin,host FROM mysql.user; > CREATE USER 'ubuntu'@'localhost' IDENTIFIED BY ''; > GRANT ALL PRIVILEGES ON *.* TO 'ubuntu'@'localhost' WITH GRANT OPTION; $ cat 00_create_database.sql | mysql # Goアプリを起動 $ cd webapp/go $ GO111MODULE=on go run api.go main.go # 外部サービスの起動 $ cd $GOPATH/src/github.com/isucon/isucon9-qualify $ make ``` ## Netdata導入 ```bash # Install bash <(curl -Ss https://my-netdata.io/kickstart.sh) netdata by default listens on all IPs on port 19999, so you can access it with: http://this.machine.ip:19999/ -> http://18.183.95.23:19999/ To stop netdata run: systemctl stop netdata To start netdata run: systemctl start netdata # Listenしてるポートを確認 sudo lsof -i tcp:19999 ``` ## Commands ``` alp $ alp -r --sort=max --file=/var/log/nginx/access.log ltsv | head -20 pt-query-digest $ sudo pt-query-digest --order-by Query_time:sum /tmp/mysql-slow.sql | less ``` ## New Relic 導入 ### Dashboard [New Relic APM Dashboard](https://one.newrelic.com/launcher/nr1-core.explorer?pane=eyJuZXJkbGV0SWQiOiJhcG0tbmVyZGxldHMub3ZlcnZpZXciLCJlbnRpdHlJZCI6Ik1qZzFNekF3TUh4QlVFMThRVkJRVEVsRFFWUkpUMDU4T0RZNE9UTTNNRFl3In0=&sidebars[0]=eyJuZXJkbGV0SWQiOiJucjEtY29yZS5hY3Rpb25zIiwiZW50aXR5SWQiOiJNamcxTXpBd01IeEJVRTE4UVZCUVRFbERRVlJKVDA1OE9EWTRPVE0zTURZdyIsInNlbGVjdGVkTmVyZGxldCI6eyJuZXJkbGV0SWQiOiJhcG0tbmVyZGxldHMub3ZlcnZpZXcifX0=&platform[timeRange][duration]=1800000&platform[$isFallbackTimeRange]=true) (ログイン必要) ### Screenshots 概要 ![](https://i.imgur.com/kWjc7Wu.png) 時間のかかるURI ![](https://i.imgur.com/lfv5eRI.png) 重たいMySQL処理 ![](https://i.imgur.com/FXXKtfH.png) 重たい外部API ![](https://i.imgur.com/lrS5Yek.png) ### 手順 1. User追加設定(3人まで設定可能) 2. Timezone設定(Asia/Tokyo) 3. nodejsだとnpmパッケージとして入れられる ``` $ cd ~/isucon/nodejs $ npm install newrelic --save ``` 4. newrelic.js (configファイル)を`~/isucon/nodejs`下に追加 5. 環境変数としてlicense keyを追加 ``` $ export NEW_RELIC_LICENSE_KEY=************** ``` - https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-nodejs-agent - https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration# - https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent - https://newrelic.co.jp/resources/webinars/get_ready_for_isucon10-ty