I am working on a native C ++ / Win32 / MFC application on Windows 7. I use CFile to open a file stored on a remote server (with flags, CFile :: modeRead | CFile :: shareDenyWrite). The server is running Windows Server 2008, and I am accessing the file on the shared drive using regular Windows file sharing. As soon as I open the file, I read it as described below.
Firstly, I am looking for several locations in the file (10 places) and reading small (128 bytes) sections. Then I look for the beginning and reading sequentially throughout the file.
What I noticed is that doing the above was much slower than just opening the file and reading through it. The initial random search and selection is very fast, almost instantaneous even with a large file. Interestingly, although this is fast, the next part, scanning through a file is very slow compared to simply scanning through it without initial random access.
In an attempt to find out what was going on, I stopped the performance monitor and looked at the network traffic. If I just browse the file sequentially, I get a download of 3.5 MB / s via the wireless adapter. If I first randomly search and then read sequentially, I get only 300 kB / s during sequential read.
The solution was to close and reopen the file after completing the random access part. When I did this, sequential reading accelerated.
So it seems that random access reading (searching and reading) was doing something on the server, and then sequential reading was slow. I am wondering if anyone knows for sure what is happening here and what is the actual reason for the behavior that I see? Although I have a fix, I would like to better understand what is happening under the hood in order to trigger this.
source
share