ASP. NET: optimizes performance by performing a large number of write operations on multiple files at the same time

Source: Internet
Author: User

In my own project, I need to write 65536 files multiple times at the same time.

If you open all the files first, repeat the writing, and close all the files. It takes about 16 minutes to complete the first write operation, and 40 minutes to complete the second write operation. The test is not continued.

For (int I = 0; I <65536; I ++)
{
FileStream [I] = new FileStream (buffDir + "\" + I. toString () + ". dat ", FileMode. create, FileAccess. write, FileShare. write, 14000 );
}
Write;
Write;
Write;
........
For (int I = 0; I <65536; I ++)
{
FileStream [I]. close ();
}

If only one file is opened during the write operation, close it after writing. All write operations are completed at about 2 minutes 30 seconds.

Loop

{
For (int I = 0; I <65536; I ++)
{
Open;
Write;
Close;
}
}

Therefore, the performance of the second method is far greater than that of the first method. Opening all files at a time requires a large amount of memory. The most important thing is. when processing filestream, net may need to allocate and recycle a large amount of memory, consuming a large amount of memory and resources.

In addition, I also conduct a test. If the number of files is small, the first type of performance will be much better than the second type.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.