about processes and engines

rufus-tokyo 0.1.3 with Tokyo Cabinet tables

Just released the Ruby gem rufus-tokyo 0.1.3. It gives easy access to Tokyo Cabinet hashes and tables via Ruby.

  require 'rubygems'
  require 'rufus/tokyo'

  db ='data.tch')

  db['nada'] = 'surf'

  p db['nada'] # => 'surf'
  p db['lost'] # => nil


This new release has undergone serious code restructurations (thanks Justin) and it features access to Tokyo Cabinet “tables” :

  require 'rubygems'
  require 'rufus/tokyo/cabinet/table'

  t ='table.tdb', :create, :write)

  t['pk0'] = { 'name' => 'alfred', 'age' => '22' }
  t['pk1'] = { 'name' => 'bob', 'age' => '18' }
  t['pk2'] = { 'name' => 'charly', 'age' => '45' }
  t['pk3'] = { 'name' => 'doug', 'age' => '77' }
  t['pk4'] = { 'name' => 'ephrem', 'age' => '32' }

  p t.query { |q|
    q.add_condition 'age', :numge, '32'
    q.order_by 'age'
    # => [ {"name"=>"ephrem", :pk=>"pk4", "age"=>"32"},
    #      {"name"=>"charly", :pk=>"pk2", "age"=>"45"} ]

  p t.query { |q|
    q.add_condition 'name', :matches, 'a'
    q.order_by 'name', :desc
    # => [ {"name"=>"charly", :pk=>"pk2", "age"=>"45"}, 
    #      {"name"=>"alfred", :pk=>"pk0", "age"=>"22"} ]


Zev and I ran a few benchmarks with this table feature.

Warning : this is only some exploratory benchmarking ! Don’t build religious dogma on top of it !

Yielded results were quite interesting :

(Thanks Faker)

My integration work / gem is very naive for now, Mikio Hirabayashi’s Tokyo Cabinet project is rather deep, it features many interesting structures (hashes, b-trees, tables) and then there’s the Dystopia

I’m looking forward continuing this work and enhancing rufus-tokyo to provide further Tokyo Cabinet features / tuning options.

Tested with Ruby 1.8.6 and JRuby 1.1.6.

Written by John Mettraux

January 29, 2009 at 8:33 am

Posted in ruby, rufus, tokyocabinet

2 Responses

Subscribe to comments with RSS.

  1. So it looks like inserts are mega fast, but some of the reads are a lot slower than AR with a regular database, or am I reading this incorrectly?

    Is it ready for production use or would you recommend using MySQL/Postgres for now?

    Thanks for the writeup!

    Paul Smith

    February 13, 2009 at 5:15 pm

  2. Hi Paul,

    Tokyo Cabinet / Tyrant are ready for production.

    Rufus-tokyo should be as well, since it’s just a nice ruby wrapper around native libs.

    There is one catch with Tokyo Cabinet/Tyrant tables, the data types are limited to String and… String, with a possibility of flagging a column as decimal index, so it falls a bit short of the classical players. But I guess it’s “work aroundable”.

    The benchmark you’re seeing here is very naive about the queries, I hadn’t wrapped the setindex method at the moment of writing, now results for queries would probably be better.

    (how to set indexes, the beginning of a spec :

    Best regards,

    John Mettraux

    February 13, 2009 at 11:34 pm

Comments are closed.

%d bloggers like this: