Linux TCP连接build立非常慢

我不确定有什么问题,但是我的服务器上每个传出的networking连接都很慢(在下面的代码段中称为dikkenek)。 这似乎是在连接build立。

bicou@dikkenek:~$ time ping -c 1 free.fr PING free.fr (212.27.48.10) 56(84) bytes of data. 64 bytes from www.free.fr (212.27.48.10): icmp_seq=1 ttl=58 time=12.1 ms --- free.fr ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 12.185/12.185/12.185/0.000 ms real 0m10.025s user 0m0.000s sys 0m0.000s 

正如你所看到的连接是完全正常的(12ms到我的ISP主页),然而它需要10秒钟来运行ping。

直接ping知识产权要快得多:

 bicou@dikkenek:~$ time ping -c 1 212.27.48.10 PING 212.27.48.10 (212.27.48.10) 56(84) bytes of data. 64 bytes from 212.27.48.10: icmp_seq=1 ttl=58 time=12.0 ms --- 212.27.48.10 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 12.045/12.045/12.045/0.000 ms real 0m0.013s user 0m0.000s sys 0m0.000s 

所以我认为我有一个名称parsing问题,但它也很快:

 bicou@dikkenek:~$ time host free.fr free.fr has address 212.27.48.10 free.fr has IPv6 address 2a01:e0c:1::1 free.fr mail is handled by 20 mx2.free.fr. free.fr mail is handled by 10 mx1.free.fr. real 0m3.022s user 0m0.008s sys 0m0.000s 

好了,花了3秒钟,但这不是一个快速的机器,见下文。

作为比较,这里是我的笔记本电脑上运行的相同命令(Mac OS X):

 <9> Mon May 11 23:05:42 ~ $ time ping -c 1 free.fr PING free.fr (212.27.48.10): 56 data bytes 64 bytes from 212.27.48.10: icmp_seq=0 ttl=58 time=15.194 ms --- free.fr ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 15.194/15.194/15.194/0.000 ms real 0m0.026s user 0m0.001s sys 0m0.003s <10> Mon May 11 23:05:48 ~ $ time ping -c 1 212.27.48.10 PING 212.27.48.10 (212.27.48.10): 56 data bytes 64 bytes from 212.27.48.10: icmp_seq=0 ttl=58 time=44.084 ms --- 212.27.48.10 ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 44.084/44.084/44.084/0.000 ms real 0m0.060s user 0m0.001s sys 0m0.003s <11> Mon May 11 23:06:09 ~ $ time host free.fr free.fr has address 212.27.48.10 free.fr has IPv6 address 2a01:e0c:1::1 free.fr mail is handled by 20 mx2.free.fr. free.fr mail is handled by 10 mx1.free.fr. real 0m3.059s user 0m0.006s sys 0m0.006s 

ping更快。

简单的HTTP连接也非常慢:

 bicou@dikkenek:~$ time curl -sI 'free.fr' HTTP/1.1 302 Moved Temporarily Server: nginx Date: Mon, 11 May 2015 21:10:47 GMT Content-Type: text/html Content-Length: 154 Connection: keep-alive Location: http://portail.free.fr/ real 0m5.548s user 0m0.008s sys 0m0.000s 

我的笔记本电脑:

 <14> Mon May 11 23:08:11 ~ $ time curl -sI 'free.fr' HTTP/1.1 302 Moved Temporarily Server: nginx Date: Mon, 11 May 2015 21:12:04 GMT Content-Type: text/html Content-Length: 154 Connection: keep-alive Location: http://portail.free.fr/ real 0m0.043s user 0m0.005s sys 0m0.004s 

两者之间的iperf(两种方式)都是非常好的:

 bicou@dikkenek:~$ iperf -c 192.168.0.13 -r ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ ------------------------------------------------------------ Client connecting to 192.168.0.13, TCP port 5001 TCP window size: 85.0 KByte (default) ------------------------------------------------------------ [ 5] local 192.168.0.10 port 55416 connected with 192.168.0.13 port 5001 [ ID] Interval Transfer Bandwidth [ 5] 0.0-10.2 sec 8.50 MBytes 7.01 Mbits/sec [ 4] local 192.168.0.10 port 5001 connected with 192.168.0.13 port 55140 [ 4] 0.0-10.4 sec 16.4 MBytes 13.3 Mbits/sec 

吞吐量不是很好,因为笔记本电脑只通过WiFi连接。 服务器使用1Gbps以太网电缆连接到路由器。

iperf到外部世界的工作原理如下(ISP说1.1Mbps UL / 31.5Mbps DL):

 bicou@dikkenek:~$ iperf -c iperf.testdebit.info -r ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ ------------------------------------------------------------ Client connecting to iperf.testdebit.info, TCP port 5001 TCP window size: 85.0 KByte (default) ------------------------------------------------------------ [ 3] local 192.168.0.10 port 37395 connected with 89.84.127.54 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0-11.0 sec 1.88 MBytes 1.43 Mbits/sec [ 5] local 192.168.0.10 port 5001 connected with 89.84.127.54 port 33129 [ 5] 0.0-10.2 sec 30.4 MBytes 24.9 Mbits/sec 

我主要关心的是慢速,几乎总是迟到5.5秒。

服务器运行Debian 8 jessie,笔记本电脑运行Mac OS X.10 Yosemite。

我可以使用哪些工具来解决Debian缓慢的问题?


编辑:正如Otheus指出的,这可能是一个DNS问题。 这是一个testing,确认它:

 bicou@dikkenek:~$ time curl -sIH 'Host: free.fr' 212.27.48.10 HTTP/1.1 302 Moved Temporarily Server: nginx Date: Mon, 11 May 2015 21:57:19 GMT Content-Type: text/html Content-Length: 154 Connection: keep-alive Location: http://portail.free.fr/ real 0m0.034s user 0m0.004s sys 0m0.000s 

现在我怎么能在这里加快速度?

你的DNSconfiguration搞砸了。 检查你的/etc/resolv.conf并确保只列出有效的服务器。