How many long connections can a Socket TCP server have on a port? What was the impact? Linux Max file Handle Count summary

Source: Internet
Author: User

How many long connections can a Socket TCP server have on a port?

There are many answers on the internet, I don't know that's right

Theoretically, it's infinite.

16, Linux, a port can accept the number of TCP links theoretical limit is?

a.1024

b.65535

c.65535 * 65535

D. No Limit

Reference answer:D

Focus: But will be determined by the maximum number of open files and memory

The number of connections on Linux can theoretically reach no limit, but in fact because everything in Linux is a file, Linux allows open files with the upper limit of the number of handles to decide ...

The maximum number of handles allowed to open files in Linux is 65535.

Without modifying the configuration, the view ulimit-n is 1024, but can be modified specifically based on memory, do not know what the internet says the upper limit for 65535 is why?

Because Ulimit-n is the maximum limit of the user's open file, it can be modified, and the value determined by limits.conf

ulimit-n and limits.conf The maximum number of files can not exceed the value of/proc/sys/fs/file-max, which is also funny,

/proc/sys/fs/file-max is the proposed value of the system, the system accounting resources to give a reasonable value, generally with the internal relationship, the larger the memory, the greater the value, but only a recommended value, Limits.conf can be set to more than/proc/sys/fs/file-max.

Then can be summed up a port can have a number of long connections is unlimited, the upper limit of ulimit-n is not 65535, the maximum number of files is determined by the size of the memory

Note: comments that have different answers

Linux Maximum number of file handlesVolume summary

Original article, reproduced: http://jameswxx.iteye.com/blog/2096461

Writing this article is to record straight, the article on the Internet is simply outrageous. What is the limit on the maximum number of files?

Shell-level throttling
modification by ulimit-n, such as executing command ulimit-n 1000, indicates that the maximum number of files that the current user of the current shell can open is set to.

Ulimit-n non-root users can only set the smaller, the larger the setting is not possibleI perform a non-root on the machine first: [email protected] etc]$ Ulimit-n 900
[Email protected] etc]$
Execute successfully, then increase: [email protected] etc]$ Ulimit-n 901
-bash:ulimit:open Files:cannot Modify limit:operation not permitted
[email protected] etc]$Increase the failure, if the decrease is OK: [Email protected] etc]$ ulimit-n 899
[email protected] etc]$If the increase to 900 is not possible: [email protected] etc]$ Ulimit-n 900
-bash:ulimit:open Files:cannot Modify limit:operation not permitted
  Root User UnrestrictedFirst switch to root: [email protected] etc]$ sudo su-
[Email protected] ~]#
To view the current limit: [email protected] ~]# ulimit-n
1000000
[email protected] ~]#Increase: [email protected] ~]# ulimit-n 1000001 [email protected] ~]#Can be increased successfully, then reduced: [email protected] ~]# ulimit-n 999999
[email protected] ~]#The decrease is also successful, and then increases: [email protected] ~]# ulimit-n 1000002 [email protected] ~]#Also OK, visible root is unrestricted. The default value for the maximum number of files opened in the UlimitIf not in limits.conf. have asetting, the default value is 1024 if the Limits.con have aSet, the default value is limits.conf. For example, I changed a machine, log in, ulimit-n display as follows: [email protected] ~]# ulimit-n
-
This is because the number of open files in my limits.conf is 2000, as follows: [email protected] ~]# cat/etc/security/limits.conf Root Soft Nofile 2000
Root Hard Nofile 2001If there are no restrictions in limits.conf, the ulimit-n appears as 1024 after logging in again. [email protected] ~]# ulimit-n 1024x768 ulimit effective period after modificationEffective immediately after the modification, after re-login into the invalid, because it was reset to the set value in Limits.conf two/etc/security/limits.conf online and Miushun, Ulimit-n set the value can not exceed the number of files opened in limits.conf (that is, soft nofile)Well, in fact, there are two cases, the root user can be exceeded, such as the current limits.conf settings are as follows: Root Soft Nofile 2000
Root Hard Nofile 2001But I use root to set the maximum number of files to 5000 is successful: [email protected] ~]# Ulimit-n 5000
[Email protected] ~]# ulimit-n
5000
[Email protected] ~]#
But the non-root user cannot exceed the limits.conf setting, I switch to WXX and execute the following command: [email protected] ~]# ulimit-n -bash:ulimit:open Files:cannot Modify limit:operation not permitted
 So the online statement is wrong, even if the maximum number of non-root files set can not exceed the limits.conf settings, this is only a representation, in fact, because each user log in, ulimit-n the default value is limits.conf? 0?2soft Nofile specified, but for non-root users, ulimit-n can only become smaller, not more and more large, in fact, this is the real reason, but the result is the same. modified limits.conf need to restart the system? This statement is very funny, modified limits.conf, re-login came into effect. On the machine to try to know, many people are really lazy, would rather ask around and do not want to take a minute to actually operate. three/proc/sys/fs/file-maxOnline said, Ulimit-n and limits.conf the maximum number of files set can not exceed the value of/proc/sys/fs/file-max, which is also funny,/proc/sys/fs/file-max is the system to give the recommended value, System accounting resources give a and reasonable value, general withMemory have aRelationship, the larger the memory, the greater the value, but only a recommended value, limits.conf can be set to more than/proc/sys/fs/file-max. [email protected] ~]# Cat/proc/sys/fs/file-max
1610495I set the maximum number of files in the limits.conf to 1610496, after saving, print out: [email protected] ~]# cat/etc/security/limits.conf Root Soft nofile1610496 Root Hard nofile1610496 Four. 0?2 Summary
    • /proc/sys/fs/file-max can't limit/etc/security/limits.conf.
    • Only the root user has permission to modify/etc/security/limits.conf
    • For non-root users,/etc/security/limits.conf restricts ulimit-n, but does not limit the root user
    • For non-root users, the ulimit-n can only be set smaller, the root user is unlimited
    • Any user modifications to Ulimit-n are valid only in the current environment, expire after exiting, re-login new, Ulimit-n determined by limits.conf
    • If limits.conf is not set, the default value is 1024
    • The maximum number of questions that the user of the current environment can open is determined by ulimit-n

How many long connections can a Socket TCP server have on a port? What was the impact? Linux Max file Handle Count summary

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.