in reply to Reading files too slow

The first read probably does 2 disk seeks (one to find out where the file is, one to red the file). The time for a disk seek is set by the rotation speed of your hard drive.

When it does the first read it caches more of the file "just in case". So when you read the rest you're reading from cache, which is fast.

Replies are listed 'Best First'.
Re^2: Reading files too slow
by matze77 (Friar) on Jan 14, 2009 at 14:34 UTC

    Beside the programming issues: Modern OS and Hardware tries to guess what "might come next" so i also think the 2nd read is from cache also keep in mind that depending on the "clustersize" (i hope i got the right word cmiiw) of your filesystem there might also be already more read than just the very small portion of the file you might access (512 Byte is the minimum which is adressed by harddisk), maybe tuning your filesystem could also help.
    Last but not least faster hardware could be an option: software raid is, surprisingly performance related not far behind (on modern systems) hardware-raid if you could spend the money, i/o is in most cases the bottleneck. I also wonder if one could hold some of the files (maybe the often accessed) in a ram-disk, but i got no experience if this is possible ...

    hth MH