MySQL+HandlerSocket安装
HandlerSocket是啥东东,请参看http://www.ourlinux.net/database/using-mysql-as-a-nosql-a-story-for-exceeding-750000-qps-on-a-commodity-server/,做个简单的摘记:
下载
wget -c http://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/tarball/master
安装Mysql
PREFIX=/opt/app
tar zxvf mysql-5.1.51.tar.gz
cd mysql-5.1.51
./configure –prefix=$PREFIX/mysql-5.1.51 –enable-assembler –with-client-ldflags=-all-static –with-unix-socket-path=/tmp/mysql.sock –with-charset=utf8 –enable-thread-safe-client –with-pthread –without-debug –with-big-tables –enable-community-features –enable-profiling –enable-local-infile –with-fast-mutexes –with-plugins=innobase,innodb_plugin && \
make -j 5 && \
strip sql/mysqld && \
make install && \
cd $PREFIX/mysql-5.1.51 && \
bin/mysql_install_db –user=mysql && \
cd ..
安装HandlerSocket
tar zxvfp ahiguti-HandlerSocket-Plugin-for-MySQL-a25ce9a.tar.gz && \
cd ahiguti-HandlerSocket-Plugin-for-MySQL-a25ce9a && \
./autogen.sh
./configure –prefix=$PREFIX/HandlerSocket-Plugin –with-mysql-source=/home/kingnet/mysql/mysql-5.1.51 –with-mysql-bindir=$PREFIX/mysql-5.1.51/bin –with-mysql-plugindir=$PREFIX/mysql-5.1.51/lib/mysql/plugin && \
make && make install
在mysql里加载HandlerSocket插件:
mysql> INSTALL PLUGIN handlersocket SONAME ‘handlersocket.so’;
mysql>SHOW PLUGINS; # 查看插件是否加载成功
在my.cnf的[mysqld]加如下配置:
loose_handlersocket_port = 9998
# the port number to bind to (for read requests)
loose_handlersocket_port_wr = 9999
# the port number to bind to (for write requests)
loose_handlersocket_threads = 16
# the number of worker threads (for read requests)
loose_handlersocket_threads_wr = 1
# the number of worker threads (for write requests)
open_files_limit = 65535
安装perl模块
cd libhsclient && \
rsync -av ./*.hpp /usr/include/
# 需要将必要的include文件copy到系统目录。
cd ../perl-Net-HandlerSocket/
perl Makefile.PL && \
make && \
make test && \
make install
perl测试脚本
#!/usr/bin/perl
use strict;
use warnings;
use Net::HandlerSocket;
#1. establishing a connection
my $args = { host => ’192.168.4.75′, port => 9998 };
my $hs = new Net::HandlerSocket($args);
#2. initializing an index so that we can use in main logics.
# MySQL tables will be opened here (if not opened)
my $res = $hs->open_index(0, ‘test’, ‘user’, ‘PRIMARY’,
‘user_name,user_email,created’);
die $hs->get_error() if $res != 0;
#3. main logic
#fetching rows by id
#execute_single (index id, cond, cond value, max rows, offset)
$res = $hs->execute_single(0, ‘=’, [ '101' ], 1, 0);
die $hs->get_error() if $res->[0] != 0;
shift(@$res);
for (my $row = 0; $row < 1; ++$row) {
my $user_name= $res->[$row + 0];
my $user_email= $res->[$row + 1];
my $created= $res->[$row + 2];
print “$user_name\t$user_email\t$created\n”;
}
#4. closing the connection
$hs->close();
执行:perl t.pl,返回:
bi_101 bi_101@test.com 2010-10-26 10:11:11