27
IMDB Showdown @robertfriberg [email protected] origodb.com

IMDB Showdown - OrigoDB, Redis and Hekaton

Embed Size (px)

Citation preview

Page 1: IMDB Showdown - OrigoDB, Redis and Hekaton

IMDB Showdown@robertfriberg

[email protected]

Page 2: IMDB Showdown - OrigoDB, Redis and Hekaton

Speed of light vs spinning metal

What Time ScaleL1 Cache 0.5 ns 0.008 2 mL2 Cache 7 ns 0.23RAM 60 ns 1 240 m 1 second1K over Gbit network 10 µs 167 2.5 minutes4K read SSD 150 µs 2500Rotating disk seek 10 ms 167000 40000 km 46 hours

Page 3: IMDB Showdown - OrigoDB, Redis and Hekaton

Price/GB vs GB/Server 1980- 2015

8 USD

6.480.000 USD

0.001 GB

2000 GB

Page 4: IMDB Showdown - OrigoDB, Redis and Hekaton

In-memory stores

• VoltDB• MemSQL

• Hazelcast• Aerospike• Memcached• Oracle Coherence• Redis

• Oracle Times Ten• SQL Server

In-memory OLTP• SAP Hana

• OrigoDBKey/value

New SQL Hybrid

?

Page 5: IMDB Showdown - OrigoDB, Redis and Hekaton

1. SQL ServerIn-memory OLTP

Page 6: IMDB Showdown - OrigoDB, Redis and Hekaton

B-trees and Transactions

LOG

DATA 64KB blocks w 8x8KB pagesLogical BTREE of 8kb data pagesIn the buffer pool (cache)

BufferManager

Transactions append inserted, deleted, original and modified pages to the LOG

CHECKPOINT

Page 7: IMDB Showdown - OrigoDB, Redis and Hekaton

SQL Server In-memory OLTP

SP

Logging

Latches

Locks

Buffer Manager I/O

Native compiled SPs

Minimal Logging and checkpointing

Lock-free data structures

Multi-version Currency control

In Memory and Memory optimized data structures

Page 8: IMDB Showdown - OrigoDB, Redis and Hekaton

Sql Server In-memory OLTP

• Heka = Greek for 100• Transparent for application• Integrates with Sql Server but with limitations• Enterprise license• 5-30x performance gain

Page 9: IMDB Showdown - OrigoDB, Redis and Hekaton

Demo!

Page 10: IMDB Showdown - OrigoDB, Redis and Hekaton

2. RedisREmote DIctionary Server

Page 11: IMDB Showdown - OrigoDB, Redis and Hekaton

• Hybrid Key/Value store• Value -> String | List | Set | Hash | SortedSet• Predefined Commands -> SET | GET | HSET | ...• Persistence: Snapshots + AOF• Highly optimized C, fast algorithms

Page 12: IMDB Showdown - OrigoDB, Redis and Hekaton

Twitter using redis

INCR next_user_id //returns 1000HMSET user:1000 name bart password ¤¤¤hash¤¤¤HSET users bart 1000ZADD followers:1000 1401267618 1234ZADD following:1234 1401267618 1000INCR next_post_id => 10343HMSET post:10343 user 1000 time $time body ’Ay Caramba’RPUSH posts:1000 10343

Page 13: IMDB Showdown - OrigoDB, Redis and Hekaton

3. OrigoDBBuild faster systems faster

Page 14: IMDB Showdown - OrigoDB, Redis and Hekaton

What’s the problem?

ServiceLayer

DomainLayer

Data AccessLayer

RelationalModel

Views/SP’s

CacheX

Page 15: IMDB Showdown - OrigoDB, Redis and Hekaton

One simple idea...

Keep state in memoryPersist operations, not system state

s0 s1 s2op1 op2

Sn = apply(opn, Sn-1)

Page 16: IMDB Showdown - OrigoDB, Redis and Hekaton

... with many names

• System prevalance – Prevalyer, java• MongoDB op log• Redis AOF• Memory Image – Martin Fowler• VoltDB – logical logging• Akka persistence – logging per actor• Event Sourcing

Page 17: IMDB Showdown - OrigoDB, Redis and Hekaton

OrigoDB

Kernel

Engine

Model

Storage

App Code

Server

Command

Query

FileSqlEvent StoreCustom

ConsistencyIsolationconcurrency

Sends commands and queries

JournalingSnapshotsBinaryFormatterProtoBufJSON

tcpJSON/http

In-processcalls

Domain specificobject-graph

Domain specific operations

ReplicationAd-hoc queriesWeb uiConsole or win svc

Page 18: IMDB Showdown - OrigoDB, Redis and Hekaton

Complete history of events

• Point in time • Debugging• Restore• Queries

• Audit trail• New interpretations

Page 19: IMDB Showdown - OrigoDB, Redis and Hekaton

Example – the model[Serializable]public class CommerceModel : Model{ internal SortedDictionary<Guid, Customer> Customers { get; set; } internal SortedDictionary<Guid, Order> Orders { get; set; } internal SortedDictionary<Guid, Product> Products { get; set; }

public CommerceModel() { Customers = new SortedDictionary<Guid, Customer>(); Orders = new SortedDictionary<Guid, Order>(); Products = new SortedDictionary<Guid, Product>(); } }

Page 20: IMDB Showdown - OrigoDB, Redis and Hekaton

Command[Serializable]public class AddCustomer : Command<CommerceModel>{ public readonly Guid Id; public readonly string Name;

public AddCustomer(Guid id, String name) { Id = id; Name = name; }

public override void Execute(CommerceModel model) { if (model.Customers.ContainsKey(Id)) Abort("Duplicate customer id"); var customer = new Customer {Id = Id, Name = Name}; model.Customers.Add(Id, customer); }}

Page 21: IMDB Showdown - OrigoDB, Redis and Hekaton

Query[Serializable]

public class CustomerById : Query<CommerceModel, CustomerView>

{

public readonly Guid Id;

public CustomerById(Guid id)

{

Id = id;

}

public override CustomerView Execute(CommerceModel model)

{

if (!model.Customers.ContainsKey(Id)) throw new Exception("no such customer");

return new CustomerView(model.Customers[Id]);

}

}

Page 22: IMDB Showdown - OrigoDB, Redis and Hekaton

Start your engines!static void Main(string[] args)

{

var engine = Engine.For<CommerceModel>();

Guid id = Guid.NewGuid();

var customerCommand = new AddCustomer(id, "Homer");

engine.Execute(customerCommand);

var customerView = engine.Execute(new CustomerById(id));

Console.WriteLine(customerView.Name);

Console.WriteLine("{0} orders", customerView.OrderIds.Count);

Console.ReadLine();

}

Page 23: IMDB Showdown - OrigoDB, Redis and Hekaton

Demo!Geekstream

Page 24: IMDB Showdown - OrigoDB, Redis and Hekaton

4. ConclusionThe old, the new and the ugly

Page 25: IMDB Showdown - OrigoDB, Redis and Hekaton

100% ACID Out of the Box?

SQL Server Redis OrigoDBAtomicity NO NO YESConsistency NO NO YESIsolation NO YES YESDurability YES YES YES

Page 26: IMDB Showdown - OrigoDB, Redis and Hekaton

Comparison Matrix

SQL REDIS ORIGO

License/Cost $$ OSS/Free MIT/Free (+$)

Language TSQL Commands + Lua C#/LINQ

OLTP YES YES YES

OLAP (indexing) YES NO YES

In-process NO NO YES

Througput/latency 3 1 2

Modeling Relational Fixed Multi

Maturity 1 2 3

Size 250GB/DB Available RAM Available RAM

Page 27: IMDB Showdown - OrigoDB, Redis and Hekaton

Thank you!

• Try Origo!• Contribute, it’s open source• http://origodb.com• @robertfriberg, [email protected]