[文章作者:张宴 本文版本:v1.4 最后修改:2010.06.11 转载请注明原文链接:http://blog.zyan.cc/read.php/362/]

  Tokyo Cabinet 是日本人 平林幹雄 开发的一款 DBM 数据库,该数据库读写非常快,哈希模式写入100万条数据只需0.643秒,读取100万条数据只需0.773秒,是 Berkeley DB 等 DBM 的几倍。

  点击在新窗口中浏览此图片



  Tokyo Tyrant 是由同一作者开发的 Tokyo Cabinet 数据库网络接口。它拥有Memcached兼容协议,也可以通过HTTP协议进行数据交换。

  Tokyo Tyrant 加上 Tokyo Cabinet,构成了一款支持高并发的分布式持久存储系统,对任何原有Memcached客户端来讲,可以将Tokyo Tyrant看成是一个Memcached,但是,它的数据是可以持久存储的。这一点,跟新浪的Memcachedb性质一样。

  相比Memcachedb而言,Tokyo Tyrant具有以下优势:

  1、故障转移:Tokyo Tyrant支持双机互为主辅模式,主辅库均可读写,而Memcachedb目前支持类似MySQL主辅库同步的方式实现读写分离,支持“主服务器可读写、辅助服务器只读”模式。

  点击在新窗口中浏览此图片

  这里使用 $memcache->addServer 而不是 $memcache->connect 去连接 Tokyo Tyrant 服务器,是因为当 Memcache 客户端使用 addServer 服务器池时,是根据“crc32(key) % current_server_num”哈希算法将 key 哈希到不同的服务器的,PHP、C 和 python 的客户端都是如此的算法。Memcache 客户端的 addserver 具有故障转移机制,当 addserver 了2台 Memcached 服务器,而其中1台宕机了,那么 current_server_num 会由原先的2变成1。

  引用 memcached 官方网站和 PHP 手册中的两段话:
引用
http://www.danga.com/memcached/
If a host goes down, the API re-maps that dead host's requests onto the servers that are available.

http://cn.php.net/manual/zh/function.Memcache-addServer.php
Failover may occur at any stage in any of the methods, as long as other servers are available the request the user won't notice. Any kind of socket or Memcached server level errors (except out-of-memory) may trigger the failover. Normal client errors such as adding an existing key will not trigger a failover.




  2、日志文件体积小:Tokyo Tyrant用于主辅同步的日志文件比较小,大约是数据库文件的1.3倍,而Memcachedb的同步日志文件非常大,如果不定期清理,很容易将磁盘写满。



  3、超大数据量下表现出色:

  点击在新窗口中浏览此图片

  但是,Tokyo Tyrant 也有缺点:在32位操作系统下,作为 Tokyo Tyrant 后端存储的 Tokyo Cabinet 数据库单个文件不能超过2G,而64位操作系统则不受这一限制。所以,如果使用 Tokyo Tyrant,推荐在64位CPU、操作系统上安装运行。



  一、安装
  1、首先编译安装tokyocabinet数据库
wget http://www.1978th.net/tokyocabinet/tokyocabinet-1.4.45.tar.gz
tar zxvf tokyocabinet-1.4.45.tar.gz
cd tokyocabinet-1.4.45/
./configure
#注:在32位Linux操作系统上编译Tokyo cabinet,请使用./configure --enable-off64代替./configure,可以使数据库文件突破2GB的限制。
#./configure --enable-off64
make
make install
cd ../


  2、然后编译安装tokyotyrant
wget http://www.1978th.net/tokyotyrant/tokyotyrant-1.1.40.tar.gz
tar zxvf tokyotyrant-1.1.40.tar.gz
cd tokyotyrant-1.1.40/
./configure
make
make install
cd ../




  二、配置
  1、创建tokyotyrant数据文件存放目录
mkdir -p /ttserver/


  2、启动tokyotyrant的主进程(ttserver)
  (1)、单机模式
ulimit -SHn 51200
ttserver -host 127.0.0.1 -port 11211 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 1 -rts /ttserver/ttserver.rts /ttserver/database.tcb#lmemb=1024#nmemb=2048#bnum=10000000


  (2)、双机互为主辅模式
  服务器192.168.1.91:
ulimit -SHn 51200
ttserver -host 192.168.1.91 -port 11211 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 91 -mhost 192.168.1.92 -mport 11211 -rts /ttserver/ttserver.rts /ttserver/database.tcb#lmemb=1024#nmemb=2048#bnum=10000000


  服务器192.168.1.92:
ulimit -SHn 51200
ttserver -host 192.168.1.92 -port 11211 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 92 -mhost 192.168.1.91 -mport 11211 -rts /ttserver/ttserver.rts /ttserver/database.tcb#lmemb=1024#nmemb=2048#bnum=10000000


  (3)、参数说明
  ttserver [-host name] [-port num] [-thnum num] [-tout num] [-dmn] [-pid path] [-log path] [-ld|-le] [-ulog path] [-ulim num] [-uas] [-sid num] [-mhost name] [-mport num] [-rts path] [dbname]

  -host name : 指定需要绑定的服务器域名或IP地址。默认绑定这台服务器上的所有IP地址。
  -port num : 指定需要绑定的端口号。默认端口号为1978
  -thnum num : 指定线程数。默认为8个线程。
  -tout num : 指定每个会话的超时时间(单位为秒)。默认永不超时。
  -dmn : 以守护进程方式运行。
  -pid path : 输出进程ID到指定文件(这里指定文件名)。
  -log path : 输出日志信息到指定文件(这里指定文件名)。
  -ld : 在日志文件中还记录DEBUG调试信息。
  -le : 在日志文件中仅记录错误信息。
  -ulog path : 指定同步日志文件存放路径(这里指定目录名)。
  -ulim num : 指定每个同步日志文件的大小(例如128m)。
  -uas : 使用异步IO记录更新日志(使用此项会减少磁盘IO消耗,但是数据会先放在内存中,不会立即写入磁盘,如果重启服务器或ttserver进程被kill掉,将导致部分数据丢失。一般情况下不建议使用)。
  -sid num : 指定服务器ID号(当使用主辅模式时,每台ttserver需要不同的ID号)
  -mhost name : 指定主辅同步模式下,主服务器的域名或IP地址。
  -mport num : 指定主辅同步模式下,主服务器的端口号。
  -rts path : 指定用来存放同步时间戳的文件名。

  如果使用的是哈希数据库,可以指定参数“#bnum=xxx”来提高性能。它可以指定bucket存储桶的数量。例如指定“#bnum=1000000”,就可以将最新最热的100万条记录缓存在内存中:
ttserver -host 127.0.0.1 -port 11211 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 1 -rts /ttserver/ttserver.rts /ttserver/database.tch#bnum=1000000


  如果大量的客户端访问ttserver,请确保文件描述符够用。许多服务器的默认文件描述符为1024,可以在启动ttserver前使用ulimit命令提高这项值。例如:
ulimit -SHn 51200


  3、停止tokyotyrant(ttserver)
ps -ef | grep ttserver

  找到ttserver的进程号并kill,例如:
kill -TERM 2159




  三、调用
  1、任何Memcached客户端均可直接调用tokyotyrant。

  2、还可以通过HTTP方式调用,下面以Linux的curl命令为例,介绍如何操作tokyotyrant:
  (1)、写数据,将数据“value”写入到“key”中:
curl -X PUT http://127.0.0.1:11211/key -d "value"


  (2)、读数据,读取“key”中数据:


  (3)、删数据,删除“key”:




  附:文章修改历史

  ● [2008年08月07日] [Version 1.0] 撰写本文

  ● [2008年10月16日] [Version 1.1] Tokyo Cabinet 版本升级到 1.3.12;Tokyo Tyrant 版本升级到 1.1.5

  ● [2008年12月04日] [Version 1.2] Tokyo Cabinet 版本升级到 1.3.22;Tokyo Tyrant 版本升级到 1.1.8

  ● [2008年07月06日] [Version 1.3] Tokyo Cabinet 版本升级到 1.4.28;Tokyo Tyrant 版本升级到 1.1.29

  ● [2010年06月11日] [Version 1.4] Tokyo Cabinet 版本升级到 1.4.45;Tokyo Tyrant 版本升级到 1.1.40;默认示例改为B+Tree数据库;增加32位Linux操作系统上编译Tokyo cabinet的configue配置。





技术大类 » Cache与存储 | 评论(124) | 引用(7) | 阅读(172863)
coach outlet, Email Homepage
2012-5-17 11:43
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 17:05
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 17:05
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
xujie777 Email
2012-5-18 17:06
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
xujie123
2012-5-21 11:22
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
xujie555
2012-5-21 13:47
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 15:10
coach outlet online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website.coach factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
cheap oakley sunglasses Email Homepage
2012-7-18 13:31
Various designer Oakley Sunglasses Outlet for Sale in our store. Oakley Sunglasses at possible lowest price and high quality, fast delivery.Hot summer has already come, when you go out the most imporant things you need take is a pair of sunglasses. These fashion and stylish Cheap Oakley Sunglasses can protect your eyes well in the strong sunlight. We do not simply need a pair of sunglasses, we need protection from UV rays, we need to be cool in summer, show our understanding of fashion. In fact, all we need is a pair of Discount Oakley Sunglasses.
coach88888888 Email
2012-8-13 17:52
If you desire to go to Coach Factory Outlet, but have no idea in which to go, you can research online. It is no doubt that there is drastically information and details about it for the reference.Coach Factory Online are loved by many people, when you walk in the street, you could see many people take coach styles.hat experts claim Coach Outlet Online shopping is in the changes they are available in.Coach Outlet will send you a coupon in the post to use in their upon only after you type a achieve. The Coach bags are customarily somewhat many than the ones in the stores.
baozang
2012-9-22 13:27
Lamo - Like Sebago, Louis Vuitton Canada  there are only about 40 styles of Lamo Footwear. Most of their footwear uses a suede leather traditional in True Religion Jeans  moccasins, though only about 1/3 of the footwear collection is a traditional moccasin look. True Religion Brand Jeans The rest of the collection is slippers and UGG styled boots.Louis Vuitton Artsy The traditional moccasins do have a soft rubber sole making them great deck True Religion Sale shoes as well, however. Expect to pay between $50 and $60 for Lamo moccasins.  Invicta watches have been here since 1837. They were made by Raphael Picard. Invicta watches got its name from a Latin word. The meaning of Invicta in Louis Vuitton Monogram Vernis Alma BB Amarante Latin is "Invincible". Earlier these watches were not so popular but recently with its new men's collection this watch brand has gained a lot of popularity. Watches for many are a style statement and so they prefer to own the best piece. Invicta watches are popular as they are like a style statement.
BEATLS
2012-10-22 00:18
TC用的本地硬盘还是磁盘阵列性能好?
wadad
2012-10-23 20:49
哦下雪挖的挖的爱我的娃打我的娃
GAWE
2013-1-29 16:59
买轴承就到:www.jkzhoucheng.cn
GAWER
2013-3-1 16:17
买轴承就到:www.jkzhoucheng.cn
HAWER
2013-3-5 13:42
买轴承就到:www.jkzhoucheng.cn
crosser Email
2013-11-4 11:48
我在使用TT server的时候发现如果VALUE过大将会严重影响性能,5千万条记录也会让TTSERVER陷入性能瓶颈(使用的是B+TREE,如果用.tch,2000万条就扛不住了)。同时请教一下,当TTSERVER在运行中发生断电后该如何恢复。
nikenfl823 Email Homepage
2013-11-5 00:57
I've got to order that Prada is really a symbol regarding location. Along with these beautiful expect,fake longchamp refund, These are perfect in addition to renowned affordable 1st tee that provides an individual a sense belonging. Tailor made Tee shirt possesses great models for men and some women,is there a longchamp outlet store, You'll come to feel outstanding with the day-to-day statements and affirmations on the upper body. This company ended up being set up by means of Religious Moore. That&#thirty-nine;azines imitating the sensation connected with beech sneakers. take in air without restraint.
易发国际真人娱乐场所
[2014-5-21 05:28]
来源:易发国际
内容: 易发国际出于亚洲著名公司专业提供,易发国际真人娱乐,百家乐,轮盘,骰宝,龙虎,路单,棋牌,游乐场等易发国际精彩娱乐。信用第一值得大众信赖。
易发国际真人娱乐场所
[2014-5-21 07:09]
来源:易发国际
内容: 易发国际出于亚洲著名公司专业提供,易发国际真人娱乐,百家乐,轮盘,骰宝,龙虎,路单,棋牌,游乐场等易发国际精彩娱乐。信用第一值得大众信赖。
易发国际真人娱乐场所
[2014-5-21 07:09]
来源:易发国际
内容: 易发国际出于亚洲著名公司专业提供,易发国际真人娱乐,百家乐,轮盘,骰宝,龙虎,路单,棋牌,游乐场等易发国际精彩娱乐。信用第一值得大众信赖。
分页: 5/7 第一页 上页 1 2 3 4 5 6 7 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]