Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
78
|
第
5
章
才能换出。如果页正在被其他线程使用,则不能将其换出。
如果每次换出页都刷写磁盘,则其性能可能会很差。因此某些数据库使用单独的后台进
程,该进程循环检查可能被换出的脏页,更新其磁盘上的版本。例如,PostgreSQL 中的
一个后台刷写器就是用来做这件事情的。
另一个要记住的重要属性是
持久性
:如果数据库崩溃,则所有未刷写的数据都会丢失。
为了确保所有更改都被持久化,
检查点
进程会协调刷写进程。检查点进程控制预写日志
(WAL)和页缓存,并确保两者协同工作。只有当缓存页完成刷写之后,相关操作的日志
记录才能从 WAL 中丢弃。在上述过程完成后才能将脏页换出缓存。
这意味着需要在多个目标间做一些权衡:
•
推迟刷写以减少磁盘访问次数。
•
提早刷写以让页能被快速地换出。
•
选择要换出的页,并以最优的顺序刷写。
•
将缓存大小保持在其内存范围内。
•
避免因数据没有被持久化到主存储中而丢失它们。
我们探索的几种技术可以帮助改善前三个特性,同时使我们保持在另外两个特性的范围之内。
5.1.3
在缓存中锁定页
每次读取或写入都进行磁盘 I/O 是不切实际的:并发的读取可能会请求同一页,并发的
写入也可能会修改同一页。由于 B 树越靠近顶部越“窄”,所以层次较高的节点(靠近
根的节点)在大多数读取中都会被命中。分裂与合并操作最终也会传播到较高层次的节
点。这意味着至少树的某一部分一定会受益于缓存。
我们可以“锁定”那些在近期大概率会被用到的页。在缓存中锁定页的操作称为
固定
。被固
定的页会在内存中保留更长的时间,这有助于减少磁盘访问次数并提高性能 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787111655169