I have an application that has many threads processing data. As part of this processing, it is writing a small file to a network share. I create the FileStream using the following code:
using (var fileStream = new FileStream("\\server\path\etc", FileMode.Create, FileAccess.Write, FileShare.None))
Under high load (writing under 100 files per second), the creation of the FileStream CAN take a long time (over 60 seconds). This occurs after the application is running under high load for a few minutes.
There must be something that’s blocking the thread when creating the FileStream. I thought maybe the threads were being blocked trying to create a connection to the file share. I checked my process via Process Explorer, but could not find a TCP connection to the file server. So I’m guessing that the SMB connection to the file server is not over TCP.
Does anyone have an idea what the problem is, or how I can do things differently to achieve better performance?
I suspect you are experiencing the problem described in this KB article: Shared file access is delayed if the file is open on another computer. I have personally seen this cause Microsoft Access to block for 30 seconds because it retried the operation 30 times, each blocking for a second. Perhaps this is an extension of this problem.
I would start with the suggestion of trying local files first and see what happens.