Download - Ch03 Blocking

Transcript
Page 1: Ch03 Blocking

Blocking

Fakultas Informatika ITTelkom 2010

Page 2: Ch03 Blocking

Context

Query Optimizationand Execution

Relational Operators

www.ittelkom.ac.id

Files and Access Methods

Buffer Management

Disk Space Management

DB

Page 3: Ch03 Blocking

Buffer Management in a DBMS

disk page

Page Requests from Higher Levels

BUFFER POOL

www.ittelkom.ac.id

• Data must be in RAM for DBMS to operate on it!• Buffer Mgr hides the fact that not all data is in RAM

DB

MAIN MEMORY

DISK

free frame

choice of frame dictatedby replacement policy

Page 4: Ch03 Blocking

Context

Query Optimizationand Execution

Relational Operators

www.ittelkom.ac.id

Files and Access Methods

Buffer Management

Disk Space Management

DB

Page 5: Ch03 Blocking

Records and Files

• Blocks are the interface for I/O, but…• Higher levels of DBMS operate on records, and files of records.• A record is one unit of structured data

• tuple in a relation• node in a tree or index• object or other structure

www.ittelkom.ac.id

• object or other structure

• Records may be fixed length or variable length• A file is a set or records stored as a unit on disk

• a file is stored on some set of disk blocks

• A spanning file organization allows records to be split among blocks

• A non-spanning file organization requires whole records to be stored in a single block

Page 6: Ch03 Blocking

Blocking

• Blocking: storing a number of records in one block on the disk.

• Blocking factor (bfr) refers to the number of records per block.

www.ittelkom.ac.id

block. • non-spanning organization: There may be empty space

in a block if an integral number of recordsdo not fit in one block.

Page 7: Ch03 Blocking

Blocks and Pages

• A page is a unit of data transfer from the DBMS point of view

• Disk blocks are the smallest practical page size• Larger pages are also possible:

• all data on one track

www.ittelkom.ac.id

• all data on one track• all data on one cylinder• same block, same cylinder on all surfaces

• typical page size: 1-10 Kbytes• typical page transfer time (ptt): 1-10 msec

Page 8: Ch03 Blocking

Record Blocking

•• The logical unit of file is byte or record, and the The logical unit of file is byte or record, and the physical unit of file is block.physical unit of file is block.

•• Block type:Block type:•• Fixed blockingFixed blocking••

www.ittelkom.ac.id

•• Fixed blockingFixed blocking•• VariableVariable--length spanned blockinglength spanned blocking•• VariableVariable--length length unspannedunspanned blockingblocking

Page 9: Ch03 Blocking

Record Blocking

•• Choose fixed length or variable lengthChoose fixed length or variable length•• Fixed is higher efficiency of I/O transfer ,memory Fixed is higher efficiency of I/O transfer ,memory

allocation ….allocation ….•• How to choose the size of blockHow to choose the size of block

www.ittelkom.ac.id

•• How to choose the size of blockHow to choose the size of block•• Large blocking is efficiency (because of locality) for Large blocking is efficiency (because of locality) for

transfer, but needs more disktransfer, but needs more disk--cash cash

Page 10: Ch03 Blocking

Fixed Blocking (Fixed-Length Records)

www.ittelkom.ac.id

Page 11: Ch03 Blocking

Fixed Blocking (Fixed-Length Records)

• Record length <= Block size• Blocking factor Bfr =

• There is wasted blocks

R

B

www.ittelkom.ac.id

• There is wasted blocks

Page 12: Ch03 Blocking

Variable Blocking- Spanned -

VariableVariable--length records, spannedlength records, spanned

www.ittelkom.ac.id

Page 13: Ch03 Blocking

Variable Blocking- Spanned -

• Variable-length record• Record can be split if there is Gap between block• Rekord Length >= block size• There isn’t wasted block• Hard to be implemented

www.ittelkom.ac.id

• Hard to be implemented• Need more time to read records in 2 blocks• There must be a Pointer Block (P) in each block• Block efective size = B-P• Record size + marker = R + M• Bfr = (B-P) / (R+M)• If M = P then Bfr = (B-P) / (R+P)

Page 14: Ch03 Blocking

Variable Blocking - Unspanned -

VariableVariable--length records , length records , unspannedunspanned

www.ittelkom.ac.id

Page 15: Ch03 Blocking

Variable Blocking Unspanned

• Variable-length record• Record can’t be split into blocks � there is

wasted blocks• Rekord length <=block size•

www.ittelkom.ac.id

• Rekord length <=block size• Average wasted block = ½ R• There isn’t Pointer block• Block efective size = B - 1/2R• Bfr = (B-1/2R)/(R+M)

Page 16: Ch03 Blocking

Wasted space (W)

• Space that can’t store data• W depends on :

• WG : waste because there is Gap between block•

www.ittelkom.ac.id

• G

• WR : waste because of blocking

• W = WG + WR � for each record

Page 17: Ch03 Blocking

W on Fixed Blocking

• In Fixed Blocking, wasted space because blocking < R

• For each record � 0 ≤ WR < R/Bfr• Fixed Blocking is used if record size << block

capasity � W >> W

www.ittelkom.ac.id

• Fixed Blocking is used if record size << block capasity � WG >> WR

• W = WG + WR � W = WG

Page 18: Ch03 Blocking

W on Variabel Spanned

• There isn’t wasted space because of blocking• There is Record Marker (M) and pointer block (P)• WR = M + P/Bfr• W = WG + WR � G / Bfr + M + (P/Bfr)

www.ittelkom.ac.id

• W = WG + WR � G / Bfr + M + (P/Bfr)W = M + (P+G)/Bfr

• If M = P, then W = P + (P+G)/Bfr

Page 19: Ch03 Blocking

W on Variabel Unspanned

• There is wasted space and Record Marker

• WR = M + ((½ R)/Bfr)• W = WG + WR � G/Bfr + M + ((½ R)/Bfr)

www.ittelkom.ac.id

• W = WG + WR � G/Bfr + M + ((½ R)/Bfr)W = M + (1/2R + G)/Bfr

• If M = P, � P + (1/2R + G)/Bfr

Page 20: Ch03 Blocking

Spanned Vs UnspannedRecords

• When the records in a file is stored on a disk they may be placed in blocks of a fixed size. This will rarely match the record size. So a decision must be made when the record size is smaller than the block

www.ittelkom.ac.id

made when the record size is smaller than the block size and the block size is not a multiple of the record size whether to store the record all in one block and have unused space or in two different blocks.

Chapter 5 20

Page 21: Ch03 Blocking

Transfer Rate

• Transfer rate (t)• the rate at which data can be retrieved from or stored to the

disk.

• There is 2 transfer rate : • Rekord transfer time (T )

www.ittelkom.ac.id

• Rekord transfer time (TR)• Time to transfer record with length R � TR = R / t

• Block transfer time (btt)• Time to transfer B block � btt = B/t

• Bulk transfer rate• To read larger data, used bulk transfer rate (t’)• t’ = (t/2) (R/(R+W))

Page 22: Ch03 Blocking

Conclusion

•• Variable length is efficient of storage but is difficult Variable length is efficient of storage but is difficult to implementto implement..

•• VariableVariable--size or fixedsize or fixed--sizesize

variablevariable �� complexity but efficiencycomplexity but efficiency

••

www.ittelkom.ac.id

•• LargeLarge--size or smallsize or small--sizesize

largelarge �� efficiency for transferefficiency for transfer

Page 23: Ch03 Blocking

Pre-Allocation

•• Need the maximum size for the file at the time of Need the maximum size for the file at the time of creationcreation

•• Difficult to reliably estimate the maximum potential Difficult to reliably estimate the maximum potential size of the filesize of the file

www.ittelkom.ac.id

size of the filesize of the file

•• Tend to overestimated file size so as not to run Tend to overestimated file size so as not to run out of spaceout of space

Page 24: Ch03 Blocking

Methods of File Allocation (1)

•• Contiguous allocationContiguous allocation•• Single set of blocks is allocated to a file at the time Single set of blocks is allocated to a file at the time

of creationof creation•• Only a single entry in the file allocation tableOnly a single entry in the file allocation table

••

www.ittelkom.ac.id

•• Only a single entry in the file allocation tableOnly a single entry in the file allocation table•• Starting block and length of the fileStarting block and length of the file

•• External fragmentation will occurExternal fragmentation will occur

Page 25: Ch03 Blocking

www.ittelkom.ac.id

Page 26: Ch03 Blocking

www.ittelkom.ac.id

Page 27: Ch03 Blocking

Methods of File Allocation (2)

•• Chained allocationChained allocation•• Allocation on basis of individual blockAllocation on basis of individual block•• Each block contains a pointer to the next block in Each block contains a pointer to the next block in

the chainthe chain•• Only single entry in the file allocation tableOnly single entry in the file allocation table

www.ittelkom.ac.id

•• Only single entry in the file allocation tableOnly single entry in the file allocation table•• Starting block and length of fileStarting block and length of file

•• No external fragmentationNo external fragmentation•• Best for sequential filesBest for sequential files•• No accommodation of the principle of localityNo accommodation of the principle of locality

Page 28: Ch03 Blocking

www.ittelkom.ac.id

Page 29: Ch03 Blocking

www.ittelkom.ac.id

Page 30: Ch03 Blocking

Methods of File Allocation (3)

•• Indexed allocationIndexed allocation•• File allocation table contains a separate oneFile allocation table contains a separate one--

level index for each filelevel index for each file•• The index has one entry for each portion The index has one entry for each portion

www.ittelkom.ac.id

•• The index has one entry for each portion The index has one entry for each portion allocated to the fileallocated to the file

•• The file allocation table contains block number The file allocation table contains block number for the indexfor the index

Page 31: Ch03 Blocking

www.ittelkom.ac.id

Page 32: Ch03 Blocking

www.ittelkom.ac.id

Page 33: Ch03 Blocking

Exercise

Diketahui sebuah harddisk memilikikarakteristik :- seek time = 10ms- kecepatan putar disk 6000 rpm

www.ittelkom.ac.id

- kecepatan putar disk 6000 rpm- Transfer rate = 2048 byte/s- kapasitas block = 2048 byte- ukuran rekord = 250 byte- ukuran gap = 256 byte- ukuran M = P = 8 byte

Page 34: Ch03 Blocking

???

a. Blocking Factorb. Rekord Transfer Timec. Block transfer timed. Pemborosan Ruang (Waste)e.

www.ittelkom.ac.id

e. Bulk Transfer Rate

Jika metode blockingnya1. Fixed blocking2. Variable Spanned3. Varible Unspanned

Page 35: Ch03 Blocking

Pembahasan

Metode Fixed Blockinga. Blocking Factor (Bfr) = B/R = 2048/ 250 = 8b. Record Transfer Time (TR) = R/t = 250 / 2048 = 0.122 msc. Block Transfer Time (btt) = B/t = 2048 / 2048 = 1 msd.

www.ittelkom.ac.id

c. Block Transfer Time (btt) = B/t = 2048 / 2048 = 1 msd. W = WG = G/Bfr = 256 / 8 = 32 byte e. Bulk Transfer Rate

(t’) = (t/2) (R/(R+W)) = (2048/2) (250/(250+32)) = (1024) (250/282) = 1024(0.886) = 907.8 ms

Page 36: Ch03 Blocking

Latihan Soal

Bagaimana jika kasus di atas digunakan :- Metoda variable Unspanned- Metoda Spanned blocking

www.ittelkom.ac.id

Kerjakan sebagai Latihan Soal

Page 37: Ch03 Blocking

TERIMA KASIH

www.ittelkom.ac.id

TERIMA KASIH