Top Banner
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Using SQL and PLSQL for Mid-Tier Database Caching Doug Hood @ScalableDBDoug Consulting Member of Technical Staff Product Manager TimesTen In-Memory Database May 16, 2019
43

Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Oct 10, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|

UsingSQLandPLSQLforMid-TierDatabaseCaching

DougHood@ScalableDBDougConsultingMemberofTechnicalStaffProductManagerTimesTen In-MemoryDatabaseMay16,2019

Page 2: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Agenda

BusinessProblem

DevOpschallenge

Architecturesandtechnicalchallenges

Howtodoit

Demo,summaryandQ&A

2

1

2

3

4

5

Page 3: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Latency,ThroughputandScalabilityLatency Howquicklycanoneoperationcomplete

Onesprinterin9.58 seconds~40km/hfor100M[2009]

Throughput Howquicklycanmanyoperationscomplete

Tensprintersinunder11seconds~40km/hfor100m[2009]

Scalability Byaddingmoreresourcescanthroughput keepincreasing

33carson2.5mileovaltrack~250km/hfor804km[Indy500,2017]

Confidential– OracleInternal/Restricted/HighlyRestricted 3

Page 4: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

LowerLatencywithTimesTen Cache

Confidential– OracleInternal/Restricted/HighlyRestricted 4

Oracle11.2.0.4RACRACnodeswereOracleSunX7-2LNVMe StorageOver50MillionUsers

LatencyisinMicroSeconds…

ApplicationTierDatabaseCache(TimesTen)RanonthesamenodesastheproductionRAC5tablejoinsfor100sofmillionsofrowsofdata

Query Oracle Cache

Q1 43 3

Q2 69 6

Q3 105 8

Q4 121 20

Q5 140 18

Q6 163 19

Q7 231 18

Page 5: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

WhyCacheData?

Confidential– OracleInternal/Restricted/HighlyRestricted 5

Page 6: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

WhyCacheData?

• TogetlowerlatencyforSQLstatements• Togetmorethroughput• Togetmorescalability

Confidential– OracleInternal/Restricted/HighlyRestricted 6

Page 7: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

CachingChallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 7

Page 8: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

TheBusinessProblem

• DBapps,makethemfasterandcheaper• Domorewithless

Confidential– OracleInternal/Restricted/HighlyRestricted 8

Page 9: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

TheDevOpsChallenge

• Makeitboring,nosurprises• Standardized,runinVMsorcontainers• Everything isautomated• Figureouteverythingthatcangowrongandbewellbehaved

Confidential– OracleInternal/Restricted/HighlyRestricted 9

Page 10: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

• Howmanyusers?Howmanyconcurrentusers?• HowmanyconcurrentOracleDBconnections?• HowmanyconcurrentApplicationServerconnections?• WhataboutHA?WhataboutDR?• Whataboutlatency?

Confidential– OracleInternal/Restricted/HighlyRestricted 10

Page 11: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 11

Canwedobetter?

Page 12: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 12

Connectionpool

Canwedobetter?

Page 13: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 13

Connectionpool

SharedServers(MTS)

Canwedobetter?

Page 14: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 14

Connectionpool

Canwedobetter?

Read/writecaches• Offloadwork fromOracle• Offloadconnections fromOracle

SharedServers(MTS)

Page 15: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges• Gofaster thanNoSQLsolutions&minimize thehardwarecost– Lowerlatencyatthe99th percentile

Confidential– OracleInternal/Restricted/HighlyRestricted 15

Page 16: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges• Gofaster thanNoSQLsolutions&minimize thehardwarecost– Lowerlatencyatthe99th percentile

Confidential– OracleInternal/Restricted/HighlyRestricted 16

• Simpleandscalableisgood,buthowmanymachinesdoyouneed?• Whataboutthe95th and99th percentileforlatency?• Whataboutcachemisses?• Howisthecachekeptuptodate?

99th percentilelatencycanbeashighas324ms…

100th percentilelatencyismanyseconds,timeout>100ms

Page 17: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

YCSBWorkloadB(95%read,5%write)

Confidential– OracleInternal/Restricted/HighlyRestricted 17

Database TPS Nodes

Cassandra 221K 32

MongoDB 260K 2

CouchBase 454K 9

Redis 1M 3

VoltDB 1.5M 6

AeroSpike 1.6M 1

Page 18: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

YCSBWorkloadB(95%read,5%write)

Confidential– OracleInternal/Restricted/HighlyRestricted 18

Database TPS Nodes

Cassandra 221K 32

MongoDB 260K 2

CouchBase 454K 9

Redis 1M 3

VoltDB 1.5M 6

AeroSpike 1.6M 1

TimesTen 2.8M 1 Letstalk

Page 19: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Architecturesandtechnicalchallenges

Confidential– OracleInternal/Restricted/HighlyRestricted 19

Connectionpool

Canwedobetter?

Read/writecaches• Offloadwork fromOracle• Offloadconnections fromOracle

Page 20: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

CustomermeasuredTimesTenCachelatency

• 97%cachehitratio– 3%ofthetimethedatawasnotinthecache,soneededaroundtriptoOracle

• 99th percentilelatency=1ms

Confidential– OracleInternal/Restricted/HighlyRestricted 20

Page 21: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

CustomermeasuredTimesTenCachelatency

• 97%cachehitratio– 3%ofthetimethedatawasnotinthecache,soneededaroundtriptoOracle

• 99th percentilelatency=1ms

Confidential– OracleInternal/Restricted/HighlyRestricted 21

Percentile Latencyinms

87 0.016

98 0.125

99.7 1

99.99 8

100 423

NoSQLwas324ms

Page 22: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

CustomermeasuredTimesTenCachelatency

• 97%cachehitratio– 3%ofthetimethedatawasnotinthecache,soneededaroundtriptoOracle

• 99th percentilelatency=1ms

Confidential– OracleInternal/Restricted/HighlyRestricted 22

Percentile Latencyinms

87 0.016

98 0.125

99.7 1

99.99 8

100 423Workingtoimprovethis• Goalis<50msfor100th percentile• Alsodefinea300ms timeout

Page 23: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Improvingthe100th percentile[maxlatency]

Confidential– OracleInternal/Restricted/HighlyRestricted 23

SQLNetConnection

pool

Canwedobetter?

Read/writecaches• Offloadwork fromOracle• Offloadconnections fromOracle

TimesTenConnection

pool

Forcachemisses,createanewSQLNetconnection!

Thiscanbereallyslow…

Page 24: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Improvingthe100th percentile[maxlatency]

Confidential– OracleInternal/Restricted/HighlyRestricted 24

SQLNetConnection

pool

Canwedobetter?

Read/writecaches• Offloadwork fromOracle• Offloadconnections fromOracle

SQLNetConnection

pool

TimesTenConnection

pool

Forcachemisses,getconnectionfromTTOCICPratherthanthesharedpool

Tunethepoolfortheexpectedmin/max

Page 25: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Howisitpossible

Confidential– OracleInternal/Restricted/HighlyRestricted 25

Page 26: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Howisitpossible

• Useareallyfast In-memorySQLRDBMS

Confidential– OracleInternal/Restricted/HighlyRestricted 26

Page 27: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Howisitpossible

• Useareallyfast In-memorySQLRDBMS• UseaCacheDB thatjustrequiresconfiguration

Confidential– OracleInternal/Restricted/HighlyRestricted 27

T1

T3

T2

Page 28: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Howisitpossible

• Useareallyfast In-memorySQLRDBMS• UseaCacheDB thatjustrequiresconfiguration• Somehardwareandsoftwaretuning

Confidential– OracleInternal/Restricted/HighlyRestricted 28

T1

T3

T2

• Prepare&bindSQLstatements• Usetherelevantindexes• Dosensiblejoins• UpdatestatisticsforSQLoptimizer• CheckTimesTenSQLstatsforSQLandIObottlenecks

Page 29: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

MostWidelyUsedRelationalIn-MemoryDatabaseDeployedbyThousandsofCompanies

29

Page 30: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

RelationalDatabase– Purein-memory– ACIDcompliant– StandardSQL/PLSQL– EntiredatabaseinDRAM

PersistentandRecoverable– DatabaseandTransactionlogspersistedonlocaldiskorflashstorage

– ReplicationtostandbyandDRsystems

30

ExtremelyFast– Microsecondsresponsetime– Veryhighthroughput

HighlyAvailable– Active-Standbyandmulti-masterreplication

– Veryhighperformanceparallelreplication

– HAandDisasterRecovery

OracleTimesTenIn-MemoryDatabase

Page 31: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

LowLatency- Microseconds ResponseTimePerformance– ResponseTime

Millionthsofa

Second

Millionthsofa

Second

31

[email protected]

2socket,22cores/socket,2threads/core

TimesTen11.2.2.8.0(100Mrows,17GBdata)

1.64

5.06

0.00

1.00

2.00

3.00

4.00

5.00

6.00

SELECTQuery UPDATETransaction

Microsecond

s

Page 32: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

HLRMobileTransactionsResponseTimeResponseTimeImprovementWithTimesTenApplication-TierDatabaseCache

Intel®[email protected]/socket2hyper-threads/core32vCPU

OracleDatabaseWithTimesTenCacheOracleDatabaseWithoutTimesTenCache

Speedup

17x

10x

17x

44x

69x

31x

29x

Page 33: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

TimesTenIn-MemoryDatabasePersistenceandRecovery

• TimesTendatabasepersistencecanbeconfiguredon– Flash,SSD,harddiskstorage

• Alltransactionsareloggedandpersisted– Redo,undo,andrecovery

• DualdatabaseCheckpointfiles– Databaserestart– Databaserecoveryafterfailures

TimesTen Checkpoint

Files

TimesTen Transaction

Log Files

Page 34: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

CacheDB =OracleApplicationTierDatabaseCacheAfeatureofOracleEnterpriseEdition

34

T1

T3

T2T1

T3

T2

CacheAgent

RepAgent

Metadata• Cachegroups

Batchreadstorefreshthecache

Parallelbatchwrites

Page 35: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

FlexibleCacheGroupConfigurations

• CacheGroupdescribestheOracleDatabasetablestocache– Allorsubsetofrowsandcolumns– DefinedusingSQLCREATECACHEGROUPPremierUsersFROMOE.CUSTOMER(NAMEVARCHAR2(100)NOTNULL,ADDRVARCHAR2(100)

)WHEREOE.CUSTOMER.ORDER>500;

• CachetablesareregulartablesinTimesTen– Joins/search,insert/update/delete

ApplicationTransactions CacheGroups

AutomaticDataSynchronization

Page 36: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Page 37: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Page 38: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Page 39: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Page 40: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Page 41: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

createdynamicreadonly cachegroupmyReadCache1autorefreshmodeincrementalinterval 100millsecondsstateonfrom hr.employees (employee_id number(6)notnull,

first_name varchar2(20),last_name varchar2(25)notnull,hire_datedatenotnull,job_id varchar2(10)notnull,salary number(8,2),manager_id number(6),department_id number(4),

primarykey(employee_id)),hr.job_history (employee_idnumber(6)notnull,

start_datedatenotnull,end_datedatenotnull,job_idvarchar2(10)notnull,department_idnumber(4),

primarykey (employee_id,start_date),foreignkey (employee_id)references hr.employees(employee_id));

Page 42: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

OracleTimesTen• Onetechnology,twoproducts,threedeploymentmodes

ApplicationTierDatabaseCache

StandaloneIn-MemoryDatabaseforOLTP

andanalytics

Application

TimesTenScaleout

SingleSystemImageIn-MemoryDatabase

OracleTimesTenIn-MemoryDatabase

Application

Page 43: Using SQL and PLSQL for Mid-Tier Database Caching · 2019. 5. 20. · –Standard SQL / PLSQL –Entire database in DRAM Persistent and Recoverable –Database and Transaction logs

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Summary• CloudScaleread/writecachingwith1mslatencyat99th percentile• OracleTimesTenisfasterthananyNoSQLDB• Cachingisconfiguration,notcoding• UseTimesTen PLSQLstoredprocedurestominimizenetworkhops

• WriteTimesTenappsasifitwereanOracleDB*– SQL,JDBC,PLSQL,OCI,ODBC,ODP.Net,Pro*C,Pro*COBOL– R,Python,Node.js,Go,Ruby&PHP

Subset oftheOracleSQLandPLSQL