hn-classics/_stories/2010/6711866.md

55 lines
1.8 KiB
Markdown
Raw Normal View History

---
created_at: '2013-11-11T14:56:03.000Z'
title: What is the theoretical maximum number of open TCP connections? (2010)
url: http://stackoverflow.com/q/2332741/1257977
author: georgecmu
points: 42
story_text: ''
comment_text:
num_comments: 21
story_id:
story_title:
story_url:
parent_id:
created_at_i: 1384181763
_tags:
- story
- author_georgecmu
- story_6711866
objectID: '6711866'
2018-06-08 12:05:27 +00:00
year: 2010
---
2018-03-03 09:35:28 +00:00
A single listening port can accept more than one connection
simultaneously.
2018-02-23 18:19:40 +00:00
2018-03-03 09:35:28 +00:00
There is a '64K' limit that is often cited, but that is per client per
server port, and needs clarifying.
2018-02-23 18:19:40 +00:00
2018-03-03 09:35:28 +00:00
Each TCP/IP packet has basically four fields for addressing; these are:
2018-02-23 18:19:40 +00:00
2018-03-03 09:35:28 +00:00
source_ip source_port destination_ip destination_port
< client > < server >
Inside the TCP stack, these four fields are used as a compound key to
match up packets to connections (e.g. file descriptors).
If a client has many connections to the same port on the same
destination, then three of those fields will be the same - only
`source_port` varies to differentiate the different connections. Ports
are 16-bit numbers, therefore the maximum number of connections any
given client can have to any given host port is 64K.
However, multiple clients can each have up to 64K connections to some
server's port, and if the server has multiple ports or either is
multi-homed then you can multiply that further.
So the real limit is file descriptors. Each individual socket connection
is given a file descriptor, so the limit is really the number of file
descriptors that the system has been configured to allow and resources
to handle. The maximum limit is typically up over 300K, but is
configurable e.g. with [sysctl](http://linux.die.net/man/8/sysctl).
The realistic limits being boasted about for normal boxes are around 80K
for example single threaded Jabber messaging servers.