Skip to content

Instantly share code, notes, and snippets.

@sechiro
Last active August 29, 2015 14:05
Show Gist options
  • Save sechiro/a2780bcde57e407143fd to your computer and use it in GitHub Desktop.
Save sechiro/a2780bcde57e407143fd to your computer and use it in GitHub Desktop.
ISUCON3予選復習時の設定。
# ISUCON夏期講習からのコピペ
# 【メモ】この設定で試した場合は、以下のmemo_privateがない方がスコアが上がった。
# "ADD INDEX memo_private(user, is_private, created_at)"
# これを入れるとMySQLのCPUボトルネックとなるので、このIndexはデータ更新コストが大きいと考えらえる。
cat <<EOF | mysql -u isucon isucon
ALTER TABLE memos ADD INDEX (is_private, created_at),
ADD INDEX mypage(user,created_at),
EOF
21a22,23
> import misaka as m
>
25c27
< app.cache = memcache.Client(['localhost:11211'], debug=0)
---
> app.cache = memcache.Client(['localhost:11212'], debug=0)
76,80c78
< temp = tempfile.NamedTemporaryFile()
< temp.write(bytes(md, 'UTF-8'))
< temp.flush()
< html = subprocess.getoutput("../bin/markdown %s" % temp.name)
< temp.close()
---
> html = m.html(md)
105c103
< cur.execute("SELECT * FROM memos WHERE is_private=0 ORDER BY created_at DESC, id DESC LIMIT 100")
---
> cur.execute("SELECT m.id,m.content,u.username,m.created_at FROM memos m JOIN users u ON m.user = u.id WHERE is_private=0 ORDER BY created_at DESC, id DESC LIMIT 100")
107,109d104
< for memo in memos:
< cur.execute('SELECT username FROM users WHERE id=%s', memo["user"])
< memo['username'] = cur.fetchone()['username']
129c124
< cur.execute("SELECT * FROM memos WHERE is_private=0 ORDER BY created_at DESC, id DESC LIMIT 100 OFFSET " + str(page * 100))
---
> cur.execute("SELECT m.id,m.content,u.username,m.created_at FROM memos m JOIN users u ON m.user = u.id WHERE is_private=0 ORDER BY created_at DESC, id DESC LIMIT 100")
134,137d128
< for memo in memos:
< cur.execute('SELECT username FROM users WHERE id=%s', memo["user"])
< memo['username'] = cur.fetchone()['username']
<
227c218
< cur.execute("SELECT * FROM memos WHERE user=%s " + cond + " ORDER BY created_at", memo["user"])
---
> cur.execute("SELECT id FROM memos WHERE user=%s " + cond + " ORDER BY created_at", memo["user"])
bind = 'unix:/tmp/gunicorn_flask.sock'
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=my-key:16m max_size=100m inactive=120m;
proxy_temp_path /var/cache/nginx/tmp;
upstream app_server {
server unix:/tmp/gunicorn_flask.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://app_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /memo {
proxy_pass http://app_server/memo;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache my-key;
proxy_cache_valid 200 302 5;
}
location /recent {
proxy_pass http://app_server/recent;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache my-key;
proxy_cache_valid 200 302 5;
}
location ~ ^/(images|js|css)/ {
rewrite_by_lua 'ngx.sleep(5)';
root /home/isucon/webapp/python/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[isucon@ip-10-0-0-160 python]$ sudo isucon3 test --workload 4
2014/08/31 06:00:14 <<<DEBUG build>>>
2014/08/31 06:00:14 test mode
2014/08/31 06:00:14 run benchmark workload: 4
2014/08/31 06:01:22 done benchmark
Result: SUCCESS
RawScore: 52893.7
Fails: 0
Score: 52893.7
# 内容の変更なし
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[program:isucon_python]
directory=/home/isucon/webapp/python
command=/home/isucon/env.sh gunicorn -c gunicorn_config.py -w 10 app:app
#command=/home/isucon/env.sh gunicorn --bind unix:/tmp/gunicorn_flask.sock -w 10 app:app
user=isucon
stdout_logfile=/tmp/isucon.python.log
stderr_logfile=/tmp/isucon.python.log
autostart=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment