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 = Rufus::Tokyo::Cabinet.new('data.tch')
db['nada'] = 'surf'
p db['nada'] # => 'surf'
p db['lost'] # => nil
db.close
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 = Rufus::Tokyo::Table.new('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"} ]
t.close
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 :
- playing with 4 records : http://gist.github.com/54343 (AR (mysql/sqlite3), TC tables)
- 10_000 records : http://gist.github.com/54371 (AR (mysql), TC tables)
- 1_000 records : http://gist.github.com/54409 (AR (mysql/sqlite3), TC tables)
(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.
http://github.com/jmettraux/rufus-tokyo/
Tested with Ruby 1.8.6 and JRuby 1.1.6.
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
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 : http://github.com/jmettraux/rufus-tokyo/blob/86a41ecbc1fb118a36b20809bd22e3bd029a361c/spec/table_spec.rb#L100-116)
Best regards,
John Mettraux
February 13, 2009 at 11:34 pm