2
$\begingroup$

I am currently getting really confused of two documents I read:

one is from Wikipedia that states:

The opposite is sequential access, where a remote element takes longer time to access.

and this Microsoft's document says:

Accessing data sequentially is much faster than accessing it randomly because of the way in which the disk hardware works.

I found the two documents contradicting with each other. Maybe they refer to different things. But I would like to know why sequential access is much faster than random access (I don't understand the Microsoft document as I don't understand the concept of seek operation)

$\endgroup$

1 Answer 1

6
$\begingroup$

They are talking about two different things.

One is about a medium that supports sequential access versus random access. The other is about reading data that is arranged sequentially or spread out requiring random access for each chunk.

Imagine a deck of cards. If you had it in a stack, and I said to get the 39th card in the stack, you could take cards off the stack one at a time until you got to the 39th card. You need to skip past 38 cards to get to the 39th. Therefore, getting the 39th card is harder than getting the 3rd. This is like a sequential access medium.

Alternatively, let's say you spread out the cards around you in a circle in order. Now it takes just as much time for you to get any card as any other since you just reach in the appropriate direction. This is like a random access medium.

Sticking with the circle, let's say I asked for cards 1, 17, and 42. You can do this pretty quickly, but if I had asked for cards 1, 2, and 3, you could probably do it much more quickly since once you got the first card, you could just scoop up the next two cards all at once. This is the difference between reading sequentially organized data versus randomly organized data. Sequentially reading sequentially organized data is very easy with the stack organization of the deck too once you find the first card.

A seek operation is moving the reading head of the hard drive to a particular location. Once there the hard drive can (very) quickly read a sequential run of data. If all your data is all in a sequential run, then it can be read very quickly once the hard drive seeks to the beginning. If the data is spread all over the hard drive, then it has to seek after each portion, and while it's seeking it's not reading so you are wasting time.

In practice, hard drives (including solid state drives which don't have to "seek") assume that you probably want a bunch of data when you tell it to seek somewhere, so they just read in a bunch of data even if you haven't (yet) asked for it in the hope that you will ask for it in the near future. Other than needing space to store this pre-fetched data, there's no reason not to do this as it's essentially free. The read head is already there. This makes sequentially organized data perform even better and randomly organized data even more wasteful. Similar to this is the fact that there is usually a minimum "block" size of data that you can read and write at a time, and so you are going to get at least a block's worth of data no matter what. Sequentially organized data will fully utilize these blocks (until the last one perhaps). Randomly organized data may or may not depending on whether the "chunks" match some multiple of the block size.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.