Announcements: -------------------- Grading will take some time!!! Lecture 18 ------------------------- 1. Intro to part 3 of class Disk access -> final frontier Hard disk access is very slow compared to memory access. 2. Disk access overview https://www.youtube.com/watch?v=wI0upu9eVcw https://www.youtube.com/watch?v=kdmLvl1n82U https://www.youtube.com/watch?v=p-JJp-oLx58 Terms: ---------- Cylinder Disk/Platter Surfaces Tracks Sectors Cluster -> Block -> Page [8K] ------------------- Fast HD: 3.5 Inch – Seagate BarraCuda Pro β€˜ST12000DM0007’ 12TB RPM: 7200 Read and Write Speed: 243 MB/s, 236 MB/s 512 bytes/sector 8 platters Magnetic disk access [Random I/O]: Seek time + rotational latency + transfer time Seek time >> rotational latency >> transfer time Cost to read 1 disk page ------------------------ 3. Disk read cost: Sequential vs. Random I/O Sequential I/O [Reading X pages with a single seek]: Seek time + rotational latency + X * transfer time/page Random I/O of X page (each page requires a seek): X * (Seek time + rotational latency + transfer time) Random I/O is much much slower than sequential I/O for magnetic disks......... ------------ - Faster and faster disks: SSD (less difference between sequential and random I/O) - Slower and slower data access too: Virtualization ---------------------- 4. Disk speed comparisons ioping us, usec microseconds (a millionth of a second, 1 / 1 000 000) ms, msec milliseconds (a thousandth of a second, 1 / 1 000) --------------------------- 5. RAID: Redundant arrays of inexpensive disks 4 disks: RAID - 0: Disk 1: 1 5 9 .. Disk 2: 2 6 10 .. Disk 3: 3 7 11 Disk 4: 4 8 12 Read pages 1-4: Reads/writes are faster, no redundancy RAID - 1: Mirror data Disk 1: 1 2 3 ... Disk 2: 1 2 3 ... 1/2 space is used Reads are 2x faster Writes are slightly slower than a single disk Redundancy: even if one disk fails, no data is lost RAID - 4: Disk 1: 1 5 9 .. Disk 2: 2 6 10 .. Disk 3: 3 7 11 Disk 4: 4 8 12 Disk 5: parity(pages 1,2,3,4) parity(pages 5,6,7,8), parity (9,10,11,12) Page 1 1 0 1 1 1 0 1 0 Page 2 0 1 0 1 1 0 0 1 Page 3 0 1 1 0 0 1 1 0 Page 4 0 0 1 0 1 0 0 1 Parity 1 0 1 0 1 1 0 0 ----------------- Reads as fast as RAID-0 Writes are complex: each write must update the parity disk Page 4 0 0 1 0 1 0 0 1 Page 4' 0 1 1 0 1 1 0 1 Parity 1 1 1 0 1 0 0 0 If one disk fails, I can still read/write the data without any loss! Page 1 1 0 1 1 1 0 1 0 Page 2 0 1 0 1 1 0 0 1 ----- 0 1 1 0 0 1 1 0 --> construct from other disks Page 4 0 0 1 0 1 0 0 1 Parity 1 0 1 0 1 1 0 0 Reads are slower during recovery RAID-5: Striping the parity block --------- Disk 1: 1 p 9 13 Disk 2: 2 5 p 14 Disk 3: 3 6 10 p Disk 4: 4 7 11 15 Disk 5: p 8 12 16 Parity disk is not a bottleneck, writes are faster, reads are still as fast as RAID-4 RAID-6: Hamming code using 2-bit parity that can recover from 2 disk failures ------------------ Data page // Data block: smallest unit of data that I can read/write to a disk: 8KB 6. Relation storage on disk SELECT relname, relpages FROM pg_class pc, pg_user pu WHERE pc.relowner = pu.usesysid and pu.usename = user ORDER BY relpages desc; --- 1. Disk access is slow 2. All data may not fit in memory 3. Optimize number of disk pages read/written for each query -> Query Cost: number of disk pages read/written