You are on page 1of 29

Chapter 2

Blocking and Buffering

Outline
• • • • Definition of Block and Blocking Block Size Factors that affect Block Size Physical Access vs. Logical Access
– Physical Read vs. Logical Read – Physical Write vs. Logical Write

• An Illustration/ A sample Problem
Prepared by: Perla Cosme 2

Prepared by: Perla Cosme 3 . and the saving (or write) process.Blocking and Buffering Blocking and buffering are 2 (two) important concepts that play a vital role in an efficient access to a file. we shall illustrate how these two concepts affect the retrieval (or read process). These concepts go together. hand-in-hand that one cannot exists without the other. In the next succeeding slides.

Blocks and Blocking Definition: A block is the smallest unit of data that can be accessed (either read or write process) to and from a storage device. Definition: Blocking is the process of grouping the records together to form a block. Prepared by: Perla Cosme 4 .

Question: Which of the above examples best fit the definition of a block based on our course. CS 102 Prepared by: Perla Cosme 5 .Examples of a Block You can imagine a block as follows: • A piece of music on a cassette tape • A page of a document • Chunk of data which are processed as one • A packet of data sent over the internet • Several records grouped together as one • etc.

Prepared by: Perla Cosme 6 .Best Fit Definition of a Block You can imagine a block as follows: • A piece of music on a cassette tape • A page of a document • Chunk of data which are processed as one • A packet of data sent over the internet • Several records grouped together as one • etc.

. Rec #N1 Rec #N Block #1 Block #2 . Hence. Rec #1 Rec #2 Rec #3 Rec #4 .Blocks in a File For our discussion.. Block #M 7 Prepared by: Perla Cosme . we think of a block as applied in a file.. a block constitute a group of records within a file.......

Prepared by: Perla Cosme 8 .Blocks Question: How do we know the number of records within a block? Answer: It depends on the Block Size.

Prepared by: Perla Cosme 9 . then the block size is predetermined by the Operating System. Block size is determined by the programmer or if the application is highly critical such as those that are used by the embedded systems.Block Size Block Size (or block factor or blocking factor) refers to the number of records that will fit in a block.

Anything left by it is shared among but not limited to the following: buffer size. free space. • Size of the operating system The operating system uses a portion of the main memory. Prepared by: Perla Cosme 10 . etc. Any fraction thereof will be a waste of space.Factors that Affect Block Size • Size of the file The number of records (or bytes) in a file is preferred to be exactly divisible by the block size. size of the program used to access the file.

The impact. is not as great as when one uses the magnetic disks. the tape density and length determines the maximum number of records or bytes. however.Factors that Affect Block Size • Storage device used If the device used is magnetic tape. Prepared by: Perla Cosme 11 .

The very reason why we do blocking is to reduce the number of Physical Accesses. the lesser is the number of blocks accessed. 2. the longer it takes to process. In like manner. the lower the blocking factor. Hence. the higher is the number of blocks accessed. The more blocks to access. Prepared by: Perla Cosme 12 . it is less efficient. 3. The higher the blocking factor.Notes to Ponder On 1.

Logical Access • Physical Access – when you directly involve the transfer of data with a physical storage device to another physical storage device. e. • Logical access – the transfer of data is made within the same type of storage device.g.Physical vs. Prepared by: Perla Cosme 13 .

Types of Access Access Physical Logical Read Write Read Write 14 Prepared by: Perla Cosme .

Illustration of the types of Access 1 Buffer Main Memory Buffer 2 Secondary Memory Question: What kind of access is described in the numbered items? Answer it from the point of view of the main memory. Prepared by: Perla Cosme 15 4 3 .

Logical write 2. Physical write 3. Logical Read 4. Physical Read 16 Prepared by: Perla Cosme .Illustration of the types of Access 1 Buffer Main Memory Buffer Secondary Memory 2 4 3 Answer: 1.

Illustration of the types of Access 1 Buffer Main Memory Buffer 2 Secondary Memory Question: What kind of access is described in the numbered items? Answer it from the point of view of the secondary memory. Prepared by: Perla Cosme 17 4 3 .

Physical read 3. Logical write 4. Logical read 2.Illustration of the types of Access 1 Buffer Main Memory Buffer 2 Secondary Memory 4 3 Answer: 1. Physical write Prepared by: Perla Cosme 18 .

Prepared by: Perla Cosme 19 .Question In what way can blocking be helpful? Answer: Blocking reduces the number of Physical accesses.

Why do we say so? Prepared by: Perla Cosme 20 .A Follow-up Question Why are we counting on Physical Accesses instead of Logical accesses? Or can we not count them both? Answer: Because physical accesses uses more time to perform the process than when we use logical accesses.

2.A Sample Problem Illustration: If a file has N records and the block size = 2. Show the composition of a file emphasizing the blocks. then do the following: 1. 3. Prepared by: Perla Cosme 21 . Determine the number of blocks within a file. Determine the number of records within a block.

..A Sample Problem Illustration: Rec #1 Rec #2 Rec #3 Rec #4 ... Block #M Question: Given the above scenario... Rec #N-1 Rec #N Block #1 Block #2 .... how many blocks will there be in a file? Prepared by: Perla Cosme 22 .

Rec #N-1 Rec #N Block #1 Block #2 . of Blocks = N records / Block Size = N records / 2 records per block = N/2 blocks Prepared by: Perla Cosme 23 ....Block Size Illustration: Rec #1 Rec #2 Rec #3 Rec #4 . Block #M Answer: No.......

Sample Problem Suppose a master file has 1000 records where each record is 1000 bytes long. Question: How many blocks are there if the block factor is 100? Ans: 10 (how did you get it?) Prepared by: Perla Cosme 24 .

Sample Problem Suppose a master file has 1000 records with each 1000 bytes per record. Question: How many blocks are there if the block factor is 135? Answer: 8 blocks (Why?) Prepared by: Perla Cosme 25 .

Unblocked File Suppose 5000 records of 100 bytes each will be subjected to a certain maintenance process. These same set of records will be processed using File A and File B. Prepared by: Perla Cosme 26 . while File B is blocked file that uses a blocking factor of 100. File A is a unblocked file. Determine the total access time to process the 5000 records when the file is unblocked and when the file is blocked. Other information are given in the table in the next slide.An Illustration of Blocked File vs.

42 20 .) Total Access time (in sec.60 File A File B (conversion factor: 1000 ms = 1 sec) Prepared by: Perla Cosme 27 .Summary Table Criteria No.) 15 . of Blocks Record Length (in bytes) Block Length (in bytes) Time to perform I/O activities per block (in ms.) Time to perform CPU activities per block (in ms.) Total Access time (in ms. of Physical Records Blocking Factor Total No.

Summary • The total access time is lower in Blocked File. more efficient. hence. Prepared by: Perla Cosme 28 . • The efficiency of blocked file is attributed to the less number of physical accesses.

End of Blocking Prepared by: Perla Cosme 29 .