Blocking
Fakultas Informatika ITTelkom 2010
Context
Query Optimizationand Execution
Relational Operators
www.ittelkom.ac.id
Files and Access Methods
Buffer Management
Disk Space Management
DB
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
Context
Query Optimizationand Execution
Relational Operators
www.ittelkom.ac.id
Files and Access Methods
Buffer Management
Disk Space Management
DB
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
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.
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
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
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
Fixed Blocking (Fixed-Length Records)
www.ittelkom.ac.id
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
Variable Blocking- Spanned -
VariableVariable--length records, spannedlength records, spanned
www.ittelkom.ac.id
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)
Variable Blocking - Unspanned -
VariableVariable--length records , length records , unspannedunspanned
www.ittelkom.ac.id
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)
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
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
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
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
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
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))
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
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
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
www.ittelkom.ac.id
www.ittelkom.ac.id
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
www.ittelkom.ac.id
www.ittelkom.ac.id
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
www.ittelkom.ac.id
www.ittelkom.ac.id
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
???
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
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
Latihan Soal
Bagaimana jika kasus di atas digunakan :- Metoda variable Unspanned- Metoda Spanned blocking
www.ittelkom.ac.id
Kerjakan sebagai Latihan Soal
TERIMA KASIH
www.ittelkom.ac.id
TERIMA KASIH
Recommended