TokyoCabinet/TokyoTyrant ã Rails ã§ä½¿ã
ã¤ã³ã¹ãã¼ã«
TokyoCabinet
% wget http://tokyocabinet.sourceforge.net/tokyocabinet-1.3.27.tar.gz % tar zxvf tokyocabinet-1.3.27.tar.gz % cd tokyocabinet-1.3.27 % ./configure --prefix=/usr/local % make % make check % sudo make install
TokyoCabinet Ruby API
% wget http://tokyocabinet.sourceforge.net/rubypkg/tokyocabinet-ruby-1.18.tar.gz % tar zxvf tokyocabinet-ruby-1.18.tar.gz % cd tokyocabinet-ruby-1.18 % ruby extconf.rb % make % sudo make install
TokyoTyrant
% wget http://tokyocabinet.sourceforge.net/tyrantpkg/tokyotyrant-1.1.11.tar.gz % tar zxvf tokyotyrant-1.1.11.tar.gz % cd tokyotyrant-1.1.11 % ./configure --prefix=/usr/local % make % sudo make install
TokyoTyrant Ruby API
% wget http://tokyocabinet.sourceforge.net/tyrantpkg/tokyotyrant-ruby-1.2.tar.gz % tar zxvf tokyotyrant-ruby-1.2.tar.gz % cd tokyotyrant-ruby-1.2 % sudo ruby install.rb
åä½ç¢ºèª
TokyoCabinetã®ç¢ºèª
% ruby example.rb hop foo:hop bar:step baz:jump quux:touchdown touchdown foo:hop bar:step baz:jump quux:touchdown
TokyoTyrantã®ç¢ºèª
% sudo ttservctl start % ruby example-tyrant.rb hop foo:hop bar:step baz:jump touchdown foo:hop bar:step baz:jump quux:touchdown
ã²ã¨ã¾ãåããã¨ã確èªï¼
è¨å®
ç¹ã«è¨å®ãã¡ã¤ã«ã¯ç¡ãã¦ï¼ttservctl(/usr/local/sbin/ttservctl)ã«ç´æ¸ãããã¦ããï¼
8 # configuration variables 9 prog="ttservctl" 10 cmd="ttserver" 11 basedir="/var/ttserver" 12 port="1978" 13 pidfile="$basedir/pid" 14 logfile="$basedir/log" 15 ulogdir="$basedir/ulog" 16 ulimsiz="256m" 17 sid=1 18 dbname="$basedir/casket.tch#bnum=1000000" 19 maxcon="65536" 20 retval=0
ãµã¼ãã®å®è¡èªä½ã¯æ¬¡ã®ãããªæãï¼
39 $cmd \ 40 -port "$port" \ 41 -dmn \ 42 -pid "$pidfile" \ 43 -log "$logfile" \ 44 -ulog "$ulogdir" \ 45 -ulim "$ulimsiz" \ 46 -sid "$sid" \ 47 "$dbname"
ã¨ãããã¨ã§ï¼ãããè¦ç¿ã£ã¦æåã§ãã£ã¦ã¿ãï¼
% ttserver -port 1978 -dmn -pid "$PWD/ttserver.pid" -log "$PWD/ttserver.log" -ulog "$PWD/ttserver.ulog" -ulim "256m" -sid "1" "$PWD/casket.tch#bnum=1000000" % ruby example-tyrant.rb hop foo:hop bar:step baz:jump touchdown foo:hop bar:step baz:jump quux:touchdown
ãã㧠pid/log/ulog/dbname ã«é¢ãã¦ã¯ full-path ã§ãªããã°åä½ããªãã®ã§æ³¨æãå¿ è¦ï¼
Ruby ã®ãªãã¸ã§ã¯ããä¿åããã«ã¯
Marshal.dump/Marshal.load ã使ãã¾ãï¼
ããã§ã¯ã¡ããã¨åãåºãã¦ãããã©ããã調ã¹ã¦ããã§ããï¼åä¸ãªãã¸ã§ã¯ããã©ãããå¤æããããã« == ãåå®ç¾©ãã¦ãã¾ãï¼
Rails ã§ä½¿ã
試ãã«ä»¥ä¸ã®ãããªãµã³ãã«ãä½ã£ã¦åããã¦ã¿ã¾ãï¼
% rails tt-test % cd tt-test % ruby script/generate model User name:string % ruby script/generate model --skip-migration UserAccessLog
ã¦ã¼ã¶(User)ã¨ãã®ã¢ã¯ã»ã¹æ¥æè¨é²(UserAccessLog)ã§ãï¼TyokyoTyrant 㯠memcached äºæãªãã§ããï¼ããã¯ããã¨ãã¦ï¼åãªããã¼ã¿ãã¼ã¹ã¨ãã¦æ±ã£ã¦ã¿ã¾ãï¼
% ruby script/console >> u = User.new({:name => "hogehoge"}) => #<User id: 1, name: "hogehoge", created_at: "2009-01-09 04:11:26", updated_at: "2009-01-09 04:11:26"> >> u.access_time => nil >> u.access_time = Time.now => Fri Jan 09 13:31:25 0900 2009 >> u.access_time => Fri Jan 09 13:31:25 0900 2009 >> exit % ruby script/console >> u = User.find(1) => #<User id: 1, name: "hogehoge", created_at: "2009-01-09 04:11:26", updated_at: "2009-01-09 04:11:26"> >> u.access_time => Fri Jan 09 13:31:25 0900 2009
ããã§ééçã« TokyoTyrant ãæ±ããã¨ãã§ãã¾ããï¼mixiのようã«ï¼ã¢ã¯ã»ã¹æéã®è¨é²ãªã©ã«ã¯ï¼é常ã«å¼·åãªãã¼ã¿ãã¼ã¹ã¨ãã¦æ±ããã¨ãã§ããã®ã§ï¼ä½¿ãæ¹æ¬¡ç¬¬ã§ã¯è² è·åæ£ã§ãããã§ãï¼