Kyoto Cabinet(DBM) + Kyoto Tycoon(网络层)

一. 安装


前注:没使用最新版本,因为最新版本似乎存在环境依赖的bug,编译N多错误,很难通过。

(1)安装kyotocabinet

mkdir -p /data0/software/
cd /data0/software/
wget
http://fallabs.com/kyotocabinet/pkg/kyotocabinet-1.2.43.tar.gz
tar xvzf
kyotocabinet-1.2.43.tar.gz
cd kyotocabinet-1.2.43
./configure
--prefix=/usr/local/webserver/kyotocabinet
make
make install
cd ../

(2)安装kyototycoon
cd /data0/software/
wget
http://fallabs.com/kyototycoon/pkg/kyototycoon-0.9.33.tar.gz
tar xvzf
kyototycoon-0.9.33.tar.gz
cd kyototycoon-0.9.33
./configure
--prefix=/usr/local/webserver/kyototycoon

--with-kc=/usr/local/webserver/kyotocabinet/
make
make install

cd ../

二.使用kchashtest生成一亿条测试数据
(生成的测试数据key为8位数字,value为3位数字)


kchashtest order   -bnum 150000000 -msiz 2g -set
/data0/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 /data0/tycoon/ca.log -ls -dmn -pid
/data0/tycoon/ktserver.pid
/data0/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=2g#dfunit=8


ktsever较影响性能的几个参数:
  -bnum 指定哈希表的桶数量。官方推荐是记录数的两倍或者更高。

  -msize 指定内存映射区域大小。
  -dfunit 设定一个值,当碎片数超过这个值系统就进行碎片整理。

  -dmn   以daemon方式启动。
  -th num : 指定线程数


三. 日常维护及使用
关闭ktserver
kill -TERM `cat
/data0/tycoon/ktserver.pid `
Ktserver切割日志
mv -f
/data0/tycoon/ktserver.log /data0/tycoon/ktserver.log.`date ‘+%Y%M%d%H%M%S‘`

kill -HUP `cat /data0/tycoon/ktserver.pid`
应用
使用http 客户端

由于每个数据库操作都经由http 调用,你可以使用任何http 客户端,诸如curl 命令来操作
数据库。
例:
添加数据

curl "http://192.168.8.46:1978/rpc/set?key=japan&value=tokyo"
读取数据

curl "http://192.168.8.46:1978/rpc/get?key=japan"
删除数据
curl
"http://192.168.8.46:1978/rpc/remove?key=japan"
除了上述RPC风格外还支持RESTfull风格

例:
添加数据
echo -n tokyo | curl -X PUT -T -
"http://192.168.8.46:1978/japan"
读取数据
curl
"http://192.168.8.46:1978/japan"
tokyo
删除数据
curl -X DELETE
"http://192.168.8.46: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
/data0/tycoon/0001-ulog -sid 1  -rts /data0/tycoon/001.rts
/data0/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=2g#dfunit=8
(ulog
和数据库文件casket1.kch 都需要指定目录,否则将在当前目录生成,目录需要事先创建好。)

再创建一个从库实例
ktserver
-dmn -host 192.1682.80 -port 1978 -ulog /data0/tycoon/0001-ulog -sid 2 -mhost
192.168.2.70 -mport 1978 -rts /data0/tycoon/001.rts

/data0/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 /data0/tycoon/0001-ulog -sid 1  -mhost
192.168.2.80 -mport 1978 -rts /data0/tycoon/001.rts 
/data0/tycoon/casket1.kch#opts=1#bnum=150000000#msiz=11g#dfunit=8

然后创建B

ktserver -dmn -host 192.168.2.80 -port 1978 -ulog /data0/tycoon/0001-ulog
-sid 2  -mhost 192.168.2.70 -mport 1978 -rts /data0/tycoon/001.rts 
/data0/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压力测试工具好,安装使用也特别方便。具体安装参见:


http://blog.s135.com/post/288/
测试流程:

如下,由于一个节点模拟三万并发会造成客户端僵死,所以先使用一台客户端模拟1万个并发去测试一个kt节点,发现kt节点无任何错误和异常。

[[email protected]]#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进程远程读写测试:
[[email protected] 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
[[email protected] 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.安装中可能遇到以下错误

[[email protected] 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
例如:
[[email protected] kyototycoon-0.9.33]# ./configure
--with-kc=/usr/local/webserver/kyotocabinet/

3.生成数据时,是一个非常耗费内存的过程,如果灌入上亿条记录,需要12G内存以上为好,不然会非常慢,甚至可能需要耗费几天的时间。而且,按目前的观察,即使现在某一台生成kch数据,再拷贝到其他节点,再启动kt进程的时候似乎还要重新加载一次数据,这个过程也是非常慢的。
 

Kyoto Cabinet(DBM) + Kyoto Tycoon(网络层)

时间: 2024-08-27 07:51:51

Kyoto Cabinet(DBM) + Kyoto Tycoon(网络层)的相关文章

实现键值对存储(三):Kyoto Cabinet 和LevelDB的架构比较分析

译自  Emmanuel Goossaert (CodeCapsule.com) 在本文中,我将会逐组件地把Kyoto Cabinet 和 LevelDB的架构过一遍.目标和本系列第二部分讲的差不多,通过分析现有键值对存储的架构来思考我应该如何建立我自己键值对存储的架构.本文将包括: 1. 本架构分析的意图和方法 2. 键值对存储组件概览 3. Kyoto Cabinet 和LevelDB在结构和概念上的分析 3.1 用Doxygen建立代码地图 3.2 整体架构 3.3 接口 3.4 参数化

Tokyo Cabinet 和Tokyo Tyrant简介

Tokyo Cabinet 和Tokyo Tyrant简介 今天要介绍的NoSQL产品是Tokyo Cabinet和Tokyo Tyrant,Tokyo Cabinet是一个性能优秀的数据存储引擎,而Tokyo Tyrant则提供了访问Tokyo Cabinet数据的网络接口.这是一个很成熟的产品,在国内外也有众多的成功案例. Tokyo Cabinet(简称TC)和Tokyo Tyrant(简称TT),顾名思义,是源自日本的开源项目.由FAL Labs维护,主要的开发人员是Mikio Hira

Go语言(golang)开源项目大全

转http://www.open-open.com/lib/view/open1396063913278.html内容目录Astronomy构建工具缓存云计算命令行选项解析器命令行工具压缩配置文件解析器控制台用户界面加密数据处理数据结构数据库和存储开发工具分布式/网格计算文档编辑器Encodings and Character SetsGamesGISGo ImplementationsGraphics and AudioGUIs and Widget ToolkitsHardwareLangu

GO语言的开源库

Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org gowalker gosearch Sourcegraph Contributing To edit this page you must be a contributor to the go-wiki project. To get contributor access, send mail t

[转]Go语言(golang)开源项目大全

内容目录 Astronomy 构建工具 缓存 云计算 命令行选项解析器 命令行工具 压缩 配置文件解析器 控制台用户界面 加密 数据处理 数据结构 数据库和存储 开发工具 分布式/网格计算 文档 编辑器 Encodings and Character Sets Games GIS Go Implementations Graphics and Audio GUIs and Widget Toolkits Hardware Language and Linguistics 日志 机器学习 Math

实现键值对存储(二)——以现有键值对存储为模型

本文是<实现键值对存储>系列译文的第二篇 原文来自Emmanuel Goossaert (CodeCapsule.com) 本文中,开头我会解释使用现有模型而非重头开始此项目的原因.我会阐述一系列选择键值对存储模型的标准.最后我将对一些广为人知的键值对存储项目做一个概述,并用这些标准选择其中一些作为模型.本文将包含: 1. 不重新发明轮子 2. 备选模型和选择标准 3. 选择的键值对存储的概述 4. 参考文献 1. 不重新发明轮子 键值对存储已经被人们唱好至少30年了[1].最著名的一个项目是

Nosql大家族介绍

原文地址:http://nosql-databases.org/ 非关系数据库世界的终极向导 ------------------------------------------------------------------------------------------------------------------ Nosql定义:下一代数据库大多专注于这几点:非关系型.分布式的.开源并且可以横向扩展. 原意图是成为新式的网络级数据库.这场运动开始于2009年早期,并快速成长.通常的特点,

最新数据库排名

前十名里有3个nosql.如果关系型的,还是关注oracle和mysql:如果是想选用nosql的,关注mongodb.redis.cassandra. 对比几个月前,前十名里9个都是关系型的:而且三个nosql基本每个月排名均上升,说明大家对nosql的关注和使用都成上升趋势. http://db-engines.com/en/ranking Rank Last Month DBMS Database Model Score Changes 1.   1. Oracle Relational

Key-Value数据库实现Part 2:使用已有的K-V数据库做模型

这篇文章中,我会解释为什么在项目中使用已有的模型而不是完全从零开始.我会列出一系列选择K-V数据库模型的标准.最后会概述并选择一些广为人知且符合所列标准的K-V数据库.文章将会主要涵盖: 不要重复造轮子 可供参考的模型和选择标准 被选中数据库的概要 1.不要重复造轮子 K-V数据库已经存在至少30多年了[1].其中最有纪念意义的项目是DBM,是于1979年由Kenneth Tompson为Unix version 7编写的最初的数据库管理软件[2].工程师们面对这有关这些数据库的种种情形 和问题