Kyoto Cabinet(DBM) + Kyoto Tycoon(网络层)
前注:没使用最新版本,因为最新版本似乎存在环境依赖的bug,编译N多错误,很难通过。
mkdir -p /data/software/
cd /data/software/
wget
http://fallabs.com/kyotocabinet/pkg/kyotocabinet-1.2.76.tar.gz
tar xvzf
kyotocabinet-1.2.76.tar.gz
cd kyotocabinet-1.2.76
./configure
make
make install
cd ../
(2)安装kyototycoon
cd /data/software/
wget
http://fallabs.com/kyototycoon/pkg/kyototycoon-0.9.56.tar.gz
tar xvzf
kyototycoon-0.9.56.tar.gz
cd kyototycoon-0.9.56
./configure
make
make install
cd ../
(生成的测试数据key为8位数字,value为3位数字)
kchashtest order -bnum 150000000 -msiz 2g -set
/data/tycoon/casket1.kch  100000000
kchashtest较影响性能的几个参数: 
  -bnum
指定哈希表的桶数量。官方推荐是记录数的两倍或者更高。 
  -msize 指定内存映射区域大小。 
  -dfunit
设定一个值,当碎片数超过这个值系统就进行碎片整理。 
  -dmn   以daemon方式启动。 
  -th num : 指定线程数 
生成测试数据后以ktserver模式启动(ktserver参数意义见文章尾) 
ktserver -host 192.168.2.70 -port
1978 -tout 10 -log /data/tycoon/ca.log -ls -dmn -pid /data/tycoon/ktserver.pid
/data/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=2g#dfunit=8
ktsever较影响性能的几个参数: 
  -bnum 指定哈希表的桶数量。官方推荐是记录数的两倍或者更高。 
  -msize
指定内存映射区域大小。 
  -dfunit 设定一个值,当碎片数超过这个值系统就进行碎片整理。 
  -dmn   以daemon方式启动。
  -th num : 指定线程数 默认是 16
三. 日常维护及使用 
关闭ktserver 
kill -TERM `cat
/data/tycoon/ktserver.pid ` 
Ktserver切割日志 
mv -f
/data/tycoon/ktserver.log /data0/tycoon/ktserver.log.`date '+%Y%M%d%H%M%S'`
kill -HUP `cat /data/tycoon/ktserver.pid` 
应用 
使用http 客户端
由于每个数据库操作都经由http 调用,你可以使用任何http 客户端,诸如curl 命令来操作 
数据库。 
例: 
添加数据
curl "http://192.168.2.70:1978/rpc/set?key=japan&value=tokyo" 
读取数据
curl "http://192.168.2.70:1978/rpc/get?key=japan" 
删除数据 
curl
"http://192.168.2.70:1978/rpc/remove?key=japan" 
除了上述RPC风格外还支持RESTfull风格
例: 
添加数据 
echo -n tokyo | curl -X PUT -T -
"http://192.168.2.70:1978/japan" 
读取数据 
curl
"http://192.168.2.70:1978/japan" 
tokyo 
删除数据 
curl -X DELETE
"http://192.168.2.70:1978/japan"
四. 主从模式的配置及功能性测试 
注意事项
1.主库必须记录更新日志。 
2.主库必须指定唯一的id 号。 
-sid num : 指定服务器server id
号(当使用主辅模式时,每台ktserver 需要不同 
的ID 号) 
3.从库也必须记录更新日志,当主库宕机时,从库就变成主库。
4.从库必须指定唯一的server id 号 
5.从库必须指定主库的端口号和地址。 
6.从库必须指定复制时间戳文件。
下面的一个主从实例,主库端口192.168.2.70:1978,从库端口192.168.2.80:1978 
首先创建一个主库实例
ktserver -dmn -host 192.168.2.70 -port 1978 -ulog
/data/tycoon/0001-ulog -sid 1  -rts /data/tycoon/001.rts
/data/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=2g#dfunit=8 
(ulog
和数据库文件casket1.kch 都需要指定目录,否则将在当前目录生成,目录需要事先创建好。)
再创建一个从库实例 
ktserver
-dmn -host 192.168.2.80 -port 1978 -ulog /data/tycoon/0001-ulog -sid 2 -mhost
192.168.2.70 -mport 1978 -rts /data/tycoon/001.rts
/data/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=1g#dfunit=8
测试
向主库中添加数据 
curl
"http://192.168.2.70:1978/rpc/set?key=japan&value=tokyo" 
读取主库 
curl
"http://192.168.2.70:1978/japan" 
Tokyo 
读取从库 
curl
"http://192.168.2.80:1978/japan" 
tokyo 
删除主库数据 
curl -X DELETE
"http://192.168.2.70:1978/japan" 
再次读取从库 
curl
"http://192.168.2.80:1978/japan" 
没有数据了。成功。
五. 双主模式的配置 
Kyoto
Tycoon 支持双主模式以提高高可用。 
例:创建两个主库实例,分别叫A 和B。 
首先创建A 
ktserver -dmn -host
192.168.2.70 -port 1978 -ulog /data/tycoon/0001-ulog -sid 1  -mhost
192.168.2.80 -mport 1978 -rts /data/tycoon/001.rts 
/data/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=11g#dfunit=8
然后创建B
ktserver -dmn -host 192.168.2.80 -port 1978 -ulog /data/tycoon/0001-ulog
-sid 2  -mhost 192.168.2.70 -mport 1978 -rts /data/tycoon/001.rts 
/data/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=11g#dfunit=8
添加数据 
向A 中添加数据 
curl
"http://192.168.2.70:1978/rpc/set?key=one&value=first" 
curl
"http://192.168.2.70:1978/rpc/set?key=two&value=second" 
向B 中添加数据
curl "http://192.168.2.80:1978/rpc/set?key=three&value=third" 
curl
"http://192.168.2.80:1978/rpc/set?key=four&value=fourth"
添加数据也可以使用ktremotemgr 实用程序 
ktremotemgr set -host 192.168.2.70 -port 1978
one first 
ktremotemgr set -host 192.168.2.70 -port 1978 two second
ktremotemgr set -host 192.168.2.80 -port 1978 three third 
ktremotemgr
set -host 192.168.2.80 -port 1978 four fourth 
查看数据 
$ ktremotemgr list
-host 192.168.2.70 -port 1978 -pv 
one first 
two second 
three third
four fourth 
$ ktremotemgr list -host 192.168.2.80 -port 1978 -pv 
one
first 
two second 
three third 
four fourth
六.并发访问测试和远程访问速度测试 
1.并发访问测试。
并发测试工具使用webbench,最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便。具体安装参见:
测试流程:
如下,由于一个节点模拟三万并发会造成客户端僵死,所以先使用一台客户端模拟1万个并发去测试一个kt节点,发现kt节点无任何错误和异常。
[root@xoyo-test-43]#webbench -c 10000 -t 10
http://192.168.2.70:1978/rpc/get?key=00000001
Webbench - Simple Web
Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://192.168.2.70:1978/rpc/get?key=00000001
10000 clients, running 10 sec.
Speed=1117350 pages/min, 3538104
bytes/sec. 
Requests: 186225 susceed, 0 failed.
然后使用四台客户端每台模拟一万个并发去测试一个kt节点,发现kt节点扔无错误,但kt节点进程占用资源开始飙高。
得出结论,一个kt节点可应对四万以上并发连接。
2.网络远程访问速度测试
使用kt自带的ktremotetest进程远程读写测试: 
[root@xoyo-45 tycoon]# ktremotetest  bulk  
-set -host 192.168.2.70 -port 1978 100000 
opening the database: 
time:
0.000 
memory: 208896 
time: 19.875 
closing the database: 
time:
0.000 
ok 
[root@xoyo-45 tycoon]# ktremotetest  bulk   -get -host
192.168.2.70 -port 1978 100000 
opening the database: 
time: 0.000
memory: 208896 
time: 17.707 
closing the database: 
time: 0.000
ok 
经多次测试,得出结论,同局域网断其他主机访问kt节点读写都为每秒5000条记录左右。本机访问,每秒为1万条左右。
附录一kstserver启动参数 
-host name : 指定需要绑定的服务器域名或IP 地址。默认绑定这台服务器上的所有IP
地址。 
-port num : 指定需要绑定的端口号。默认端口号为1978 
-tout num :
指定每个会话的超时时间(单位为秒)。默认永不超时。 
-th num : 指定线程数。默认为8 个线程。 
-log file:
输出日志信息到指定文件(这里指定文件名)。 
-li : 日志记录级别---notice。 
-ls : 日志记录级别---system。
-le : 日志记录级别---error。 
-lz : 不记录日志. 
-ulog dir :
指定同步日志文件存放路径(这里指定目录名)。 
-ulim num : 指定每个同步日志文件的大小(例如128m)。 
-uasi num :
指定数据同步到磁盘的时间间隔,该选项默认是关闭的。 
-sid num : 指定服务器ID 号(当使用主辅模式时,每台ktserver 需要不同的ID
号) 
-ord : opens the database as a reader. 
-oat : opens the database with
the auto transaction option. 
-oas : opens the database with the auto
synchronization option. 
-onl : opens the database with the no locking
option. 
-otl : opens the database with the try locking option. 
-onr :
opens the database with the no auto repair option. 
-asi num : 指定自动同步间隔,默认关闭。
-ash : 当自动同步的时候也同步到物理磁盘上 
-bgs dir : specifies the path of the background
snapshot directory. By default, it is disabled. 
-bgsi num : specifies the
interval of background snapshotting. By default, it is 180. 
-bgsc str :
指定快照的压缩格式。支持的格式有"zlib","lzo",lzma" 
-dmn : 以守护进程方式运行。 
-pid file: 输出进程ID
到指定文件(这里指定文件名)。 
-cmd dir : 指定外部指令的搜寻路径,默认是当前路径。 
-scr file : 指定脚本文件
-mhost str: 指定主辅同步模式下,主服务器的域名或IP 地址。 
-mport num : 指定主辅同步模式下,主服务器的端口号。
-rts file: 指定用来存放同步时间戳的文件名。 
-riv num : 指定每次同步操作的毫秒时间间隔,默认是0.04 毫秒。
-plsv file : specifies the shared library file of a pluggable server.
-plex str : specifies the configuration expression of a pluggable server.
-pldb file : 指定插件库的动态链接库文件。
附录二常用ktremotemgr参数
1.打印当前数据库状态信息 
ktremotemgr report [-host str] [-port num] [-tout num]
2.插入数据 
ktremotemgr set [-host str] [-port num] [-tout num] [-db str]
[-add|-rep|-app|-inci|-incd] [-sx] 
[-xt num] key value 
3.删除数据
ktremotemgr remove [-host str] [-port num] [-tout num] [-db str] [-sx] key
4.查询数据 
ktremotemgr get [-host str] [-port num] [-tout num] [-db str]
[-sx] [-px] [-pt] [-pz] key 
5.列出所有key 
ktremotemgr list [-host str]
[-port num] [-tout num] [-db str] [-des] [-max num] [-sx] [-pv] 
[-px] [-pt]
[key] 
6.根据key 删除多条记录 
ktremotemgr removebulk [-host str] [-port num]
[-tout num] [-bin] [-db str] [-sx] key1 key2 
key3 ... 
7.根据key 取出多条记录
ktremotemgr getbulk [-host str] [-port num] [-tout num] [-bin] [-db str]
[-sx] [-px] key1 key2 
key3 ... 
8.批量添加key、value 
ktremotemgr setbulk
[-host str] [-port num] [-tout num] [-bin] [-db str] [-sx] [-xt num] key
value ... 
9.模拟一个客户端复制并打印更新记录 
ktremotemgr slave [-host str] [-port
num] [-tout num] [-ts num] [-sid num] [-ux] [-uw] [-uf] 
[-ur]
10.删除数据库中的所有记录 
ktremotemgr clear [-host str] [-port num] [-tout num]
[-db str] 
11.设定复制配置 
ktremotemgr tunerepl [-host str] [-port num] [-tout
num] [-mport str] [-ts num] [-iv num] 
[mhost] 
选项说明 
-host str:
指定主机名或IP 
-port num: 指定端口号 
-tout num: 指定超时时间. 
-bin: 使用二进制协议.
-mport num: 指定主库端口号. 
-ts num: 指定已经读取日志的最大时间戳。“now”意为当前时间戳。 
-iv num:
指定每次同步操作的毫秒时间间隔。 
-db str: 指定数据库名称 
-st: 打印详细信息。 
-hard: 启动设备的物理同步
-cmd str: specifies an outer command for postprocessing. 
-add: 运行添加操作
-app: 追加操作 
-rep: 替代操作 
-inci: 使整数自增 
-incd: 使实数自增 
-sx:
将输入数据转换成16进制字符串 
-xt num: 指定截止时间 
-px: 将输出数据转换成16进制字符串 
-pt: 打印截止时间
-pz: does not append line feed at the end of the output. 
-des: visits
records in descending order. 
-max num: specifies the maximum number of shown
records. 
-pv: 打印value 值. 
-step num: 指定步骤的数字. 
-sid num: 指定server ID .
-ux: fetches update logs of the specified server ID number only. 
-uw:
等待更新. 
-uf: 打印每次更新日志的状态. 
-ur:移除老的更新日志文件.
附录三安装遇到的错误及使用中可能遇到的问题
1.kc和kt都不使用最新版本,因为最新版本似乎存在环境依赖的bug,编译N多错误,很难通过。 
2.安装中可能遇到以下错误
[root@xoyo-test-43 kyototycoon-0.9.35]# ./configure 
checking Kyoto
Cabinet by pkg-config... no 
configure: error: required version of Kyoto
Cabinet was not detected 
原因:版本不匹配 
我测试匹配的版本如下
kyotocabinet-1.2.43.tar.gz 
kyototycoon-0.9.33.tar.gz
注意事项:如果安装kyotocabinet 使用--prefix 参数指定安装目录了,再安装kyototycoon 时
就需要加参数--with-kc 
例如: 
[root@test kyototycoon-0.9.33]# ./configure
--with-kc=/usr/local/webserver/kyotocabinet/
3.生成数据时,是一个非常耗费内存的过程,如果灌入上亿条记录,需要12G内存以上为好,不然会非常慢,甚至可能需要耗费几天的时间。而且,按目前的观察,即使现在某一台生成kch数据,再拷贝到其他节点,再启动kt进程的时候似乎还要重新加载一次数据,这个过程也是非常慢的。  
Kyoto Cabinet(DBM) + Kyoto Tycoon(网络层)的更多相关文章
- Kyoto Cabinet 使用及原理
		Kyoto Cabinet 基本规格书 如果你知道 Tokyo Cabinet ,那么就应该知道 Kyoto Cabinet,因为他们都是同一个作者(平林幹雄)开发出来的 Key-Value 数据库. ... 
- 实现键值对存储(三):Kyoto Cabinet 和LevelDB的架构比較分析
		译自 Emmanuel Goossaert (CodeCapsule.com) 在本文中,我将会逐组件地把Kyoto Cabinet 和 LevelDB的架构过一遍.目标和本系列第二部分讲的差点儿相 ... 
- GO语言的开源库
		Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org ... 
- Go语言(golang)开源项目大全
		转http://www.open-open.com/lib/view/open1396063913278.html内容目录Astronomy构建工具缓存云计算命令行选项解析器命令行工具压缩配置文件解析 ... 
- [转]Go语言(golang)开源项目大全
		内容目录 Astronomy 构建工具 缓存 云计算 命令行选项解析器 命令行工具 压缩 配置文件解析器 控制台用户界面 加密 数据处理 数据结构 数据库和存储 开发工具 分布式/网格计算 文档 编辑 ... 
- go语言项目汇总
		Horst Rutter edited this page 7 days ago · 529 revisions Indexes and search engines These sites prov ... 
- Golang优秀开源项目汇总,  10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目
		Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ... 
- Kyoto Cabinet--nosql型单机数据库
		摘要: Kyoto Cabinet是轻量级nosql型本地内存数据库 简介 Kyoto Cabinet是一个数据库管理的 lib,是 Tokyo Cabinet 的改进版本.数据库是一个简单的包含记录 ... 
- NoSQL数据库笔谈(转)
		NoSQL数据库笔谈 databases , appdir , node , paper颜开 , v0.2 , 2010.2 序 思想篇 CAP 最终一致性 变体 BASE 其他 I/O的五分钟法则 ... 
随机推荐
- lintcode:将二叉查找树转换成双链表
			题目 将一个二叉查找树按照中序遍历转换成双向链表 给定一个二叉查找树: 4 / \ 2 5 / \ 1 3 返回 1<->2<->3<->4<->5. ... 
- servlet学习笔记一
			Servlet一.基本概念 我们的程序根据是否需要访问网络,可分为网络程序和非网络程序.而 网络程序又分为B/S结构和C/S结构. 什么是C/S?即客户端(Client)/服务器(Server)模式. ... 
- Ubuntu对FireFox安装flash插件
			有时候我们需要在Ubuntu下采用手动安装一些软件,比如Firefox的Flash插件.Adobe® Flash® Player 是一款轻量级浏览器插件,具有丰富的 Internet 应用运行时间,提 ... 
- Asterisk的配置详解
			Asterisk的配置文件都在/etc/asterisk目录下,重要的配置文件有: sip.conf sip电话基本配置 extensions.conf ... 
- hihoCoder  1039字符消除   (字符串处理)
			http://hihocoder.com/problemset/problem/1039 因为字符串只由3种字母组成,并且插入的字符也只能是这三种字符的其中一个,那么可以考虑枚举这三个字符其中一个字符 ... 
- selenium支付高版本的FireFox
			http://blog.csdn.net/pw_windgod/article/details/6537409 15:22:12.031 WARN - GET /selenium-server/dri ... 
- .htaccess的应用
			今天下班后,同事问到这个东西的用法.我以前也没接触过,特地搜索了一下,现在保存方便以后使用. 1.首先判断服务器类型,服务器是否支持. 2.写法是否有错误. 3.需要的功能是否在.htaccess是否 ... 
- Windows,OS X 屏幕录制gif的工具
			gif比png,jpg具有更好的展示效果.github上的很多项目就用gif. 一个比较好的工具是 : http://cockos.com/licecap/ 但是目前不支持linux. 
- Python风格规范
			Python风格规范 分号 Tip 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 Tip 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Py ... 
- VS2008下使用 CMFCPropertyGridCtrl 转载
			http://blog.csdn.net/sunnyloves/article/details/5655575 在DLG中的基本应用 . 首先在Cxxdlg.h文件中加入 public: CMFCPr ... 
