Achieving 100,000 Transactions Per Second with a NoSQL Database

52
Achieving 100,000 Transactions Per Second with a NoSQL Database Eric David Bloch @eedeebee 19 jun 2012

description

Achieving 100,000 Transactions Per Second with a NoSQL Database. Eric David Bloch @ eedeebee 19 jun 2012. A bit about me. I’ve written software used by millions of people. Apps, libraries, compilers, device drivers, operating systems This is my second QCon and my first talk - PowerPoint PPT Presentation

Transcript of Achieving 100,000 Transactions Per Second with a NoSQL Database

Page 1: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Achieving 100,000 Transactions Per Second with a NoSQL Database

Eric David Bloch@eedeebee

19 jun 2012

Page 2: Achieving  100,000 Transactions Per Second  with a NoSQL Database

• I’ve written software used by millions of people.

Apps, libraries, compilers, device drivers, operating

systems

• This is my second QCon and my first talk

• I’m the Community Director at MarkLogic, last 2 years.

• Born here in NY in 1965; now in CA

• I survived having 3 kids in less than 2 years.

A bit about me

Page 3: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Me, 1967

Page 4: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Me, today

Page 5: Achieving  100,000 Transactions Per Second  with a NoSQL Database

A: Why?

B: How?Whirl-wind database architecture tourMelody from part A againTechniques to get to 100K

Musical Form for the Talk

Page 6: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 7: Achieving  100,000 Transactions Per Second  with a NoSQL Database

It’s about money.

Top 5 bank needed to manage trades Trades look more like documents than tables Schemas for trades change all the time Transactions Scale and velocity (“Big Data”)

Page 8: Achieving  100,000 Transactions Per Second  with a NoSQL Database

1 million trades per day Followed by 1 million position reports at end of day

Roll up trades of current date for each “book, instrument” pair Group-by, with key = “date, book, instrument”

Day1

Day2

1M trades1M positions

Day3

Day4

Day5

. . .

Trades and Positions

Page 9: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Trades and Positions

<trade> <quantity>8540882</quantity> <quantity2>1193.71</quantity2> <instrument>WASAX</instrument> <book>679</book> <trade-date>2011-03-13-07:00</trade-date> <settle-date>2011-03-17-07:00</settle-date></trade>

<position> <instrument>EAAFX</instrument> <book>679</book> <quantity>3</quantity> <business-date>2011-03-25Z</business-date> <position-date>2011-03-24Z</position-date></position>

Page 10: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Now show us

• 15K inserts per second• Linear scalability

Page 11: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Requirements

NoSQL flexibility, performance & scale

Enterprise-grade

transactional guarantees

Page 12: Achieving  100,000 Transactions Per Second  with a NoSQL Database

What NoSQL, OldSQL, or NewSQLdatabase out there can we use?

?

Page 13: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 14: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 15: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 16: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Your database has a large effect on how you see the

world

Page 17: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 18: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 18 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 18 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

What is MarkLogic?

Non-relational, document-oriented, distributed database Shared nothing clustering, linear scale out Multi-Version Concurrency Control (MVCC) Transactions (ACID)

Search Engine Web scale (Big Data) Inverted indexes (term lists) Real-time updates Compose-able queries

Page 19: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 19 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 19 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Architecture

Data model Indexing Clustering Query execution Transactions

Question

What does data model have to do with scalability?

Page 20: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Key (URI) Value (Document)

/trade/153748994 <trade> <id>8</id> <time>2012-02-20T14:00:00</time> <instrument>BYME AAA</instrument> <price cur=“usd”>600.27</price></trade>

/user/eedeebee { “name” : “Eric Bloch”, “age” : 47, “hair” : “gray”, “kids” : [ “Grace”, “Ryan”, “Owen” ]}

/book5293 It was the best of times, it was the worst of times, it was the age of wisdom, ...

/2012-02-20T14:47:53/01445 .mp3.avi[your favorite binary format]

Page 21: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 21 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 21 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Inverted Index

“which”

“uniquely”

“identify”

“each”

“uniquely identify”<article>

article/abstract/@author<product>IMS</product>

123, 127, 129, 152, 344, 791 . . .

122, 125, 126, 129, 130, 167 . . .

123, 126, 130, 142, 143, 167 . . .

123, 130, 131, 135, 162, 177 . . .

126, 130, 167, 212, 219, 377 . . .

. . .

. . .

Document References126, 130, 167, 212, 219, 377 . . .

Page 22: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 22 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 22 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Range Index

Value

Docid

0 2878 112913 531… …… …

Docid

Value

287 0531 131129 8… …… …

<trade> <trader_id>8</trader_id> <time>2012-02-20T14:00:00</time> <instrument>IBM</instrument> …</trade><trade> <trader_id>13</trader_id> <time>2012-02-20T14:30:00</time> <instrument>AAPL</instrument> …</trade><trade> <trader_id>0</trader_id> <time>2012-02-20T15:30:00</time> <instrument>GOOG</instrument> …</trade>

• Column Oriented• Memory Mapped

Rows

Page 23: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 23 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 23 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Shared-Nothing Clustering

Host D1 Host D2 Host D3 Host Dj…

Host E1

Page 24: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 24 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 24 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Query Evaluation – “Map”

Host E1 Host E2 Host E3 Host Ei

Host D1 Host D2 Host D3 Host Dj…

F1 Fn… F1 Fn… F1 Fn… F1 Fn…

Q

Q Q Q Q

Page 25: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 25 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 25 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Query Evaluation – “Reduce”

Host E1 Host E2 Host E3 Host Ei

Host D1 Host D2 Host D3 Host Dj…

F1 Fn… F1 Fn… F1 Fn… F1 Fn…

Top 10

Top 10

Top 10

Top 10

Top 10

Page 26: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 26 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 26 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Queries/Updates with MVCC

Every query has a timestamp Documents do not change

Reads are lock-free Inserts – see next slide Deletes – mark as deleted Edits –

copy edit insert the copy mark the original as deleted

Page 27: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 27 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 27 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Insert Mechanics

1) New URI+Document arrive at E-node2) URI Probe – determine whether URI exists in any

forest3) URI Lock – write locks taken on D node(s)4) Forest Assignment – URI is deterministically placed in

Forest5) Indexing6) Journaling 7) Commit – transaction complete8) Release URI Locks – D node(s) are notified to release

lock

Page 28: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 28 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 28 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Save-and-merge (Log Structured Tree Merge)

Database

Forest 1 Forest 2

S1 S2S3

S1 S2S3

S0

Insert/Update

Save

Merge

Disk

Memory

J

Journaled

Page 29: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Back to the money

Page 30: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 30 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 30 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Trades and Positions

1 million trades per day followed by 1 million position reports at end of day

Roll up trades of the current “date” for each “book:instrument” pair

Group-by, with key = “book:date:instrument”

Day1

Day2

1M trades1M positions

Day3

Day4

Day5

. . .

Page 31: Achieving  100,000 Transactions Per Second  with a NoSQL Database
Page 32: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 32 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 32 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Naive Query Pseudocode

for each book for each instrument in that book position = position(yesterday, book, instrument) for each trade of that instrument in this book position += trade(today, book, instrument).quantity insert(today, book, instrument, position)

Page 33: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 33 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 33 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Initial results

Single node – 19,000 inserts per second

Page 34: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 34 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 34 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Initial results with cluster

1DE 2DE 3DE0

10000

20000

30000

40000

50000

60000

70000

Report Query 2

# of nodes

doc/

sec

Page 35: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 35 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 35 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Techniques to get to 100K

Insert Query for Computing New Positions Materialized compound key, Co-Occurrence Query and

Aggregation Insert of New Positions

Batching Optimized insert mechanics

Page 36: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 36 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 36 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Materializing a compound key

<trade> <quantity2>1193.71</quantity2> <instrument>WASAX</instrument> <book>679</book> <trade-date>2011-03-13-07:00</trade-date> <settle-date>2011-03-17-07:00</settle-date></trade>

Page 37: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 37 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 37 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Materializing a compound key

<trade> <roll-up book-date-instrument=“151333445566782303”/> <quantity2>1193.71</quantity2> <instrument>WASAX</instrument> <book>679</book> <trade-date>2011-03-13-07:00</trade-date> <settle-date>2011-03-17-07:00</settle-date></trade>

Page 38: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 38 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 38 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Co-Occurrence and Distributed Aggregation

V D… …8540882

1129

… …… …… …

D V

… …… …… 854088

2… …… …

• Co-occurrences: Find pairings of range indexed values

• Aggregate on the D nodes (Map/Reduce):

Sum up the quantities above

• Similar to a Group-by, • in a column-oriented, in-memory

database

V D… …… 1129

… …… …… …

D V

… …… …15137…

… …… …

<trade> <roll-up book-date-instrument=“151373445566703”/> <quantity>8540882</quantity> <instrument>WASAX</instrument> <book>679</book> <trade-date>2011-03-13-07:00</trade-date> <settle-date>2011-03-17-07:00</settle-date></trade>

Page 39: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 39 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 39 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Initial results with new query

> 30K inserts/second on a single node

Page 40: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 40 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 40 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Co-Occurrence + Aggregate versus Naïve approach

1DE 2DE 3DE0

10000

20000

30000

40000

50000

60000

70000

Report Query 3Report Query 2

# of nodes

doc/

sec

Page 41: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 41 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 41 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Techniques

Computing Positions Materialized compound key, Co-Occurrence Query and

Aggregation Updates

Batching Optimized insert mechanics

Page 42: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 42 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 42 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Transaction Size and Throughput

1 2 4 8 16 32 100 500 1000 100000

5000

10000

15000

20000

25000

30000

35000

insert throughput

# doc inserts per transaction

#do

cs p

er s

ec.

Page 43: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 43 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 43 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Techniques

Computing Positions Materialized compound key, Co-Occurrence Query and

Aggregation Updates (Transaction)

Batching Optimized insert mechanics

Page 44: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 44 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 44 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Insert Mechanics, Again

1) New URI+Document arrive at E-node2) *URI Probe – determine whether URI exists in any forest3) *URI Lock – write locks are created4) Forest Assignment – URI is deterministically placed in Forest5) Indexing6) Journaling7) Commit – transaction complete8) *Release URI Locks – D nodes are notified to release lock

* Overhead of these operations increases with cluster size

x

Page 45: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 45 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 45 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Deterministic Placement

4) Forest Assignment – URI is deterministically placed in Forest

Hash functionURI 64-bit

numberBucketed into a Forest

Fi

• Done in C++ within server• But…• Can also be done in the client• Server allows queries to be evaluated against

only one forest…

Page 46: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 46 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 46 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Optimized Insert

D1 D2

F3 F4F1 F2

Q

EQ

Page 47: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 47 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 47 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Optimized Insert Mechanics

1) New URI+Document arrive at E-nodea) Compute Fi usingb) Ask server to evaluated the insert query only against Fi

2) URI Probe – Fi Only3) URI Lock – Fi Only4) Forest Assignment – Fi Only5) Indexing6) Journaling7) Commit – transaction complete8) Lock Release - Fi Only

Page 48: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 48 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 48 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Regular Insert Vs. Optimized Insert

1DE 2DE 3DE0

10000

20000

30000

40000

50000

60000

70000

regular insertin-forest-eval

# of nodes

docs

/sec

ond

In-Forest Eval

Page 49: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 49 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 49 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Tada! Achieving 100K Updates

In-Forest Eval

Page 50: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 50 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 50 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

We weren’t content with 15K

So we showed them…

100,000 INSERTS PER SECOND

A quote from the bank“We threw everything we had at MarkLogic and it didn’t break a

sweat”

Page 51: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Enterprise-grade NoSQL document-oriented database

with real-time full-text search and transactions

Doing 100K transactions per second

Page 52: Achieving  100,000 Transactions Per Second  with a NoSQL Database

Slide 52 Copyright © 2012 MarkLogic® Corporation. All rights reserved.Slide 52 Copyright © 2012 MarkLogic® Corporation. All rights reserved.

Thank You!@eedeebeehttp://[email protected]