size of buffer and disk access times

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

size of buffer and disk access times

Post by newmember »

lets say i have a records about 4kb long but i need to read only specific field 30 bytes long.

Will i gain any perfomance/speed if i read ONLY 30 bytes and not the whole record?

I'm asking this because i read somewhere that filesystem retrieves data in chunks of 4kb(depending on allocation unit) and even if i read only single byte it is the same as read the whole chunk.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's highly dependant on how the file system does what it does. So unless we know the specifics of the file system you are concerned against, there's not much we can say. Some systems will read and keep the chunk in memory, copying out the bits being wished to read. Others will just read the part you want, throwing the rest back.

The block size varies wildly as well.. Plus there are things like page faults, cache misses, seek times and butterfly accesses to deal with.. so, my suggestion is don't worry about it as the file system is usually pretty solid.

If you are opening and closing a file all the time, you may want to make the file span all the accesses needed. Seeking in files can be slow.. loading the file into memory and parsing it is almost always faster..
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

I agree with everything Feyd said ... except:
feyd wrote:so, my suggestion is don't worry about it as the file system is usually pretty solid.
Working mostly with shared servers I find the file system the biggest bottleneck. Maybe that would be what Feyd meant by "usually" though. I wouldn't worry so much about how you read the data but how you handle it as Feyd suggested.
Post Reply