Asp. NET tip: At the same time to write a large number of files on the performance optimization _ Practical skills

Source: Internet
Author: User

A project of my own that requires multiple write operations on 65,536 files at the same time.

If you open all the files first, then write them again, and then close all the files. Then it takes about 16 minutes for the first write to complete, and 40 minutes for the second time. No further tests were made.

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 when the write is done, close it. Then all the write operations are done in 2 minutes and 30 seconds.

Cycle


for (int i=0;i<65536;i++)
{
Open
Write
Close
}

This shows that the second method of performance is much greater than the first. Open all the files at once, need to occupy a large amount of memory, the most important is. NET in processing FileStream, you may have to do a lot of memory allocation and recycling work, consumes a lot of memory and resources.

In addition, I also do a test, if the number of files is small, then the first performance will be much better than the second.

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.