xiaobaoqiu Blog

Think More, Code Less

Linux网卡速度

最近项目的图片服务器从公司的服务器下载图片做裁剪等操作的时候,老是存在超时的问题

1
2
3
4
5
6
7
8
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_51]
    at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_51]
    at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_51]
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:273) ~[na:1.7.0_51]
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_51]
    at sun.net.www.MeteredStream.read(MeteredStream.java:134) ~[na:1.7.0_51]
    at java.io.FilterInputStream.read(FilterInputStream.java:133) ~[na:1.7.0_51]

手动wget图片一切正常,但是速度还不如本地机器,于是想看一下服务器的网卡信息。下面用本机作为示例:

1.使用ifconfig找到网卡:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
eth0      Link encap:以太网  硬件地址 f0:1f:af:27:58:8d  
          inet 地址:192.168.138.99  广播:192.168.139.255  掩码:255.255.254.0
          inet6 地址: fe80::f21f:afff:fe27:588d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1
          接收数据包:696848 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:334077 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000 
          接收字节:486532283 (486.5 MB)  发送字节:49164276 (49.1 MB)
          中断:18 

lo        Link encap:本地环回  
          inet 地址:127.0.0.1  掩码:255.0.0.0
          inet6 地址: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  跃点数:1
          接收数据包:14772 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:14772 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:0 
          接收字节:1329005 (1.3 MB)  发送字节:1329005 (1.3 MB)

2.查看网卡是否被识别及型号

1
2
xiaobaoqiu@xiaobaoqiu:~/octopress$ lspci | grep Ethernet
0c:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5761 Gigabit Ethernet PCIe (rev 10)

3.使用ethtool工具查看网卡的详细信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
xiaobaoqiu@xiaobaoqiu:~/octopress$ sudo ethtool eth0
[sudo] password for xiaobaoqiu: 
Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Half 1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Half 1000baseT/Full 
    Advertised pause frame use: Symmetric
    Advertised auto-negotiation: Yes
    Link partner advertised link modes:  10baseT/Half 10baseT/Full 
                                         100baseT/Half 100baseT/Full 
    Link partner advertised pause frame use: No
    Link partner advertised auto-negotiation: Yes
    Speed: 100Mb/s      #网卡速度
    Duplex: Full        #全双工
    Port: Twisted Pair  #网络类型-双绞线
    PHYAD: 1
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: on
    Supports Wake-on: g
    Wake-on: g          #唤醒起用(远程关机开机需设置)
    Current message level: 0x000000ff (255)
                   drv probe link timer ifdown ifup rx_err tx_err
    Link detected: yes  #链路检测

4.查看网卡的连接状态

1
2
xiaobaoqiu@xiaobaoqiu:~/octopress$ sudo mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok

5.网卡数据包收发统计

1
2
3
4
5
6
7
8
9
10
11
12
xiaobaoqiu@xiaobaoqiu:~/octopress$ sudo ethtool -S eth0
NIC statistics:
     rx_octets: 494545915
     rx_fragments: 0
     rx_ucast_packets: 437748
     rx_mcast_packets: 147474
     rx_bcast_packets: 128799
     rx_fcs_errors: 0
     rx_align_errors: 0
     rx_xon_pause_rcvd: 0
     rx_xoff_pause_rcvd: 0
     ...