12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

288 Chap. 8 File Processing <strong>and</strong> External SortingHow much time is required <strong>to</strong> read the track? On average, it will requirehalf a rotation <strong>to</strong> bring the first sec<strong>to</strong>r of the track under the I/O head, <strong>and</strong>then one complete rotation <strong>to</strong> read the track.How long will it take <strong>to</strong> read a file of 1MB divided in<strong>to</strong> 2048 sec<strong>to</strong>rsized(512 byte) records? This file will be s<strong>to</strong>red in 256 clusters, becauseeach cluster holds 8 sec<strong>to</strong>rs. The answer <strong>to</strong> the question depends in largemeasure on how the file is s<strong>to</strong>red on the disk, that is, whether it is all <strong>to</strong>getheror broken in<strong>to</strong> multiple extents. We will calculate both cases <strong>to</strong> seehow much difference this makes.If the file is s<strong>to</strong>red so as <strong>to</strong> fill all of the sec<strong>to</strong>rs of eight adjacent tracks,then the cost <strong>to</strong> read the first sec<strong>to</strong>r will be the time <strong>to</strong> seek <strong>to</strong> the first track(assuming this requires a r<strong>and</strong>om seek), then a wait for the initial rotationaldelay, <strong>and</strong> then the time <strong>to</strong> read. This requires9.5 + 11.1 × 1.5 = 26.2 ms.At this point, because we assume that the next seven tracks require only atrack-<strong>to</strong>-track seek because they are adjacent, each requiresThe <strong>to</strong>tal time required is therefore2.2 + 11.1 × 1.5 = 18.9 ms.26.2ms + 7 × 18.9ms = 158.5ms.If the file’s clusters are spread r<strong>and</strong>omly across the disk, then we mustperform a seek for each cluster, followed by the time for rotational delay.Once the first sec<strong>to</strong>r of the cluster comes under the I/O head, very little timeis needed <strong>to</strong> read the cluster because only 8/256 of the track needs <strong>to</strong> rotateunder the head, for a <strong>to</strong>tal time of about 5.9 ms for latency <strong>and</strong> read time.Thus, the <strong>to</strong>tal time required is about256(9.5 + 5.9) ≈ 3942msor close <strong>to</strong> 4 seconds. This is much longer than the time required when thefile is all <strong>to</strong>gether on disk!This example illustrates why it is important <strong>to</strong> keep disk files from becomingfragmented, <strong>and</strong> why so-called “disk defragmenters” can speed upfile processing time. File fragmentation happens most commonly when thedisk is nearly full <strong>and</strong> the file manager must search for free space whenevera file is created or changed.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!