yuuki / isucon5-qualifier

はむちゃん
1 stars 0 forks source link

去年の準備メモ #5

Open yuuki opened 9 years ago

yuuki commented 9 years ago

去年の予選/本戦はこんな目もを準備してたっぽい。 https://github.com/motemen/isucon-qualifier-2014/issues

最初やること

http://qiita.com/methane/items/2026dce76d7de40d6ad8

/etc/init.d/iptables stop
chkconfig iptables off

too many openfiles http://d.hatena.ne.jp/akishin999/20130213/1360711554

https://github.com/kazeburo/isucon_summer_class_2014

sudo adduser isucon
echo "isuconr       ALL=(ALL)       NOPASSWD: ALL" | sudo tee /etc/sudoers.d/isucon
sudo su - isucon
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
enabled=1
failovermethod=priority
gpgcheck=1
gpgkey=http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
sslverify=1
yum install -y \
  vim screen tmux rsync \
  pcre-devel perf strace make gcc openssl-devel strace kernel-devel kernel-headers \
  apr-util bzip2-devel bzip2 ctags diffutils dstat pigz libxml2-devel supervisor \
  gcc gdb git httpd-tools man-pages patch pcre-devel \
  sqlite-devel zlib-devel percona-toolkit pidstat perf
yum install -y http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-client-5.5.39-2.linux2.6.x86_64.rpm \
 http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-devel-5.5.39-2.linux2.6.x86_64.rpm \
 http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-server-5.5.39-2.linux2.6.x86_64.rpm \
 http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-shared-5.5.39-2.linux2.6.x86_64.rpm \
 http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-shared-compat-5.5.39-2.linux2.6.x86_64.rpm
sudo easy_install http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0a12.tar.gz
sudo mkdir /var/log/supervisor
sudo /sbin/chkconfig memcached on
sudo /sbin/chkconfig mysql on
sudo /sbin/chkconfig httpd on
cat <'EOF' >> ~/.bashrc
export PATH=/home/isucon/local/perl-5.20/bin:$PATH
export PATH=/home/isucon/local/go/bin:$PATH
export GOPATH=/home/isucon/local/go/bin
export GOROOT=/home/isucon/local/go
EOF

innotop

 yum -y install perl-TermReadKey perl-DBI perl-DBD-mysql perl-ExtUtils-MakeMaker perl-Time-HiRes
# wget http://innotop.googlecode.com/files/innotop-1.8.0.tar.gz
# tar xvzf innotop-1.8.0.tar.gz
# cd innotop-1.8.0
# perl Makefile.PL

innotop -w -h db001 -u user -p passwd innotop -w -h db001 -u user -p passwd -d 0.001 --count 500 -n | tee ./query.log

sudo yum --enablerepo=epel install redis

設定

$ cat /etc/sysctl.conf
net.ipv4.tcp_max_tw_buckets = 2000000
net.ipv4.ip_local_port_range = 10000 65000
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 10
$ sudo /sbin/sysctl -p

xbuild

git clone https://github.com/tagomoris/xbuild.git
./xbuild/perl-install 5.20.0 ~/local/perl-5.20
export PATH=/home/isucon/local/perl-5.20/bin:$PATH

memcached

sudo yum install -y wget libevent-devel perl-devel
cd /tmp
wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
tar zxf memcached-1.4.21.tar.gz
cd memcached-1.4.21
./configure --prefix=/usr/local/memcached && make && sudo make install
[program:memcahed]
directory=/
command=/usr/local/memcached/bin/memcached -p 11211 -U 0 -u nobody -m 256 -c 200000 -v -t 1 -C -B ascii
autostart = true

redis

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/
daemonize no
pidfile /var/run/redis/redis-server.pid
port 6379
timeout 30
loglevel notice
logfile /var/log/redis/redis.log
databases 8

unixsocket /tmp/redis.sock
unixsocketperm 755
tcp-keepalive 60

save 900 1
save 300 10
save 120 20000

maxclients 10000

appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 100000
slowlog-max-len 1024

http://redis.io/topics/latency

redis-cli --latency -h `host` -p `port`
[program:redis]
directory=/
command=/usr/local/bin/redis-server /etc/redis/redis.conf
autostart = true

nginx

cd /tmp
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
tar zxf pcre-8.36.tar.gz
wget http://openresty.org/download/ngx_openresty-1.7.4.1.tar.gz
tar zxf ngx_openresty-1.7.4.1.tar.gz
cd ngx_openresty-1.7.4.1
export PATH=/sbin:$PATH
./configure --with-luajit --prefix=/usr/local/openresty --with-http_gzip_static_module --with-pcre=/tmp/pcre-8.36 --with-pcre-jit
make
sudo make install
sudo mkdir -p /var/log/nginx
sudo chmod 755 /var/log/nginx
sudo /etc/init.d/httpd stop
sudo /sbin/chkconfig httpd off
[program:nginx]
directory=/
command=/usr/local/openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf
autostart = true
worker_processes  1;

events {
  worker_connections  10000;
}

http {
# access_log by y_uuki
  log_format tsv_isucon4  "time:$time_local"
    "\thost:$remote_addr"
    "\tvhost:$host"
    "\tforwardedfor:$http_x_forwarded_for"
    "\treq:$request"
    "\tstatus:$status"
    "\tsize:$body_bytes_sent"
    "\treferer:$http_referer"
    "\tua:$http_user_agent"
    "\ttaken_sec:$request_time"
    "\tcache:$upstream_http_x_cache"
    "\truntime:$upstream_http_x_runtime"
    "\terrormsg:$upstream_http_x_error_message"
    "\tupstream:$upstream_addr"
    "\tupstream_status:$upstream_status"
    "\tserver:$upstream_http_x_server"
  ;
  access_log /var/log/nginx/isucon4.access_log.tsv tsv_isucon4;

  include     mime.types;
# access_log  off;
  sendfile    on;
  tcp_nopush  on;
  tcp_nodelay on;
  etag        off;
  upstream app {
    server unix:/dev/shm/app.sock;
  }

  server {
    location / {
      proxy_pass http://app;
    }
    location ~ ^/(stylesheets|images)/ {
      open_file_cache max=100;
      root /home/isucon/webapp/public;
    }
  }
}
$ cat /etc/my.cnf
innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 0
innodb_flush_method=O_DIRECT

最後やること