Optimizing disk writes
If your site creates many new files on disk, such as files uploaded by visitors, consider these performance improvements:
Avoid head seeks
Use
FileStream.SetLength
to avoid fragmentationUse 64 K buffers
Disable 8.3 filenames
Avoiding head seeks
Writing bytes sequentially without moving the read/write head happens much faster than random access. If you are only writing the files and not reading them, try writing them on a dedicated disk drive using a single dedicated thread. That way, other processes won't move the read/write head on the drive.
Using FileStream.SetLength to avoid fragmentation
If multiple threads write files at the same time, space used for those files will become interleaved, leading to instant fragmentation.
To prevent this, use the FileStream.SetLength
method to reserve enough space for the file before you start writing.
If you use the ASP.NET FileUpload
control to receive files from a visitor, it can give get the length of a file as shown:
int bufferLength...