[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
一个TCP连接由一个四元组所确定
源IP源端口目的IP目的端口
任意一个元素改变,都代表一个新的连接,以Nginx为例,它的端口是固定使用80。另外服务器的IP也是固定的,那么理论上最多可以建立 2 ^ 32 (ip数)
× 2 ^ 16 (端口数) 个连接。
<>文件描述符限制
实际上,能建立的连接远小于这个数字。我们每打开一个连接都对应一个文件描述符fd(linux系统下一切皆文件)。出于安全角度的考虑,linux系统在多个位置都限制了可打开的文件描述符的数量,包括系统级、用户级、进程级。
* 系统级:当前系统可打开的最大数量,通过fs.file-max参数可修改
* 用户级:指定用户可打开的最大数量,修改/etc/security/limits.conf
* 进程级:单个进程可打开的最大数量,通过fs.nr_open参数可修改
<>内存限制
每一条TCP连接都有file、socket等内核对象,这样一个空TCP连接需要占用3.3KB内存,考虑到实际收发还要配置缓存区,这样内存占用更高了。
通过sysctl命令查看接收缓存区大小
$ sysctl -a | grep rmem net.ipv4.tcp_rmem = 4096 87380 8388608 net.core.
rmem_default = 212992 net.core.rmem_max = 8388608
tcp_rmem中的第一个值是TCP连接所需分配的最少字节数。该值默认是4K,最大为8MB。所以需要接收数据时,需要起码再分配4K内存。
通过sysctl命令查看发送缓存区大小
$ sysctl -a | grep wmem net.ipv4.tcp_wmem = 4096 65536 8388608 net.core.
wmem_default = 212992 net.core.wmem_max = 8388608
tcp_wmem中的第一个值是发送缓存区的最小值,默认也是4K。如果数据很大的话,该缓存区实际分配的也会比默认值大。