Banking Case study: Scaling with low latency using NewSQL Jags - - PowerPoint PPT Presentation

banking case study scaling with low latency using newsql
SMART_READER_LITE
LIVE PREVIEW

Banking Case study: Scaling with low latency using NewSQL Jags - - PowerPoint PPT Presentation

Banking Case study: Scaling with low latency using NewSQL Jags Ramnarayan (VMWare) Jim Bedenbaugh (VMWare) Qcon 2012 Agenda Business Requirements Operational data Analysis Problem Statement Scaling pain Introduction to SQLfire Driving


slide-1
SLIDE 1

Banking Case study: Scaling with low latency using NewSQL

Jags Ramnarayan (VMWare) Jim Bedenbaugh (VMWare) Qcon 2012

slide-2
SLIDE 2

Agenda

Business Requirements Operational data Analysis Problem Statement Scaling pain Introduction to SQLfire Driving principles in SQLFire Use cases Demo (partitioned regions, colocation, etc) Data-aware procedures concepts Consistency model Shared-nothing disk persistence

slide-3
SLIDE 3

Business Requirements: What are they after?

A large regional bank in the Northeastern U.S. Collects large amounts of operational data By region and branch Significant number of attributes associated with each transaction Drive thru or foot traffic Transaction type Product types Time of day

slide-4
SLIDE 4

Business Requirements: What are they after? (con’t)

Analysis The data is analyzed to determine the staffing requirements for each branch and region. These requirements yield guidance on: Number of staff needed Skills needed Hours of operation

slide-5
SLIDE 5

¡ ¡

“R “Righ ght n now

  • w ou
  • ur d

dat atab abas ase i is on

  • nly

ly 3 32G but... ... ¡ “W “We ar are con constan antly ly acq acquiring n g new ban anks… ¡ “A “And t this d dat atab abas ase i is gr grow

  • wing r

g rap apidly ly…” …” ¡ “A “And i it t tak akes at at le leas ast a w a week t to ge

  • get n

new resou

  • urce

ces an and t this i is ju just t too s

  • o slow

low.” .” ¡

So what seems to be the problem?

slide-6
SLIDE 6

Vertical Scaling has led to The “Jenga Architecture”

“We can only scale one way: Vertically. We want to scale horizontally but the vendor wants a pile of money to put in a new solution. When we need more resources, all we can do is jam in more memory and hang more drives off the same machine, but we’re getting at the end of that

  • road. We need another solution.”
slide-7
SLIDE 7

How did they arrive in this predicament?

Poor planning: “We just didn’t think about how this data is used or how much we would end up collecting over time.” Doing it on the cheap: “We were locked into one database vendor and the original implementation was cheap to do with their low end database.” Clustering: “Our team isn’t really all that sophisticated in doing these kinds of databases. An awful lot of our data lives on the mainframe.”

slide-8
SLIDE 8

The ¡introduc(on ¡of ¡SQLfire… ¡

slide-9
SLIDE 9

Replicated, partitioned tables in

  • memory. Redundancy through

memory copies. Data resides on disk when you explicitly say so Powerful SQL engine: standard SQL for select, DML DDL has SQLF extension Leverages GemFire data grid engine.

And how does SQLfire ease my pain?

slide-10
SLIDE 10

Scaling at the speed of thought

Consistency model is FIFO, Tunable. Distributed transactions without global locks Applications access the distributed DB using JDBC, ADO.NET

slide-11
SLIDE 11

Asynchronous replication over WAN Synchronous replication within cluster Clients failover, failback Easily integrate with existing DBs

  • caching framework to read through, write through or write

behind

Scaling at the speed of thought

slide-12
SLIDE 12

"Data aware procedures“ - standard Java stored procedures with "data aware" and parallelism extensions When nodes are added, data and behavior is rebalanced without blocking current clients

Scaling at the speed of thought

slide-13
SLIDE 13

The Partitioning Strategy: How we chose…

CREATE TABLE FLIGHTS ( FLIGHT_ID CHAR(6) NOT NULL , REGION INTEGER NOT NULL, SEGMENT_NUMBER INTEGER NOT NULL , ORIG_AIRPORT CHAR(3), DEPART_TIME TIME, … ) PARTITION BY COLUMN(REGION) REDUNDANCY 1 PERSISTENT;

slide-14
SLIDE 14

Partitioning: The Result

What it looked like: 2x48G VM with 2 processors Data Partitioned and Replicated Split: 13 million rows/ 9 million rows What happened when we added another VM Added 48g 2 processor Data rebalanced across 3 partitions: 8 million/6 million/8 million How it performed We ran side by side comparisons of and existing SQL statement. The existing server took nearly 20 minutes to complete The SQLfire version completed in under 1 minute. The benefit of partitioning is that we can go to a single partition and retrieve data instead of a table scan.

slide-15
SLIDE 15

No ¡

Hashing ¡is ¡performed ¡on ¡the ¡Java ¡ implementa(on ¡of ¡the ¡column’s ¡type. ¡

Is ¡par((oning ¡ declared? ¡ Use ¡explicit ¡direc(ves ¡

Yes ¡

Are ¡there ¡foreign ¡ ¡ keys? ¡

Yes ¡ referenced ¡table ¡ par((oned ¡on ¡the ¡foreign ¡ key? ¡ Is ¡the ¡ ¡ ¡

Colocate ¡with ¡ referenced ¡table ¡

Yes ¡ No ¡

Is ¡there ¡a ¡primary ¡ ¡ key? ¡

No ¡

Are ¡there ¡UNIQUE ¡ columns? ¡ Par((on ¡by ¡primary ¡ key ¡

Yes ¡

Par((on ¡by ¡the ¡first ¡ UNIQUE ¡column ¡

Yes ¡

Par((on ¡by ¡internally ¡ generated ¡row ¡id ¡

No ¡

If ¡no ¡PARTITION ¡BY ¡clause ¡is ¡specified, ¡GemFire ¡ SQLF ¡will ¡automaBcally ¡parBBon ¡and ¡collocate ¡ tables ¡based ¡on ¡this ¡algorithm. ¡

Start ¡

slide-16
SLIDE 16

Reac(ons ¡to ¡the ¡implementa(on ¡

The DBA’s had the Grumpy Old Man response: “Hey you kids get off my grass!”

slide-17
SLIDE 17

Reac(ons ¡to ¡the ¡implementa(on ¡

Management response: “Where do we sign?”

slide-18
SLIDE 18

Reac(ons ¡to ¡the ¡implementa(on ¡

Business response: “Where do we sign?”

slide-19
SLIDE 19

Reac(ons ¡to ¡the ¡implementa(on ¡

Developers response:

“What? We have to modify existing SQL? This just doesn’t drop in?”

slide-20
SLIDE 20

Conversion Gotchas and Tips…

  • DDL. It’s different for Derby. DB2 has all kinds of options and
  • parameters. Use a hatchet, not scissors when editing. I wrote a few

scripts to rip out a lot of the DB2 DDL. It’s just not needed. Data types: Map them before you convert the DDL. Write a script to convert them. Data conversion: SQLfire has a neat import procedure SYSCS_UTIL.IMPORT_TABLE. Use it. I always requested CSV files and split them up into chunks in case anything went wrong. Use JDBCRowloader for read misses. Comes with SQLfire. Use DDLUtils for DDL conversion. Cannot use Stored Procedures. Rewrite as Java Stored Procedure

slide-21
SLIDE 21

¡SQLFire ¡Driving ¡Principles ¡

Undifferentiat ated f feat atures i in n next ge gen d dat atab abas ases -

  • Hor
  • rizon

zontal s al scalab calabili lity, h , high gh av avai ailab labili lity NoSQ

  • SQL d

dat ata m a mod

  • dels

ls le less r rigi gid b but m mos

  • st n

now

  • w s

suppor

  • rt s

som

  • me f

for

  • rm
  • f
  • f SQ

SQL – – cq cql, u , un-ql ql, , oq

  • ql,

, etc etc SQ SQL : F : Fle lexible le, e , eas asily ly u understood

  • od, s

, stron

  • ng t

g type s system e essential f al for

  • r q

query e engi gine e effici ciency cy Focu

  • cus on
  • n com

commod

  • dity s

servers; ; Memor

  • ry d

density f follow

  • llows M

Moor

  • ore’s

’s law law Optimize ze f for

  • r m

memor

  • ry; F

; Focu

  • cus on
  • n lar

large ge N Not

  • t “Bi

“Big d g dat ata” a”

slide-22
SLIDE 22

¡SQLFire ¡Driving ¡Principles ¡

Exploi loit d dat ata af a affinity f for

  • r p

par aralle allel p l proce

  • cessing; of

g; offer n new A APIs

  • A
  • App d

develop loper i is t the n new D DBA BA Dat ata i a is f flow lowing.. W g.. Wor

  • rk w

with r rele levan ant, “N , “NOW” d ” dat ata Not

  • t J

Just H High gh A Avai ailab labili lity.. Con .. Continuou

  • us av

avai ailab labili lity Sy Synch chron

  • nou
  • us cop

copies i in p prox

  • ximity..

.. As Async ync cop copies acr acros

  • ss W

WAN Con Consistency cy s shou

  • uld

ld b be t tunab able le E Eventual con al consistency cy i is t too d

  • o difficu

cult lt f for

  • r t

the av average age d develop loper Write(A (A,2 ,2) )  R Read ad(A (A) m ) may ay r return 1 1 or

  • r (1

(1,2 ,2) )

slide-23
SLIDE 23

DESIGN ¡PATTERNS ¡

¡ ¡ ¡

slide-24
SLIDE 24

“Write ¡thru” ¡Distributed ¡caching ¡

Pre-load using DDLUtils for queries Lazily load using “RowLoader” for PK queries Configure LRU eviction or expiry for large data “Write thru” – participate in container transaction ¡

slide-25
SLIDE 25

Distributed ¡caching ¡with ¡Async ¡writes ¡to ¡DB ¡

Buffer high write rate from DB Writes can be enqueued in memory redundantly on multiple nodes Or, also be persisted to disk on each node Batches can be conflated and written to DB Pattern for “high ingest” into Data Warehouse ¡

slide-26
SLIDE 26

As ¡a ¡scalable ¡OLTP ¡data ¡store ¡

Shared nothing persistence to disk Backup and recovery No Database to configure and be throttled by ¡

slide-27
SLIDE 27

As ¡embedded, ¡clustered ¡Java ¡database ¡

Just deploy a JAR or WAR into clustered App nodes Just like H2 or Derby except data can be sync’d with DB is partitioned or replicated across the cluster ¡ Low cost and easy to manage

slide-28
SLIDE 28

To ¡process ¡app ¡behavior ¡in ¡parallel ¡

Map-reduce but based on simpler RPC

slide-29
SLIDE 29

To ¡make ¡data ¡visible ¡across ¡sites ¡in ¡real ¡(me ¡

slide-30
SLIDE 30

Demo

default partitioned tables, colocation, persistent tables

FLIGHTS

  • FLIGHT_ID CHAR(6) NOT NULL ,

SEGMENT_NUMBER INTEGER NOT NULL , ORIG_AIRPORT CHAR(3), DEPART_TIME TIME, ….. PRIMARY KEY (FLIGHT_ID, SEGMENT_NUMBER)

FLIGHTAVAILABILITY

  • FLIGHT_ID CHAR(6) NOT NULL ,

SEGMENT_NUMBER INTEGER NOT NULL , FLIGHT_DATE DATE NOT NULL , ECONOMY_SEATS_TAKEN INTEGER , ….. PRIMARY KEY ( FLIGHT_ID, SEGMENT_NUMBER, FLIGHT_DATE)) FOREIGN KEY (FLIGHT_ID, SEGMENT_NUMBER) REFERENCES FLIGHTS ( FLIGHT_ID, SEGMENT_NUMBER)

FLIGHTHISTORY

  • FLIGHT_ID CHAR(6),

SEGMENT_NUMBER INTEGER, ORIG_AIRPORT CHAR(3), DEPART_TIME TIME, DEST_AIRPORT CHAR(3), ….. 1 – M 1 – 1

SEVERAL CODE/DIMENSION TABLES

  • AIRLINES: AIRLINE INFORMATION (VERY STATIC)

COUNTRIES : LIST OF COUNTRIES SERVED BY FLIGHTS CITIES: MAPS: PHOTOS OF REGIONS SERVED

slide-31
SLIDE 31

Demo ¡– ¡Start ¡with ¡replicated ¡tables ¡ replicated ¡tables ¡

slide-32
SLIDE 32

Demo ¡– ¡Par((on ¡the ¡“fact” ¡tables ¡

slide-33
SLIDE 33

Demo ¡– ¡Add ¡a ¡new ¡server ¡and ¡rebalance ¡

slide-34
SLIDE 34

Demo ¡– ¡HA ¡

slide-35
SLIDE 35

Say, Flights and FlightAvailability both were hash partitioned on PK Select * from Flights f, FlightAvailability fa where f.flight_id = fa.flight_id and f.flight_id ='xxx‘ and fa.seats_taken > yy;

  • With Hash partitioning the join would have to execute everywhere
  • Distributed joins are expensive and inhibit scaling

– joins across distributed nodes could involve distributed locks and potentially a lot of intermediate data transfer across nodes

Linearly scaling joins

slide-36
SLIDE 36

Designer thinks about how data maps to partitions – The main idea is to:

1) minimize excessive data distribution by keeping the most frequently accessed and joined data collocated on partitions 2) Collocate transaction working set on partitions so complex 2-phase commits/paxos commit is eliminated or minimized.

Read Pat Helland’s “Life beyond Distributed Transactions” and the Google MegaStore paper

Partition Aware DB Design

slide-37
SLIDE 37

1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡

10 ¡

Collocate ¡Data ¡For ¡Fast ¡Joins. ¡

¡ ¡

CREATE ¡TABLE ¡FlightAvailability ¡ ¡ ¡ ¡ ¡ ¡(flight_id ¡.., ¡ ¡ ¡ ¡ ¡ ¡ ¡segment ¡.., ¡date ¡..) ¡ PARTITION ¡BY ¡ ¡ ¡ ¡ ¡ ¡COLUMN ¡(flight_id) ¡ ¡ ¡ ¡ ¡ ¡COLOCATE ¡WITH ¡Flights; ¡

SQLFire ¡Node ¡1 ¡

FltAvailability ¡1 ¡

SQLFire ¡Node ¡2 ¡

FltAvailability ¡2 ¡ Replica ¡ Replica ¡ Flight ¡1 ¡ Flight ¡2 ¡

SQLFire ¡can ¡join ¡ tables ¡without ¡ network ¡hops. ¡ C1 ¡ C2 ¡ Related ¡data ¡placed ¡

  • n ¡the ¡same ¡node. ¡
slide-38
SLIDE 38

¡ ¡

SQLFire ¡Node ¡1 ¡

FltAvailability ¡1 ¡

SQLFire ¡Node ¡2 ¡

FltAvailability ¡2 ¡ Replica ¡ Replica ¡ Flight ¡1 ¡ Flight ¡2 ¡

SQLFire ¡can ¡join ¡ tables ¡without ¡ network ¡hops. ¡ C1 ¡ C2 ¡ Related ¡data ¡placed ¡

  • n ¡the ¡same ¡node. ¡

Select * from Flights f, FlightAvailability fa where <equijoin clause> and f.flight_id =‘UA765';

Collocate ¡Data ¡For ¡Fast ¡Joins. ¡

Query ¡pruned ¡to ¡node ¡1 ¡

slide-39
SLIDE 39

¡ ¡

SQLFire ¡Node ¡1 ¡

FltAvailability ¡1 ¡

SQLFire ¡Node ¡2 ¡

FltAvailability ¡2 ¡ Replica ¡ Replica ¡ Flight ¡1 ¡ Flight ¡2 ¡

In ¡parallel, ¡each ¡node ¡does ¡hash ¡join, ¡aggrega[on ¡locally ¡ C1 ¡ C2 ¡ Related ¡data ¡placed ¡

  • n ¡the ¡same ¡node. ¡

SELECT sum(fa.seats_taken), f.orig_airport, fa.date FROM flights f, FltAvailability fa WHERE <equijoin> GROUP By fa.date, f.orig_airport ORDER BY fa.date, f.orig_airport DESC

Collocate ¡Data ¡For ¡Fast ¡Joins. ¡

Parallel ¡sca^er-­‑gather ¡

slide-40
SLIDE 40

Partitioning and redundancy

Redundancy = 2 (but tunable) ¡ Single owner for any row at point in time ¡ Replication can be “rack aware” ¡ Replication is synchronous but done in parallel ¡

slide-41
SLIDE 41

Data-Aware Stored Procs

  • Procedure execution routed to the data
  • Full scaled-out execution
  • Highly available
  • Use pure Java to access/store data
  • Demo later on

Like Map/Reduce But Different ¡

slide-42
SLIDE 42

1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡

10 ¡

Scaling ¡Stored ¡Procedures ¡

¡ ¡

CALL ¡maxSales(arguments) ¡ ¡ON ¡TABLE ¡sales ¡

WHERE ¡(Loca(on ¡in ¡(‘CA’,’WA’,’OR') ¡

WITH ¡RESULT ¡PROCESSOR ¡ ¡ maxSalesReducer ¡ ¡ ¡

SQLFire ¡uses ¡data-­‑ ¡ aware ¡rou[ng ¡to ¡ route ¡processing ¡to ¡ the ¡data. ¡

maxSales ¡on ¡ local ¡data ¡ maxSales ¡on ¡ local ¡data ¡ maxSalesReducer ¡

Result ¡Processors ¡ give ¡map/reduce ¡ func[onality. ¡

slide-43
SLIDE 43

Scalability: Consistency

With Transactions ¡ And Without ¡

  • Row updates always

atomic and isolated

  • FIFO consistency

¡

  • Distributed transactions

with 1-phase commit

  • Coordinator per node
  • Eager locking + Fail

fast ¡

Assumes: Most x-actions small in space and time Write-write conflicts rare

slide-44
SLIDE 44
  • Parallel log structured

storage

  • Each partition writes in

parallel

  • Backups write to disk

also

– Increase reliability against h/w loss

Scalability: High performance persistence

Memory Tables Append only Operation logs OS Buffers

LOG Compressor

Record1 Record2 Record3 Record1 Record2 Record3

Memory Tables Append only Operation logs OS Buffers

LOG Compressor

Record1 Record2 Record3 Record1 Record2 Record3
slide-45
SLIDE 45

How does it scale for queries?

N = ¡ 2 ¡ 4 ¡ 6 ¡ 8 ¡ 10 ¡ 200k ¡ 420k ¡ 604k ¡ 790k ¡ 1M ¡ Partitioned Table PK queries per second (1kb Rows) ¡ Number Of Servers ¡ # Clients = 2*N 200 ¡ 400 ¡ 600 ¡ 800 ¡ 1000 ¡

slide-46
SLIDE 46

How does it scale for updates?

N = ¡ 2 ¡ 4 ¡ 6 ¡ 8 ¡ 10 ¡ 220k ¡ 490k ¡ 750k ¡ 950k ¡ 1.3M ¡ Partitioned Table Updates Per Second (3 columns) ¡ Number Of Servers ¡ 85% < 1ms latency ¡ # Clients = 2*N 200 ¡ 400 ¡ 600 ¡ 800 ¡ 1000 ¡

slide-47
SLIDE 47

http://vmware.com/go/sqlfire

Try SQLFire Today! Free for developer (3 nodes) perpetually. ¡

Download: ¡ Forum: ¡ http://vmware.com/vmtn/appplatform/vfabric_sqlfire

Got questions? Get answers. ¡

:sigh: Just Google it ¡

Twitter: ¡ @vFabricSQLFire

Q & A