netstat -o
输出中包含一些计时器信息,但我没有在任何地方找到该列中输出的解释Timer
。
有人能解释一下或指出解释吗?
这就是 netstat -o 的输出(在 Ubuntu 8.04 上)。
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State Timer
tcp 0 0 192.168.22.1:443 111.111.11.210:5804 ESTABLISHEDkeepalive (6176.47/0/0)
tcp 0 0 192.168.22.1:443 192.168.22.253:48379 TIME_WAIT timewait (36.57/0/0)
tcp 0 924 192.168.22.1:47763 10.9.169.60:443 ESTABLISHEDon (0.34/0/0)
tcp 0 0 192.168.22.1:443 192.168.111.99:4059 ESTABLISHEDkeepalive (6963.60/0/0)
tcp 0 0 192.168.22.1:443 192.168.111.74:1729 ESTABLISHEDkeepalive (1393.60/0/0)
tcp 0 0 192.168.56.1:42204 10.9.169.60:443 ESTABLISHEDoff (0.00/0/0)
tcp 0 0 192.168.56.1:42207 10.9.169.60:443 ESTABLISHEDoff (0.00/0/0)
tcp 0 940 192.168.22.1:42186 10.9.169.60:443 ESTABLISHEDon (0.28/0/0)
tcp 0 0 192.168.22.1:443 192.168.22.253:48367 TIME_WAIT timewait (31.57/0/0)
tcp 0 0 192.168.22.1:42234 10.9.169.60:443 ESTABLISHEDoff (0.00/0/0)
tcp 0 0 192.168.22.1:42209 10.9.169.60:443 ESTABLISHEDoff (0.00/0/0)
答案1
第一个数字显然是倒数计时器。根据状态类型,一旦计时器超时,它将重试并发送另一个 FIN 或任何需要重试的数据包。因此,第二个数字跟踪重试次数。请注意,计时器会增加,因为 TCP 有退避计时器,以防出现流量状况。退避计时器避免过于频繁的重试。每次失败都会导致越来越大的退避。退避可能是指数增长或线性增长,具体取决于 TCP 堆栈。我还没搞清楚 3 这个数字是干什么的。我的显示总是为零。
答案2
计时器列有两个字段(来自上面的 o/p):
keepalive (6176.47/0/0)
<1st field> <2nd field>
可以1st field
具有以下值:
keepalive
- 当套接字的保活定时器打开时
on
- 当套接字的重传定时器打开时
off
- 以上都不打开
有2nd field
三个子字段:
(6176.47/0/0) -> (a/b/c)
a
= 计时器值(a = 保持活动计时器,当第一个字段为“保持活动”时;a = 重传计时器,当第一个字段为“开启”时)
b
= 已发生的重传次数
c
= 已发送的保持活动探测次数
例如,我在客户端和服务器之间打开了两个套接字(不是回送)。keepalive 设置为:
KEEPALIVE_IDLETIME 30
KEEPALIVE_NUMPROBES 4
KEEPALIVE_INTVL 10
我关闭了客户端机器,因此在服务器端我运行了 netstat 并且输出为:
端口1:
netstat -c --timer | grep "192.0.0.1:43245 192.0.68.1:49742"
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (1.92/0/0)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (0.71/0/0)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (9.46/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (8.30/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (7.14/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (5.98/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (4.82/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (3.66/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (2.50/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (1.33/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (0.17/0/1)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (9.01/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (7.75/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (6.47/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (5.29/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (4.08/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (2.89/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (1.73/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (0.54/0/2)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (9.38/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (8.23/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (7.08/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (5.93/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (4.76/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (3.62/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (2.48/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (1.32/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (0.13/0/3)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (8.98/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (7.78/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (6.62/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (5.45/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (4.29/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (3.14/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (1.99/0/4)
tcp 0 0 192.0.0.1:43245 192.0.68.1:49742 ESTABLISHED keepalive (0.85/0/4)
您可以在上面看到,服务器发送了四次保持活动探测,每次间隔 10 秒,由于没有收到任何响应,因此发送的探测次数会增加,在 4 次之后,它会断开与客户端的连接。
端口 2:
对于第二个连接,套接字是相同的,不同之处在于,在客户端关闭之后和保持活动过期之前,我的服务器端应用程序试图发送一些消息:
netstat -c --timer | grep "192.0.0.1:36483 192.0.68.1:43881"
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (8.18/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (7.00/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (5.86/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (4.71/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (3.55/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (2.40/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (1.21/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (0.05/0/1)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (8.91/0/2)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (7.75/0/2)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (6.56/0/2)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (5.39/0/2)
tcp 0 0 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED keepalive (4.14/0/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.21/2/2) // <---- retransmission timer kicks in
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.68/3/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.74/4/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.59/4/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.43/4/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.28/5/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.11/5/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.95/6/2)
. . . . .
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.65/249/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.58/250/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.48/250/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.36/250/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.26/251/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.15/251/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (3.01/252/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.92/252/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.84/252/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.72/253/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.64/253/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.55/253/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.47/254/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.39/254/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (0.31/254/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (2.19/255/2)
tcp 0 210 192.0.0.1:36483 192.0.68.1:43881 ESTABLISHED on (1.12/255/2)
如您所见,在这种情况下情况略有不同。当客户端宕机时,我的服务器开始发送保持活动消息,但在它仍在发送这些保持活动消息时,我的服务器尝试向客户端发送一条消息。由于客户端宕机,服务器无法从客户端获得任何 ACK,因此 TCP 重新传输开始,服务器尝试再次发送数据,每次在重新传输计时器(第 1 个字段)到期时增加重新传输计数(第 2 个字段)。
希望这netstat --timer
能很好地解释这个选项。
答案3
第一个字段:timewait/keepalive
从传输最后一个数据到发送下一个 TCP 保持连接探测的时间(以秒为单位)。
默认情况下,该值从 7200 秒开始,每次发送更多数据时都会重新设置。如果该值较低,例如 4000 秒,则意味着某些保持活动连接长时间挂起或无任何操作。
与内部代理或其他内部进程的连接可能会暂停更长时间,但这不应该发生在基于 Web 的连接上。