#tar -zxvf tokyocabinet-1.4.47.tar.gz #cd tokyocabinet-1.4.47 #./configure --prefix=/usr/local/tokyocabinet #make #make install
安装tokyotyrant
#tar -zxvf tokyotyrant-1.4.47.tar.gz #cd tokyotyrant-1.4.47 #./configure --prefix=/usr/local/tokyotyrant #make #make install
启动TT
#mkdir /var/ttserver-1978 #chmod -R 777 /var/ttserver-1978 #vi /usr/local/tokyotyrant/sbin/ttservctl === // 修改部分 basedir="/var/ttserver" -> basedir="/var/ttserver-1978" === #/usr/local/tokyotyrant/sbin/ttservctl start
安装tokyo_tyrant
#tar -zxvf tokyo_tyrant-0.6.0.tgz #cd tokyo_tyrant #/usr/local/php/bin/phpize #./configure --with-php-config=/usr/local/php/bin/php-config --with-tokyo-tyrant=/usr/local/tokyotyrant --with-tokyo-cabinet-dir=/usr/local/tokyocabinet #make #make install
需要配置php
#vi /usr/local/php/etc/php.ini // 添加如下 [totyr_tyrant] extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/tokyo_tyrant.so";
fastcgi方式安装php,重启php
#pkill -o php-fpm #/usr/local/php/sbin/php-fpm
选择数据库类型:TCHDB
配置如下
#vi /usr/local/tokyotyrant/sbin/ttservctl === // 修改部分 dbname="$basedir/casket.tch#bnum=1000000" ---> dbname="$basedir/casket.tch#bnum=20000000#xmsiz=4294967296" === #/usr/local/tokyotyrant/sbin/ttservctl stop #/usr/local/tokyotyrant/sbin/ttservctl start
注释:
bnum:TT算法下放在内存中记录总数
xmsize:分配给TT使用的内存,如果超过该内存,在该数据库类型下的TT性能将急剧下降,单位是B,不是K或者M哦
如果考虑到数据量特别大,可以尝试选择TCBDB,相比TCHDB,速度下降了了很多,同时对内存的需求也下降了很多
配置如下
#vi /usr/local/tokyotyrant/sbin/ttservctl === // 修改部分 dbname="$basedir/casket.tch#bnum=1000000" ---> dbname="$basedir/casket.tch#lmemb=1024#nmemb=2048#bnum=20000000" ===
具体的可以参照附件“dtcc_tc_tt_tcsql.pdf”,张宴写的,如果侵犯了作者的著作权,请第一时间告知,立刻删除
如果全部安装成功,便可以调用php的tt接口
<?php /****http://www.php.net/manual/en/class.tokyotyrant.php**** TokyoTyrant::add — Adds to a numeric key TokyoTyrant::connect — Connect to a database TokyoTyrant::connectUri — Connects to a database TokyoTyrant::__construct — Construct a new TokyoTyrant object TokyoTyrant::copy — Copies the database TokyoTyrant::ext — Execute a remote script TokyoTyrant::fwmKeys — Returns the forward matching keys TokyoTyrant::get — The get purpose TokyoTyrant::getIterator — Get an iterator TokyoTyrant::num — Number of records in the database TokyoTyrant::out — Removes records TokyoTyrant::put — Puts values TokyoTyrant::putCat — Concatenates to a record TokyoTyrant::putKeep — Puts a record TokyoTyrant::putNr — Puts value TokyoTyrant::putShl — Concatenates to a record TokyoTyrant::restore — Restore the database TokyoTyrant::setMaster — Set the replication master TokyoTyrant::size — Returns the size of the value TokyoTyrant::stat — Get statistics TokyoTyrant::sync — Synchronize the database TokyoTyrant::tune — Tunes connection values TokyoTyrant::vanish — Empties the database Examples: $tt = new connect($host, $port); $tt->put($key, $value); $tt->get($key); $tt->out($key); $tt->vanish(); $num = $tt->num(); ***************************************************/
1.主要是修改Linux的TCP连接数,可以是TT高并发的特点发挥出来
#sysctl -w net.ipv4.tcp_tw_reuse=1 #sysctl -w net.ipv4.tcp_tw_recycle=1 #sysctl -w net.ipv4.tcp_fin_timeout=10 #sysctl -w net.core.wmem_max=8388608 #sysctl -w net.core.rmem_max=8388608
注释:不需要重启Linux