In-Memory Databases

now DRAM capacities are large enough that most databases can fit in memory. So why not just use a “traditional” diskoriented DBMS with a really large cache?
展开查看详情

1.15-721 DATABASE SYST EM S [Image Source] Lecture #02 – In-Memory Databases Andy Pavlo // Carnegie Mellon University // Spring 2016

2. 2 TO DAY ’ S AG E N DA Background In-Memory DBMS Architectures Historical Systems Peloton Overview Project #1 CMU 15-721 (Spring 2016)

3. 3 BAC KG R O U N D Much of the history of DBMSs is about avoiding the slowness of disks. Hardware was much different when the original DBMSs were designed: → Uniprocessor (single-core CPU) → RAM was severely limited. → The database had to be stored on disk. CMU 15-721 (Spring 2016)

4. 4 BAC KG R O U N D But now DRAM capacities are large enough that most databases can fit in memory. So why not just use a “traditional” disk- oriented DBMS with a really large cache? CMU 15-721 (Spring 2016)

5. 5 DISK-ORIENTED DBMS The primary storage location of the database is on non-volatile storage (e.g., HDD, SSD). → The database is organized as a set of fixed-length blocks called slotted pages. The system uses an in-memory (volatile) buffer pool to cache blocks fetched from disk. → Its job is to manage the movement of those blocks back and forth between disk and memory. CMU 15-721 (Spring 2016)

6. 6 BUFFER POOL When a query accesses a page, the DBMS checks to see if that page is already in memory: → If it’s not, then the DBMS has to retrieve it from disk and copy it into a frame in its buffer pool. → If there are no free frames, then find a page to evict. → If the page being evicted is dirty, then the DBMS has to write it back to disk. Once the page is in memory, the DBMS translates any on-disk addresses to their in- memory addresses. CMU 15-721 (Spring 2016)

7. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Table Slotted Pages CMU 15-721 (Spring 2016)

8. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

9. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

10. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

11. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

12. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

13. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page2 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

14. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

15. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page1 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

16. 7 DATA O R G A N I Z AT I O N Index Buffer Pool Database (On-Disk) page6 page0 page1 page1 page4 page2 Page Id + Slot # Page Table Slotted Pages CMU 15-721 (Spring 2016)

17. 8 S LOT T E D PAG E S header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 CMU 15-721 (Spring 2016)

18. 8 S LOT T E D PAG E S header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 CMU 15-721 (Spring 2016)

19. 8 S LOT T E D PAG E S header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

20. 8 S LOT T E D PAG E S Variable-length Data header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

21. 8 S LOT T E D PAG E S Variable-length Data header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

22. 8 S LOT T E D PAG E S Variable-length Data header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

23. 8 S LOT T E D PAG E S Variable-length Data header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

24. 8 S LOT T E D PAG E S Variable-length Data header blob1 blob2 blob3 · · · free space · · · tuple3 tuple2 tuple1 Fixed-length Data Slots CMU 15-721 (Spring 2016)

25. 9 BUFFER POOL Every tuple access has to go through the buffer pool manager regardless of whether that data will always be in memory. → Always have to translate a tuple’s record id to its memory location. → Worker thread has to pin pages that it needs to make sure that they are not swapped to disk. CMU 15-721 (Spring 2016)

26. 10 CO N C U R R E N C Y CO N T R O L In a disk-oriented DBMS, the systems assumes that a txn could stall at any time when it tries to access data that is not in memory. Execute other txns at the same time so that if one txn stalls then others can keep running. → Has to set locks and latches to provide ACID guarantees for txns. → Locks are stored in a separate data structure to avoid being swapped to disk. CMU 15-721 (Spring 2016)

27. 11 LO G G I N G & R E CO V E R Y Most DBMSs use STEAL + NO-FORCE buffer pool policies, so all modifications have to be flushed to the WAL before a txn can commit. Each log entry contains the before and after image of record modified. CMU 15-721 (Spring 2016)

28. 12 DISK-ORIENTED DBMS OVERHEAD Measured CPU Cycles OLTP THROUGH THE LOOKING GLASS, AND WHAT WE FOUND THERE SIGMOD, pp. 981-992, 2008. CMU 15-721 (Spring 2016)

29. 12 DISK-ORIENTED DBMS OVERHEAD Measured CPU Cycles BUFFER POOL LOCKING RECOVERY REAL WORK OLTP THROUGH THE LOOKING GLASS, AND WHAT WE FOUND THERE SIGMOD, pp. 981-992, 2008. CMU 15-721 (Spring 2016)