473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

C# strange cache behaviour

Gwl
I made some test to mesure the c# read perfomance on binary file and I
made some curious discovery. Except for some minor details, the
following is the code I used to read the file:

byte[] buffer = new byte[bufferSize];
FileStream fileStream = new FileStream(fileName,
FileMode.Open,
FileAccess.Read, FileShare.None, fileStreamBufferSize,
fileOptions);
BinaryReader stream = new BinaryReader(fileStream);
int itemRead;
while (true)
{
itemRead = stream.Read(buffer, 0, bufferSize);
if (itemRead == 0) //end of file
break;
}

The interesting things happen playing with the fileOptions parameter.
Its type is an enumeration and twos of the admitted value are:

* FileOptions.SequentialScan
* FileOptions.None

I ran the above code consecutively 8 times on a 100MB files varying
fileOptions value. Here it is the results according the FileOptions
value:

1 FileOptions.SequentialScan: 20.05 MB/Sec
2 FileOptions.SequentialScan: 20.25 MB/Sec
3 FileOptions.SequentialScan: 20.40 MB/Sec
4 FileOptions.SequentialScan: 20.39 MB/Sec
5 FileOptions.None: 16.55 MB/Sec
6 FileOptions.None: 704.23 MB/Sec
7 FileOptions.SequentialScan: 680.27 MB/Sec
8 FileOptions.SequentialScan: 694.44 MB/Sec

I expected to see the cache effect show up starting from the second
read but this does not happen until sixth read. I repeated the test
many times and the system cache never (with the exception I will
discuss further) start to cache at first read. In my tests caching
starts only when I open the file using FileOptions.None. After that
moment all further read take advantage of the cache system. Any idea
what's happening? I made some more test and collect them here:
http://www.dragoncello.com/blog/

g.

May 1 '07 #1
0 1174

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Torsten Reiners | last post by:
Hi, it might be a simple solution but I do not see it. The problem is that I have the following file stored on my local harddrive. All references are URL to a remote computer. It is working,...
0
by: Neil Kimber | last post by:
Hi, I'm using the Cache object to persist some values between pages. I'm setting the expiration for 2 minutes. I'm actually storing Bitmap streams in the cache. In this way, one page can draw an...
1
by: Mike Trebilcock | last post by:
I have a web app that builds a tree from a database. The tree is built on demand when the user POSTs the page back to the sever. The server maintains a copy of the current tree in a session...
3
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
2
by: Darren Newton | last post by:
Last month we upgraded our production server from .net 1.1 to 2.0. We have seen some odd behaviour that we do not know how to fix. It seems that Cache is reset or cleared. We have 2 or 3 global...
5
by: BLUE | last post by:
I insert a string in cache in a property set and I retrieve that string in the get. I retrieve my string with Read web method and I insert it with Write web method: to try cache I do Read,...
8
by: anukedari | last post by:
Hi, Could any boby please help to get the answers for the following questions: Is Apache always sends "X-Cache:MISS" header even when caching is off (disable)? or Can we say that cache...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
1
by: =?ISO-8859-1?Q?Jo=E3o_Maia?= | last post by:
Hello there, I'm using Cache VaryByParam on a page and I'm not getting the behaviour I expected. Here's what happens: - I have page a.aspx declared with Cache VaryByParam="name" - Page a.aspx...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.