-
Notifications
You must be signed in to change notification settings - Fork 2
Open FileStream with FileOptions.Asynchronous when benchmarking async file I/O #1
Comments
Thank you for the feedback! I'll make the changes and update the results tonight 😄 |
👍 |
So I've re-run the benchmark, but further, I've added specifying In short specifying You can see the full report in the readme (and the changes in results in the recent commits). I'd be open to any further feedback before I closed this issue, however, it takes a decent chunk of time to interpret these results and draw conclusions; so it will take some time to run this all again. |
Hey @atruskie, I then checked the official .NET performance repo and saw that they also tested FileStream. The results are similar to what we observed (see end of this comment). What can we do to gain more insights?
Results of the official benchmark: IterationTime=250.0000 ms MaxIterationCount=20 MinIterationCount=15
|
I've tested some more, and |
So I was testing with
That paper you linked to was super interesting. I'm also glad you got similar results in your https://github.com/feO2x/InsightsOnFiles repo 😄 And thanks for tagging me in the dotnet/performance repo - that was some interesting discussion. |
Thanks for your efforts to bechmark the different methods to access the file system.
I think I found an issue with your async file stream benchmarks: when you open the file stream, you call
File.Open(File, FileMode.Open, FileAccess.Read)
. What you should do instead isnew FileStream(File, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.Asynchronous)
. The important part is the last parameter: on Windows, this instructs the file system to allow asynchronous operations with the disk controller. If this is not set, then the asynchronous operation is actually performed on another CLR thread-pool thread (and this thread sleeps while the disk's controller is retrieving the data). I suspect that this is the reason why your async file benchmark methods are slower than the synchronous ones. I would actually expect them to be as fast as the synchronous ones.Unfortunately, asynchronous file access is turned off by default, you have to explicitly enable it by setting
FileOptions.Asynchronous
orisAsync: true
when creating a file stream. Furthermore, I don't know how this behaves on operating systems other than Windows.By the way, the 4096 is the file stream's internal buffer size, this is the default value set by Microsoft. You could also change this and measure how it affects the file load speed. I suspect that larger buffers will lead to lower loading times, but remember that arrays with a size larger than 85 000 bytes will be placed in the Large Object Heap (which one should generally avoid).
The text was updated successfully, but these errors were encountered: