Dont Give Up on Serializability Just Yet Neha Narula Dont Give Up on - - PowerPoint PPT Presentation

don t give up on serializability just yet
SMART_READER_LITE
LIVE PREVIEW

Dont Give Up on Serializability Just Yet Neha Narula Dont Give Up on - - PowerPoint PPT Presentation

Dont Give Up on Serializability Just Yet Neha Narula Dont Give Up on Serializability Just Yet A journey into serializable systems Neha Narula MIT CSAIL GOTO Chicago May 2015 2 @neha PhD candidate at MIT Formerly at Google


slide-1
SLIDE 1

Don’t Give Up on Serializability Just Yet

Neha Narula

slide-2
SLIDE 2

Don’t Give Up on Serializability Just Yet

Neha Narula MIT CSAIL GOTO Chicago May 2015

2 ¡

A journey into serializable systems

slide-3
SLIDE 3

@neha

3 ¡

  • PhD candidate at

MIT

  • Formerly at

Google

  • Research in fast

transactions for multi-core databases and distributed systems

slide-4
SLIDE 4

4 ¡

However, the most important person in my gang will be a systems programmer. A person who can debug a device driver

  • r a distributed system is a person who

can be trusted in a Hobbesian nightmare

  • f breathtaking scope; a systems

programmer has seen the terrors of the world and understood the intrinsic horror

  • f existence.
slide-5
SLIDE 5

A journey into serializable systems

slide-6
SLIDE 6

6 ¡

slide-7
SLIDE 7

1M messages/sec 1/5 of all page views in the US 1M messages/sec from mobile devices

slide-8
SLIDE 8

Databases are difficult to scale

8 ¡

Application servers are stateless; add more for more traffic Database is stateful

slide-9
SLIDE 9

Distributed databases

9 ¡

Partition data on multiple servers for more performance

slide-10
SLIDE 10

Example partitioned database

Database ¡ Database ¡ Database ¡ widgets table

widget_id 100-199 0-99 200-299

Webservers Database ¡

?

slide-11
SLIDE 11

2007

  • Mapreduce
  • Google File System
  • Bigtable

11 ¡

slide-12
SLIDE 12

Pros/Cons

  • In-memory
  • HIGHLY scalable
  • Transparently fault

tolerant

  • Geo replication

12 ¡

  • No schema
  • Require complex

key/row/document design

  • No query language
  • No indexes
  • No transactions
  • No guarantees
slide-13
SLIDE 13

13 ¡

slide-14
SLIDE 14

14 ¡

slide-15
SLIDE 15

15 ¡

mysql> BEGIN TRANSACTION UPDATE … COMMIT

slide-16
SLIDE 16

Problem with dropping transactions

  • Difficult to reason about concurrent

interleavings

  • Might result in incorrect, unrecoverable

state

16 ¡

slide-17
SLIDE 17
slide-18
SLIDE 18

“The hacker discovered that multiple simultaneous withdrawals are processed essentially at the same time and that the system's software doesn't check quickly enough for a negative balance”

h1p://arstechnica.com/security/2014/03/yet-­‑another-­‑exchange-­‑hacked-­‑poloniex-­‑loses-­‑ around-­‑50000-­‑in-­‑bitcoin/ ¡

slide-19
SLIDE 19

Consistency guarantees help us reason about our code and avoid subtle bugs

slide-20
SLIDE 20

Consistency

A very misused word in systems!

  • C as in ACID
  • C as in CAP
  • C as in sequential, causal, eventual, strict

consistency

slide-21
SLIDE 21

ACID Transactions

Atomic Consistent Isolated Durable

21 ¡

Whole thing happens or not Application-defined correctness Other transactions do not interfere Can recover correctly from a crash

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION ... COMMIT

slide-22
SLIDE 22

What is Serializability?

22 ¡

Serializability != Serial

slide-23
SLIDE 23

What is Serializability?

The result of executing a set of transactions is the same as if those transactions had executed one at a time, in some serial order. If each transaction preserves correctness, the DB will be in a correct state. We can pretend like there’s no concurrency!

23 ¡

slide-24
SLIDE 24

TXN1(k, j Key) (Value, Value) { a := GET(k) b := GET(j) return a, b }

Database transactions should be serializable

24 ¡

TXN2(k, j Key) { ADD(k,1) ADD(j,1) } TXN1 TXN2 TXN2 TXN1

time

  • r

To the programmer: Valid return values for TX1: (0,0) k=0,j=0

  • r (1,1)
slide-25
SLIDE 25

Benefits of Serializability

  • Do not have to reason about interleavings
  • Do not have to express invariants separately

from the code!

25 ¡

slide-26
SLIDE 26

Serializability Costs

  • On a multi-core database, serialization and

cache line transfers

  • On a distributed database, serialization and

network calls Concurrency control: Locking and coordination

26 ¡

slide-27
SLIDE 27

Eventual consistency

If no new updates are made to the object, eventually all accesses will return the last updated value.

slide-28
SLIDE 28

Eventual consistency

If no new updates are made to the object, eventually all accesses will return the last updated value the same value. (What is last, really?) (And when do we stop writing?) (And what about multi-key transactions?)

slide-29
SLIDE 29

Sequential consistency: cache coherence

P1 ¡ P2 ¡ P3 ¡ RAM ¡

slide-30
SLIDE 30

P1: ¡W(x)a ¡ P2: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)b ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)a ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)b ¡ P1: ¡W(x)a ¡ P2: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)b ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)a ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)b ¡

Lme ¡ Lme ¡

slide-31
SLIDE 31

P1: ¡W(x)a ¡ P2: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)b ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)b ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)a ¡ P1: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)a ¡ P2: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)b ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)b ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)a ¡

Lme ¡ Lme ¡

slide-32
SLIDE 32

External Consistency

Everything that sequential consistency has Except results actually match time. An external observer

slide-33
SLIDE 33

P1: ¡W(x)a ¡ P2: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡W(x)b ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)b ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R(x)a ¡

The ¡value ¡of ¡x ¡ is ¡b! ¡ Then ¡I ¡read ¡ x=a? ¡

¡ ¡ P3: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

Not Externally Consistent

Lme ¡

slide-34
SLIDE 34

CAP Theorem

  • Brewer’s PODC talk: “Consistency, Availability,

Partition-tolerance: choose two” in 2000

– Partition-tolerance is a failure model – Choice: can you process reads and writes during a partition or not?

  • FLP result – “Impossibility of Distributed

Consensus with One Faulty Process” in 1985

– Asynchronous model; cannot tell the difference between message delay and failure

slide-35
SLIDE 35

What does this mean?

It’s impossible to decide anything on the internet?

slide-36
SLIDE 36

NP-hard

slide-37
SLIDE 37

What does CAP mean?

It’s impossible to 100% of the time decide everything on the internet if we can’t rely on synchronous messaging We can 100% of the time decide everything if partitions heal (we know the upper bound on message delays) We can still play Candy Crush

slide-38
SLIDE 38

CAP Consistency vs. Performance

Consistency (like serializability) requires communication and blocking How do we reduce these costs while:

  • Producing a correct ordering of reads and

writes and

  • Handling failures and (eventually) making

progress?

slide-39
SLIDE 39

Improving Serializability Performance

39 ¡

Technique Systems Atomic clocks to bound time skew Spanner Transaction chopping Lynx, ROCOCO Commutative locking Escrow transactions, abstract data types, Doppel Deterministic ordering Granola, Calvin

slide-40
SLIDE 40

Goal: parallel performance

  • Different concurrency control schemes for

popular, contended data

  • Commutative locking
  • Abstract datatypes
  • Per-core (or per-server) data and

constraints

40 ¡

slide-41
SLIDE 41

Ordered PUT, insert to an

  • rdered list, user-defined

functions

Operation Model

Developers write transactions as stored procedures which are composed of operations on keys and values:

41 ¡

value GET(k) void PUT(k,v) void INCR(k,n) void MAX(k,n) void MULT(k,n) void OPUT(k,v,o) void TOPK_INSERT(k,v,o) void UDF(k,v,a)

Traditional key/value

  • perations

Operations on numeric values which modify the existing value Replicate for reads Save last write Replicate for commutative

  • perations

Log operations

slide-42
SLIDE 42

Spanner/F1

“We believe it is better to have application programmers deal with performance problems due to overuse of transactions as bottlenecks arise, rather than always coding around the lack of transactions.”

slide-43
SLIDE 43

Takeaways

  • Use well-tested, long-lived database

systems

  • Use SERIALIZABLE until it becomes a

performance problem

  • Think about what is changing when you

move to systems with different models

43 ¡

slide-44
SLIDE 44

Thanks!

The ¡Stata ¡Center ¡via ¡emax: ¡h1p://hip.cat/emax/ ¡

narula@mit.edu http://nehanaru.la @neha

slide-45
SLIDE 45

Questions?

Please remember to evaluate via the GOTO Guide App