了解TCP侦听囤积



我将深入了解更改TCP连接队列大小的影响。所以我写了一个简单的服务器/客户端对来测试它

服务器在python模块SocketServer中实例化ForkingTCPServer。为了测试挂起的连接队列大小的影响,我覆盖了服务器的两个参数,如下所示:

max_children = 1        # default 40, max number of child processes
request_queue_size = 0  # default 5, socket listen() backlog

下面是服务器的请求处理程序,它提供了一个简单的"延迟"回显服务。

class RequestHandler(socketserver.StreamRequestHandler):
def handle(self):
self.data = self.rfile.readline().strip()
time.sleep(30)
self.wfile.write(self.data)

在客户端中,10个套接字连接服务器并同时发送一条线路。

for i in xrange(10): 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.append(s)
s.connect_ex(address)
s.sendall('{}n'.format(i)

结果只有3-4个插座成功连接。其他人甚至没有完成3向握手,最后服务器向他们发送了一个RST。以下是其中一个失败客户端的tcpdump输出。可以看出,服务器(端口:10086)从客户端(端口:53241)接收到SYN,并发回SYN/ACK。客户端在接收到CCD_ 7时还发送了CCD_。然而,服务器似乎没有从客户端接收到ACK。所以它不断地向客户端发送SYN/ACK,最后通过发送RST来放弃。

有人能向我解释一下为什么服务器没有看到ACK吗?是因为连接队列溢出吗?

17:41:30.568077 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [S], seq 3931554775, win 32792, options [mss 16396,sackOK,TS val 2434238 ecr 0,nop,wscale 6], length 0
17:41:30.568090 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2434238 ecr 2434238,nop,wscale 6], length 0
17:41:30.568100 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2434238 ecr 2434238], length 0
17:41:30.568479 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434239 ecr 2434238], length 2
17:41:30.770902 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434440 ecr 2434238], length 2
17:41:31.172453 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434843 ecr 2434238], length 2
17:41:31.767360 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2435438 ecr 2434843,nop,wscale 6], length 0
17:41:31.767391 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2435438 ecr 2434238], length 0
17:41:31.976349 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2435647 ecr 2434238], length 2
17:41:33.584352 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2437255 ecr 2434238], length 2
17:41:33.969825 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2437640 ecr 2437255,nop,wscale 6], length 0
17:41:33.969854 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2437640 ecr 2434238], length 0
17:41:36.800489 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2440471 ecr 2434238], length 2
17:41:38.177461 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2441848 ecr 2440471,nop,wscale 6], length 0
17:41:38.177493 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2441848 ecr 2434238], length 0
17:41:43.232468 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2446903 ecr 2434238], length 2
17:41:46.193321 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2449864 ecr 2446903,nop,wscale 6], length 0
17:41:46.193352 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2449864 ecr 2434238], length 0
17:41:56.096467 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2459767 ecr 2434238], length 2
17:42:02.211676 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2465882 ecr 2459767,nop,wscale 6], length 0
17:42:02.211698 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2465882 ecr 2434238], length 0
17:42:21.825117 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2485495 ecr 2434238], length 2
17:43:13.281525 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2536952 ecr 2434238], length 2
17:43:13.281625 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [R], seq 2946632839, win 0, length 0

是因为连接队列溢出吗?

否。如果囤积队列已满,它就不会发送SYN/ACK,它要么什么都不做,要么发送RST,这取决于平台。

相关内容

  • 没有找到相关文章

最新更新