chapter 111 chapter 11: hardware (slides by hector garcia-molina, hector/cs245/notes.htm)

40
Chapter 11 1 Chapter 11: Hardware (Slides by Hector Garcia-Molina, http://www-db.stanford.edu/~hector/ cs245/notes.htm)

Upload: nelson-holmes

Post on 30-Dec-2015

230 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 1

Chapter 11: Hardware

(Slides by Hector Garcia-Molina,http://www-db.stanford.edu/~hector/cs245/

notes.htm)

Page 2: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 2

Outline• Hardware: Disks• Access Times• Optimizations• Other Topics:

– Storage costs– Using secondary storage– Disk failures

Page 3: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 3

The Big Picture:

DBMS

Data Storage

Page 4: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 4

P

M

TypicalComputer

SecondaryStorage

...

Page 5: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 5

ProcessorFast, slow, reduced instruction set,

with cache, pipelined…Speed: 100 500 1000 MIPS

MemoryFast, slow, non-volatile, read-only,…Access time: 10-6 10-9 sec.

1 s 1 ns

Page 6: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 6

Secondary storageMany flavors:

- Disk: Floppy (hard, soft)Removable PacksWinchesterRam disksOptical, CD-ROM…Arrays

- Tape Reel, cartridgeRobots

Page 7: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 7

Focus on: “Typical Disk”

Terms: Platter, Head, Cylinder, TrackSector (physical),Block (logical), Gap

Page 8: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 8

Top View

Page 9: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 9

“Typical” NumbersDiameter: 1 inch 15 inchesCylinders: 100 2000Surfaces: 1 (CDs) (Tracks/cyl) 2 (floppies) 30Sector Size:512B 50KCapacity: 360 KB (old floppy)

30 GB (I use)

Page 10: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 10

Disk Access Time

block xin memory

?

I wantblock X

Page 11: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 11

Time = Seek Time +Rotational Delay +Transfer Time +Other

Page 12: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 12

Rotational Delay

Head Here

Block I Want

Page 13: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 13

Average Rotational Delay

R = 1/2 revolution

“typical” R = 8.33 ms (3600 RPM)

Page 14: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 14

Transfer Rate: t

• “typical” t: 1 3 MB/second• transfer time: block size

t

Page 15: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 15

Other Delays

• CPU time to issue I/O• Contention for controller• Contention for bus, memory

“Typical” Value: 0

Page 16: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 16

• So far: Random Block Access• What about: Reading “Next” block?

Page 17: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 17

If we do things right (e.g., Double Buffer, Stagger Blocks…)

Time to get = Block Size + Negligible

block t

- skip gap

- switch track- once in a while, next cylinder

Page 18: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 18

Rule of Random I/O: ExpensiveThumb Sequential I/O: Much less• Ex: 1 KB Block

»Random I/O: 20 ms.»Sequential I/O: 1 ms.

Page 19: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 19

Cost for Writing similar to Reading

…. unless we want to verify! need to add (full) rotation + Block size

t

Page 20: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 20

• To Modify a Block?

To Modify Block:(a) Read Block(b) Modify in Memory(c) Write Block[(d) Verify?]

Page 21: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 21

Block Address:

• Physical Device• Cylinder #• Surface #• Sector

Page 22: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 22

Outline• Hardware: Disks• Access Times• Optimizations• Other Topics

– Storage Costs– Using Secondary Storage– Disk Failures

here

Page 23: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 23

Optimizations (in controller or O.S.)

• Double Buffering• Disk Scheduling Algorithms: sec.

11.5.4– e.g., elevator algorithm

Page 24: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 24

Double Buffering

Problem: Have a File» Sequence of Blocks B1, B2

Have a Program» Process B1» Process B2» Process B3

...

Page 25: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 25

Single Buffer Solution

(1) Read B1 Buffer(2) Process Data in Buffer(3) Read B2 Buffer(4) Process Data in Buffer ...

Page 26: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 26

Say P = time to process/blockR = time to read in 1 blockn = # blocks

Single buffer time = n(P+R)

Page 27: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 27

Double Buffering

Memory:

Disk: A B C D GE F

A B

done

process

AC

process

B

done

Page 28: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 28

Say P R

What is processing time?

P = Processing time/blockR = IO time/blockn = # blocks

• Double buffering time = R + nP

• Single buffering time = n(R+P)

Page 29: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 29

Block Size Selection?

• Big Block Amortize I/O Cost

• Big Block Read in more useless stuff! and takes longer to read

Unfortunately...

Page 30: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 30

Trend

• As memory prices drop, blocks get bigger ...

Trend

Page 31: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 31

Storage Cost

10-9 10-6 10-3 10-0 103

access time (sec)

1015

1013

1011

109

107

105

103

cache

electronicmain

electronicsecondary

magneticopticaldisks

tape

opticaldisks

tape

typi

cal c

apac

ity

(byt

es)

from Gray & Reuter

Page 32: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 32

Storage Cost

10-9 10-6 10-3 10-0 103

access time (sec)

104

102

100

10-2

10-4

cache

electronicmain

electronicsecondary magnetic

opticaldisks

tape

opticaldisks

tape

doll

ars/

MB

from Gray & Reuter

Page 33: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 33

Using secondary storage effectively

• Example: Sorting data on disk• Conclusion:

– I/O costs dominate– Design algorithms to reduce I/O

• Also: How big should blocks be?

Page 34: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 34

Disk Failures (Sec 11.6)

• Partial Total• Intermittent Permanent

Page 35: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 35

Coping with Disk Failures

• Detection– e.g. Checksum

• Correction Redundancy

Page 36: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 36

At what level do we cope?

• Single Disk– e.g., Error Correcting Codes

• Disk Array

Logical Physical

Page 37: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 37

Operating System e.g., Stable Storage

Logical Block Copy A Copy B

Page 38: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 38

Database System

• e.g.,

LogCurrent DB Last week’s DB

Page 39: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 39

Summary

• Secondary storage, mainly disks• I/O times• I/Os should be avoided,

especially random ones…..

Summary

Page 40: Chapter 111 Chapter 11: Hardware (Slides by Hector Garcia-Molina, hector/cs245/notes.htm)

Chapter 11 40

Outline• Hardware: Disks• Access Times• Optimizations• Other Topics

– Storage Costs– Using Secondary Storage– Disk Failures

here