falcon storage engine designed for speed presentation

43
MySQL Users' Conference April 2009 Falcon - built for speed Ann Harrison Kevin Lewis

Upload: elliando-dias

Post on 15-May-2015

768 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Falcon Storage Engine   Designed For Speed Presentation

MySQL Users' Conference April 2009

Falcon - built for speed

Ann HarrisonKevin Lewis

Page 2: Falcon Storage Engine   Designed For Speed Presentation

If it's so fast, why isn't it done yet?

Page 3: Falcon Storage Engine   Designed For Speed Presentation

Talk overviewFalcon at a glanceProject historyMulti-threading for the database developerCycle locking

Page 4: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – read first record

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 5: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – read complete

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 6: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – read again

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 7: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – write new record

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 8: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – commit

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 9: Falcon Storage Engine   Designed For Speed Presentation

Falcon at a glance – write complete

Serial LogFiles Database

Tablespaces

Serial Log

Windows Page Cache

Record CacheMySQL Server

Page 10: Falcon Storage Engine   Designed For Speed Presentation

Falcon historyOrigin

Transactional SQL Engine for Web App EnvironmentBought by MySQL in 2006

MVCCConsistent ReadVerisons control write accessMemory only – no steal

Indexes and data separateData encoded on disk and in memoryFine grained multi-threading

Page 11: Falcon Storage Engine   Designed For Speed Presentation

Falcon Goals circa 2006

Exploit large memory for more than just a bigger cacheUse threads and processors for data migrationEliminate tradeoffs, minimize tuningScale gracefully to very heavy loadsSupport web applications

Page 12: Falcon Storage Engine   Designed For Speed Presentation

Web application characteristicsLarge archive of dataSmaller active set High read:write ratioUneven, bursty activity

Page 13: Falcon Storage Engine   Designed For Speed Presentation

What we did instead

Enforce limit on record cache sizeRespond to simple atypical loads

Autocommit single record accessRepeat “insert ... select”Single pass read of large data set

Challenge InnoDB on DBT2Large working setContinuous heavy load

Hired the world's most vicious test designer

Page 14: Falcon Storage Engine   Designed For Speed Presentation

Record CacheRecord Cache contains:

Committed records with no versions

Page 15: Falcon Storage Engine   Designed For Speed Presentation

Record CacheRecord Cache contains:

Committed records with no versions

New, uncommitted records

Page 16: Falcon Storage Engine   Designed For Speed Presentation

Record Cache Record Cache contains:

Committed records with no versions

New, uncommitted records

Records with multiple versions

Page 17: Falcon Storage Engine   Designed For Speed Presentation

Record Cache cleanup – step 1Cleanup old committed single version recordsScavengerRuns on schedule or demandRemoves oldest mature recordsSettable limits – start and stop

Page 18: Falcon Storage Engine   Designed For Speed Presentation

Record Cache Cleanup – step 2Clean out record versions too oldto be useful

PruneRemove old, unneeded versions

Page 19: Falcon Storage Engine   Designed For Speed Presentation

Record Cache Cleanup – step 3

Clean up a cache full of new records

ChillCopy new record data to logDone by transaction threadSettable start size

Page 20: Falcon Storage Engine   Designed For Speed Presentation

Record Cache Cleanup – step 4Clean up multiple versions of asingle record created by a singletransaction

Remove intermediate versionsCreated by a single transactionRolled back to save pointRepeated updates

Page 21: Falcon Storage Engine   Designed For Speed Presentation

Record Cache Cleanup – step 5Clean up records with multipleversions, still potentially visibleBacklog

Copy entire record tree to diskExpensiveNot yet working

Page 22: Falcon Storage Engine   Designed For Speed Presentation

Simple, atypical loadsChallenge:

Autocommit single record accessRecord cache is uselessRecord encoding is uselessTransaction creation / destruction is too expensive

Response:Reuse read only transactions

Result:Multi-threaded bookkeeping nightmare

Page 23: Falcon Storage Engine   Designed For Speed Presentation

Simple, atypical loadsChallenge:

Repeat “insert ... select...”

Fill cache with old and new records

Page 24: Falcon Storage Engine   Designed For Speed Presentation

Simple, atypical loadsChallenge:

Repeat “insert ... select...”

Fill cache with old and new records

First solutionScavenge old recordsChill new record data

Page 25: Falcon Storage Engine   Designed For Speed Presentation

Simple, atypical loadsChallenge:

Repeat “insert ... select...”Fill cache with old and new records First solution

Scavenge old recordsChill new records

Second solutionMove the records headers outAlso helps index creation

Page 26: Falcon Storage Engine   Designed For Speed Presentation

Simple, atypical loads

Single pass read of large data setRead more records than Read them over and overCaches are uselessEncoding is overhead

Response:Make encoding optional?

Page 27: Falcon Storage Engine   Designed For Speed Presentation

Challenge InnoDB on DBT2Initial results were not encouraging (2007)

0

5000

10000

15000

20000

25000

30000

10 20 50 100 150 200

Connections

Tran

sact

ions

Falcon2007InnoDB2007

Page 28: Falcon Storage Engine   Designed For Speed Presentation

Challenge InnoDB on DBT2But Falcon has improved a lot since April 2007

0

5000

10000

15000

20000

25000

30000

10 20 50 100 150 200

Connections

Tran

sact

ions

Falcon2007InnoDB2007Falcon2009

Page 29: Falcon Storage Engine   Designed For Speed Presentation

Challenge InnoDB on DBT2So did InnoDB

0

5000

10000

15000

20000

25000

30000

10 20 50 100 150 200

Connections

Tran

sact

ions Falcon2007

InnoDB2007Falcon2009InnoDB2009

Page 30: Falcon Storage Engine   Designed For Speed Presentation

Bug trends

Page 31: Falcon Storage Engine   Designed For Speed Presentation

Multi-threadingDatabases are a natural fit for multi-threading

ConnectionsGophersScavengerDisk reader/writer

Except for shared structuresLocking blocks parallel operations

Challenge – sharing without locking

Page 32: Falcon Storage Engine   Designed For Speed Presentation

Multi-threadingNon-locking operation

Purge old record versions

Page 33: Falcon Storage Engine   Designed For Speed Presentation

Multi-threadingNon-locking operation

Purge old record versions

Page 34: Falcon Storage Engine   Designed For Speed Presentation

Multi-threadingLocking operation

Remove intermediate versions

Page 35: Falcon Storage Engine   Designed For Speed Presentation

Multi-threadingLocking operation

Remove intermediate versions

What granularity of lock?

Page 36: Falcon Storage Engine   Designed For Speed Presentation

Multi-threading – Lock granularity

One per record: Too many interlocked instructions

One per record group:Thread reading one record prevents scavenge of another

No answer is right – more options?

Page 37: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – read record chainBefore starting to read a record chain, get a shared lock on a “cycle”

Transaction A Transaction BTransaction C

Cycle 1 = 3shared

Cycle 2inactive

Page 38: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – clean a record chainBefore starting to read a record chain, get a shared lock on a “cycle”

Transaction A active in Cycle 1 Transaction B active in Cycle 1Transaction C active in Cycle 1Scavenger unlinks versionsfrom record chain and links themto a “to be deleted” list.

Cycle 1 = 4shared

Cycle 2 inactive

Page 39: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – records relinked

Transaction A releases lockTransaction B releases lockTransaction C still activeScavenger releases lock

Cycle 1 = 1shared

Cycle 2 inactive

Page 40: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – swap cyclesNew access locks cycle 2

Transaction C holds Cycle 1 lockCycle Manager requests exclusive on Cycle 1 (pumps cycle)Transaction A acquires Cycle 2 lock

Cycle 1 = 1 shared

Cycle 2 = 1 shared

Page 41: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – cleanup phase

Transaction C releases lockTransaction B acquires Cycle 2 lockCycle manager exclusive Cycle 1

Cycle 1 = 0 shared

exclusive

Cycle 2 = 2 shared

Page 42: Falcon Storage Engine   Designed For Speed Presentation

Cycle locking – cleanup complete

Transaction C acquires Cycle 2 lockCycle manager exclusive Cycle 1Remove unlinked, unloved, oldversions When cleanup is done, Cyclemanager releases cycle 1

Cycle 1 exclusive

Cycle 2 = 2 shared

Page 43: Falcon Storage Engine   Designed For Speed Presentation

Questions