ruby,no sql and tokyocabinet

22
Ruby,NoSQL and TokyoCabinet 盛盛盛盛盛 盛盛盛 http://www.zhuangbiaowei.com/blog/

Upload: -

Post on 19-May-2015

3.986 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Ruby,no sql and tokyocabinet

Ruby,NoSQL and TokyoCabinet

盛大创新院 庄表伟http://www.zhuangbiaowei.com/blog/

Page 2: Ruby,no sql and tokyocabinet

From RDBMS to NoSQL (1)

Long long ago …Network Database (GE IDS 1961)Hierarchical Database (IBM IMS 1968)

Relational database eraEdgar Frank Codd -- Since 1969Relational modelSQLManagement systemOver $ 20 billion (2008)

Page 3: Ruby,no sql and tokyocabinet

Now is Web2.0 eraHave huge storage(TB/PB data size)Need high performanceNeed high scalabilityNeed high availability

NoSQL now comingNew theory supportNew API styleNew buzzword

From RDBMS to NoSQL (2)

Page 4: Ruby,no sql and tokyocabinet

Projects or papers…Google BigTable (2004)Tokyo Cabinet (2006)Amazon Dynamo (2007)MongoDB,CouchDB,Cassandra,Voldemort

(2008)Redis,Riak,HBase… (2009)More and more…

From RDBMS to NoSQL (3)

Page 5: Ruby,no sql and tokyocabinet

CAP (Eric Brewer 2000)ConsistencyAvailabilityPartition tolerance

BASEBasically AvailableSoft-stateEventual Consistency

MapReduceFrom functional programmingDistributed computing framework

Important NoSQL theory

Page 6: Ruby,no sql and tokyocabinet

Loss of data integrityAny data is allowed

Can not ensure data consistencyEventual Consistency

No transaction Stored procedure convert to map/reduce

script Lack support of management system System refactoring or rewrite

Choose NoSQL means…

Page 7: Ruby,no sql and tokyocabinet

by Mikio Hirabayashi ( 平林幹雄 )http://1978th.net/

TokyoCabinet -- lightweight database library TokyoTyrant -- lightweight database server Key/Value Database Database types

Hash / B+ Tree / Fixed-length / Table High performance

Insert: 0.4sec/1M records(2,500,000 qps)Search: 0.33sec/1M records(3,000,000 qps)

High concurrency High Scalability

TokyoCabinet and TokyoTyrant

Page 8: Ruby,no sql and tokyocabinet

Everyone table need a port Loss table struct and data type Can not access by column Reduction of performance

Read 400,000 record/sec(TCT)Read 1,800,000 record/sec(TCH)Read 1,000,000 record/sec(TCB)

When the data more than 100 million, will performance reduction

Network protocol is not perfect

TC/TT table engine insuffi ciency

Page 9: Ruby,no sql and tokyocabinet

One port,more table Row access and column access B+ tree data store New binary api protocol New data storage mode

Config TCHIndex TCBData TCB

About TCDatabase

Page 10: Ruby,no sql and tokyocabinet

ActiveTokyoCabinet (1)

Config

Page 11: Ruby,no sql and tokyocabinet

Model

ActiveTokyoCabinet (2)

Page 12: Ruby,no sql and tokyocabinet

database.ymldevelopment:

adapter: tcdb

path: ./db

database: blog

modelclass Post < ActiveRecord::Base validates_presence_of :body, :title has_many :commentsend

About tcdb-adapter (1)

Page 13: Ruby,no sql and tokyocabinet

Migrationclass CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :title t.text :body t.timestamps end end def self.down drop_table :posts endend

About tcdb-adapter (2)

Page 14: Ruby,no sql and tokyocabinet

Demo

Page 15: Ruby,no sql and tokyocabinet

SQLite MySQL OracleMoney

MySQL MySQL MySQLDBA

RDBMS NoSQLRisk

RDBMS tcdb-adapter NoSQLSQL/NoSQL Bridge

Storage architecture migration

Page 16: Ruby,no sql and tokyocabinet

Rails

ActiveRecord

MysqlAdapter

MySQL

Architecture diagram (today)

Rails

ActiveRecord(modify)

TokyoCabinetAdapter

TokyoCabinet/TokyoTyrant

Classic ActiveTokyoCabinet

Rails

ActiveRecord

TcdbAdapter

tcdb.rb

tcdb-adapter

Page 17: Ruby,no sql and tokyocabinet

TCDatabase Cloud DatabaseTransparent distributedRunning like mysql proxyAccess to TC / MongoDB / MySQL / moreConfiguration and management support

Tcdb-adapter Cloud ActiveRecordAlmost support all of the SQLRails3 support (based arel)Intergration thinking sphinxOne Interface, One architecture!

You can imagine more …

The future

Page 18: Ruby,no sql and tokyocabinet

Architecture diagram (future - 1)

Rails

ActiveRecord

TcdbAdapter

TCDatabase

Page 19: Ruby,no sql and tokyocabinet

Architecture diagram (future - 2)

Rails

ActiveRecord

TcdbAdapter

TCDatabaseTCData

base

TCDatabase

TCDatabase

Page 20: Ruby,no sql and tokyocabinet

Rails

ActiveRecord

CloudDBAdapter

CloudDatabase

TokyoCabinet MongoDB …… Sphinx MySQL

Architecture diagram (future - 3)

Page 21: Ruby,no sql and tokyocabinet

It will be open source!

Page 22: Ruby,no sql and tokyocabinet

THANKS