Secrets of the Kyoto Cabinet

Posted by Mislav Ćosić Friday, Feb 03, 2017

If you are looking for an ultra fast key value or B+ database, you are at the right place.

Kyoto Cabinet is a storage engine. Data is stored into files. Each key value pair has one file. Beside key value store, Kyoto Cabinet supports B+ data structure.

It is a DBM, so there are no concepts like tables and data types as there are in relational databases. If you are looking for features like joint table and foreign keys, Kyoto Cabinet is not the candidate for your future database.

Beside great speed, Kyoto Cabinet offers really small overhead on stored data. Just 16 bytes for hash database and 4 bytes for B+ tree database. So once your data ends up on a disk, it will take as less space as possible. Scalability is where Kyoto Cabinet shines. A database can grow up to 8 exabytes (8e+9 gigabytes).

Robustness gives security, so data will not corrupt even under catastrophic situation. The engine is optimised for parallelism. It is suitable for the multi-threaded environment.

Kyoto Cabinet is written in C++ and provides APIs for the following programming languages C++, C, Java, Python, Ruby, Perl and Lua. It is published under GNU license. However, there is a commercial License for proprietary software.

When should we use Kyoto Cabinet over other key values storage? The area where Kyoto Cabinet shines is a database with large values stored (e.g. 1KB).

If you want to check other similar storage engines and compare them to the Kyoto Cabinet you can do it at the following link:

Let's jump to an example to show how easy Kyoto Cabinet is to use. We will use Kyoto Tycoon which is server implementation of Kyoto Cabinet. For the sake of simplicity, we will run Docker image. So you have to have Docker installed on your server.

Run  Kyoto Tycoon:

docker pull hensansi/kyototycoon
docker run -d -p 1978:1978 hensansi/kyototycoon

Kyoto Tycoon server is running on the port 1978. We will use a simple Perl script to store data onto the running server. To run the following script, you need Cache::KyotoTycoon CPAN Perl module install on the server.

Perl script:

use Cache::KyotoTycoon;
my $kt = Cache::KyotoTycoon->new(host => '', port => 1978);
$kt->set(  foo => ‘bar’);
print $kt->get('foo') . “ ”;

That is all!

comments powered by Disqus

news / events / blogs