title: performance when accessing a file on a network server sequentially after having accessed it randomly
body: <p>I'm working on a native C++/Win32/MFC app on Windows 7.  I'm using CFile to open a file stored on a remote server (with the flags, CFile::modeRead | CFile::shareDenyWrite).  The server is running Windows Server 2008 and I'm accessing the file on a shared drive via regular windows file sharing.  Once I open the file, I'm reading it as described below.</p>
  
  <p>First, I'm seeking to multiple locations in the file (10 locations) and reading small (128 byte) sections.  Then, I'm seeking to the beginning and reading sequentially through the entire file.</p>
  
  <p>What I noticed is that doing the above was MUCH slower than just opening the file and reading through it.  The initial random seeks and sampling is very quick, almost instant even with a large file.  What's interesting is that even though this is quick, the next part, scanning through the file is very slow when compared with just scanning through it without the initial random access.</p>
  
  <p>In trying to figure out what was going on I pulled up performance monitor and watched the network traffic.  If I just do the sequential read through the file, I'm getting 3.5MB/s download over the wireless adapter.  If I first randomly seek around, then sequentially read through I'm only getting 300kB/s during the sequential read.</p>
  
  <p>The solution was to close and re-open the file after doing the random access part.  When I did this, the sequential read sped right up.</p>
  
  <p>So it seems that doing the random access reads (the seek and read) did something on the server which then caused the sequential read to be slow.  I'm wondering, does anyone know for sure whats going on here and what the actual cause is of the behavior I'm seeing?  Although I have a fix for it I'd like to better understand what's going on under the hood to cause this.</p>