[Perl] open multiple files-use of file handles

Source: Internet
Author: User

It is often said that a file is divided into many small files. If you need to "open file handle-write data-Close file handle" after each judgment ", it takes a lot of time to repeatedly open or close the file handle.

The process is often in the "S" sleep state.

If multiple files are opened at the same time and the file to be written is determined, the CPU wait time can be reduced.

For my $ I (0 .. 99)

{

$ O = "out". $ I;

Open $ O, "> test. $ I" or die $ !;

Print $ o "test ";

Close $ O;

}

 

Number of files allowed to be opened simultaneously in Linux:

/Proc/sys/fs/file-max

 

Appendix:

How does one modify the maximum number of file descriptors that can be opened simultaneously in the Linux kernel by default?
Source code file found
File-max <kernel-path>;/fs/file. c
Inode-Nr <kernel-path>;/fs/innode. c

If the system is not a streamlined kernel, use the following methods to modify it:
Ulimit-n <number of files that can be opened at the same time>; sets the maximum number of files that can be opened at the same time (max open files)

# Echo "65536">;/proc/sys/fs/file-Max # Applicable to 2.2 and 2.4 kernels
# Echo "131072">;/proc/sys/fs/inode-Max # Applicable only to kernel 2.2
Or Add the following content to/etc/sysctl. conf to make permanent changes:

 

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.