tcp/ip协议listen函数中backlog参数的含义与php-fpm的502 Bad Gateway
To understand the backlog argument, we must realize that for a given listening socket, the kernel maintains two queues :
要明白backlog参数的含义,我们必须明白对于一个listening socket,kernel维护者两个队列:
1.An incomplete connection queue, which contains an entry for each SYN that has arrived from a client for which the server is awaiting completion of the TCP three-way handshake. These sockets are in the SYN_RCVD state .
1.一个未完成连接的队列,此队列维护着那些已收到了客户端SYN分节信息,等待完成三路握手的连接,socket的状态是SYN_RCVD
2.A completed connection queue, which contains an entry for each client with whom the TCP three-way handshake has completed. These sockets are in the ESTABLISHED state
2.一个已完成的连接的队列,此队列包含了那些已经完成三路握手的连接,socket的状态是ESTABLISHED
The backlog argument to the listen function has historically specified the maximum value for the sum of both queues.
backlog参数历史上被定义为上面两个队列的大小之和
Berkeley-derived implementations add a fudge factor to the backlog: It is multiplied by 1.5
Berkely实现中的backlog值为上面两队列之和再乘以1.5
When a SYN arrives from a client, TCP creates a new entry on the incomplete queue and then responds with the second segment of the three-way handshake: the server's SYN with an ACK of the client's SYN (Section 2.6). This entry will remain on the incomplete queue until the third segment of the three-way handshake arrives (the client's ACK of the server's SYN), or until the entry times out. (Berkeley-derived implementations have a timeout of 75 seconds for these incomplete entries.)
当客户端的第一个SYN到达的时候,TCP会在未完成队列中增加一个新的记录然后回复给客户端三路握手中的第二个分节(服务端的SYN和针对客户端的ACK),这条记录会在未完成队列中一直存在,直到三路握手中的最后一个分节到达,或者直到超时(Berkeley时间将这个超时定义为75秒)
If the queues are full when a client SYN arrives, TCP ignores the arriving SYN (pp. 930–931 of TCPv2); it does not send an RST. This is because the condition is considered temporary, and the client TCP will retransmit its SYN, hopefully finding room on the queue in the near future. If the server TCP immediately responded with an RST, the client's connect would return an error, forcing the application to handle this condition instead of letting TCP's normal retransmission take over. Also, the client could not differentiate between an RST in response to a SYN meaning "there is no server at this port" versus "there is a server at this port but its queues are full."
如果当客户端SYN到达的时候队列已满,TCP将会忽略后续到达的SYN,但是不会给客户端发送RST信息,因为此时允许客户端重传SYN分节,如果返回错误信息,那么客户端将无法分清到底是服务端对应端口上没有相应应用程序还是服务端对应端口上队列已满这两种情况
通过下面方式可以修改系统的 somaxconn
vim /etc/sysctl.conf
net.core.somaxconn = 2048
sysctl -p
在 php-fpm 中,有一个选项是关于这个方面的
listen.backlog = -1
这个数值,最好不要设置为 -1 ,-1 的时候没不能采用系统的设置数置,导致出现 502 出现
2015/02/11 12:37:22 [error] 25725#0: *1015645 connect() to unix:/tmp/php-cgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 222.240.64.190,
解决方法就是手动设置这个数值
listen.backlog = 1024
tcp/ip协议listen函数中backlog参数的含义与php-fpm的502 Bad Gateway的更多相关文章
- tcp/ip协议listen函数中backlog參数的含义
listen函数的定义例如以下所看到的: #include <sys/socket.h> int accept(int sockfd, struct sockaddr * restrict ...
- listen()函数中backlog参数分析
实例分析1 将服务器端的listen函数backlog设置为2,用20个客户端与服务器建立连接,查看连接的建立情况. 服务器代码: #include <stdio.h> #include& ...
- TCP/IP 协议图--网络层中的 IP 协议
IP(IPv4.IPv6)相当于 OSI 参考模型中的第3层——网络层.网络层的主要作用是“实现终端节点之间的通信”.这种终端节点之间的通信也叫“点对点通信”. 网络的下一层——数据链路层的主要作用是 ...
- TCP/IP协议图--网络层中的IP协议
IP(IPv4.IPv6)相当于 OSI 参考模型中的第3层--网络层.网络层的主要作用是"实现终端节点之间的通信".这种终端节点之间的通信也叫"点对点通信". ...
- 网络编程的基本概念,TCP/IP协议简介
8.1.1 网络基础知识 计算机网络形式多样,内容繁杂.网络上的计算机要互相通信,必须遵循一定的协议.目前使用最广泛的网络协议是Internet上所使用的TCP/IP协议. 网络编程的目的就是指直接或 ...
- TCP/IP协议学习之实例ping命令学习笔记
TCP/IP协议学习之实例ping命令学习笔记(一) 一. 目的为了让网络协议学习更有效果,在真实网络上进行ping命令前相关知识的学习,暂时不管DNS,在内网中,进行2台主机间的ping命令的整个详 ...
- tcp ip 协议安全
ARP(地址解析协议) 地址解析协议,即ARP(Address Resolution Protocol),是根据IP地址获取物理地址的一个TCP/IP协议.主机发送信息时将包含目标IP地址的ARP请求 ...
- 计算机网络协议OSI TCP/IP协议--001
网桥:连接同构的LAN的网络互联设备,(同构的LAN 网是,应用层到逻辑层) 实 现的功能是:MAC子层和物理层.1.帧的发送与接收.2.缓冲的管理.3.协议转换. 路由器:在网络层实现互联,他 ...
- TCP/IP协议——TCP/IP协议栈及框架
TCP/IP协议同ISO/OSI模型一样,也可以安排成栈形式.但这个栈不同于ISO/OSI版本,比ISO/OSI栈少,所以又称之为短栈.另外,需要知道的是:TCP/IP协议栈只是许多支持ISO/OSI ...
随机推荐
- iOS 字典自动生成模型
在实际开发中,我们经常需要根据字典来建模型.每次都打那么一串代码,想想也是挺恶心的.可以自己给NSDictionary写一个分类,进行属性生成. NSDictionary+Property.h #im ...
- atitit.软件开发方法总结O6
atitit.软件开发方法总结O6 #--cmm/cmmi 都晓得这个. #--IPD集成产品开发 结构化的流程 IPD工具:包括业务及技术上的共工具. 5.考评:包括团队和个人绩效考核两个方面:首 ...
- iOS开发——高级技术&地图功能的实现
地图功能的实现 因为有个项目要在地图中显示位置,所以用到了MapKit. 记录下来,以免以后忘记. 加入MapKit library 首先得在项目中加入MapKit,如图 MapView 先增加一个V ...
- 遵循amd规范的require.js(适合浏览器端)
1. 下载require.js 2. 引用 html <!DOCTYPE html> <html lang="en"> <head> <m ...
- python遍历数据
#coding=utf-8 import MySQLdb conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd= ...
- 使用ThreadPool代替Thread
线程的空间开销 线程内核对象.包含上下文信息.32位系统占用700字节 线程环境块.包括线程的异常处理链.32位系统占用4KB 用户模式栈.保存方法的参数.局部变量和返回值 内核模式栈.调用操作系统的 ...
- oprofile
一.原理 在关注事件发生一定次数时,进行一次采样,记录下需要的信息(比如指令寄存器或栈寄存器信息). 二.参数 项 说明 eventname 要关注的事件名称,常用的事件名称及功能如下: CP ...
- 漫谈Puppet4
激动人心的改进 速度,速度,还是速度 稳定性和鲁棒性的提升 全新的Parser “不变"的agent 不兼容的改动 包管理方式的变化 配置文件/目录的路径变化 其他路径变化 Director ...
- Redis 数据结构之Keys
这是Redis官方文档的keys列表 (1) set key value--设置某个键为某个值 (2) get key -- 获取设置的值 (3)del key -- 删除设置的键 (4)expir ...
- Scala 深入浅出实战经典 第76讲:模式匹配下的赋值语句
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载: 百度云盘:http://pan.baidu.com/s/1c0noOt ...