Viila2.0
上线初始访问速度慢道一个不可思议,打开一个期货的详情能拖过拉拉1分钟。在我3天的努力下,终于从 9989ms提升到现在的727ms。和大家分享一下,建议持怀疑态度的同行先进入www.viila.net去验证一下,如果觉得根本不符合你的预期,就别耽误时间了。
查找原因
发现ruby
解析较慢,数据库果询也较慢,所以着手解决:
查资料大家都说REE 解决了
内存泄露的问题,并且运行较稳定.
解决步骤如下:
Ruby-enterprise 1.8.7 安装手记
要安装 ruby enterprice 1.8.7 先安装 tcmalloc
tcmalloc 是google发布在内存的分配上效率和速度要高得多,可以在很大程度上提高服务器在高并发情况下的性能,降低系统负载.
ubuntu 下安装方法:
添加仓库地址到/etc/apt/sources.list
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
保存sources.list
apt-get update
apt-get install libtcmalloc-minimal0
tcmalloc 安装完成.
下载: ruby-enterprise-1.8.7-2010.02.tar.gz
tar xzvf ruby-enterprise-x.x.x.tar.gz
PREFIX=/opt/ruby-enterprise
cd ruby-enterprise-x.x.x/source
patch -p1 -R < ../fast-
threading.patch
cd ../..
cd ruby-enterprise-x.x.x/source/distro/google-perftools-*
./configure --prefix=$PREFIX --disable-dependency-tracking
make libtcmalloc_minimal.la
sudo mkdir -p $PREFIX/lib
sudo rm -f $PREFIX/lib/libtcmalloc_minimal*.so*
sudo cp -Rpf .libs/libtcmalloc_minimal*.so* $PREFIX/lib/
cd ../..
./configure --prefix=$PREFIX --enable-mbari-api CFLAGS='-g -O2'
打开 Makefile
找到
LIBS =
LIBS = $(PRELIBS) -ldl -lcrypt -lm $(EXTLIBS)
make PRELIBS="-Wl,-rpath,$PREFIX/lib -L$PREFIX/lib -ltcmalloc_minimal"
sudo make install
./ruby-enterprise-X.X.X/
installer -c --enable-shared
./ruby-enterprise-X.X.X/installer -c --enable-pthread
PATH="/opt/ruby-enterprise-x.x.x/bin:
GC 调整:
RUBY_HEAP_MIN_SLOTS=500000
RUBY_HEAP_SLOTS_INCREMENT=250000
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
RUBY_GC_MALLOC_LIMIT=50000000
优化mysql 提高查询能力:
给查询量大的表增加索引并根据系统调整MYSQL的参数如下:
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
net_buffer_length = 8K
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
query_cache_size = 32M
thread_concurrency = 4
thread_cache_size = 1200
max_connections=10000
default-storage-engine=INNODB
log-bin-trust-
function-creators = 1
event_scheduler = ON
query_cache_size = 400M
thread_stack = 128k
tmp_table_size = 256M
max_tmp_tables = 256
binlog_cache_size = 2M
max_binlog_size = 128M
max_binlog_cache_size = 512M
log_queries-not-using-indexes
long_query_time = 1
innodb_buffer_pool_size = 1300M
innodb_log_file_size = 256M
innodb_lock_wait_timeout = 100
innodb_flush_log_at_trx_commit = 2
经过长时间的编译.终于安装完成.
重启系统发现性能有大幅度的上升:
从日志中看访问期货的走势图中的访问时间由原来的:
Completed in 9989ms View: 2381, DB: 7583)
提升到:
Completed in 727ms (View: 374, DB: 132)