linux性能分析之网络篇

目录

一、性能指标

二、网络基准测试

2.1 PPS测试方法

2.2 TCP/UDP性能

2.3 HTTP 性能

2.4 应用负载


一、性能指标

  • 带宽:链路的最大传输速率。b/s(比特/秒) 常用带宽100M,1000M
  • 吞吐量:表示没有丢包时的最大数据传输速率,b/s(比特/秒),受带宽影响。经常听到的带宽测试,就是吞吐量,一般比带宽小,对于专用交换机来说,吞吐量接近带宽。
  • 延时:数据发出到远端响应的时间。
  • pps:(packet per second )包/秒,表示以网络包为单位的传输速率。评估网络转发能力。对于TCP或者Web来说,更多用并发连接数和每秒请求数(QPS)为指标,反应应用程序的性能。

二、网络基准测试

各层协议性能

2.1 PPS测试方法


        Linux 内核自带的高性能网络测试工具 pktgen。pktgen 支持丰富的自定义选项,方便你根据实际需要构造所需网络包,从而更准确地测试出目标服务器的性能。
    
        pktgen 在每个 CPU 上启动一个内核线程,并可以通过 /proc/net/pktgen 下面的同名文件,跟这些线程交互;而 pgctrl 则主要用来控制这次测试的开启和停止。
    
  

 # 定义一个工具函数pgset
    function pgset() {
        local result
        echo $1 > $PGDEV
    
        result=`cat $PGDEV | fgrep "Result: OK:"`
        if [ "$result" = "" ]; then
             cat $PGDEV | fgrep Result:
        fi
    }
    
    # 为0号线程绑定eth0网卡
    PGDEV=/proc/net/pktgen/kpktgend_0
    pgset "rem_device_all"   # 清空网卡绑定
    pgset "add_device ens33"  # 添加eth0网卡
    
    # 配置eth0网卡的测试选项
    PGDEV=/proc/net/pktgen/ens33
    pgset "count 1000000"    # 总发包数量
    pgset "delay 5000"       # 不同包之间的发送延迟(单位纳秒)
    pgset "clone_skb 0"      # SKB包复制
    pgset "pkt_size 64"      # 网络包大小
    pgset "dst 192.168.0.38" # 目的IP
    pgset "dst_mac fe80::xxxx:b8a0:xxxx:1791"  # 目的MAC
    
    # 启动测试
    PGDEV=/proc/net/pktgen/pgctrl
    pgset "start"
    root@ubuntu:/home/wy/misc/net# ./pgset.sh 
    ./pgset.sh: line 5: echo: write error: Invalid argument
    root@ubuntu:/home/wy/misc/net# cat  /proc/net/pktgen/ens33 
    Params: count 1000000  min_pkt_size: 64  max_pkt_size: 64
         frags: 0  delay: 5000  clone_skb: 0  ifname: ens33
         flows: 0 flowlen: 0
         queue_map_min: 0  queue_map_max: 0
         dst_min: 192.168.0.38  dst_max: 
         src_min:   src_max: 
         src_mac: 00:0c:29:a0:24:13 dst_mac: 00:00:00:00:00:00
         udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
         src_mac_count: 0  dst_mac_count: 0
         Flags: 
    Current:
         pkts-sofar: 1000000  errors: 0
         started: 790002417us  stopped: 824829444us idle: 53604us
         seq_num: 1000001  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
         cur_saddr: 192.168.0.133  cur_daddr: 192.168.0.38
         cur_udp_dst: 9  cur_udp_src: 9
         cur_queue_map: 0
         flows: 0
    Result: OK: 34827026(c34773421+d53604) usec, 1000000 (64byte,0frags)
      28713pps 14Mb/sec (14701056bps) errors: 0

  1. 第一部分的 Params 是测试选项;
  2. 第二部分的 Current 是测试进度,其中, packts so far(pkts-sofar)表示已经发送了 100 万个包,也就表明测试已完成。
  3. 第三部分的 Result 是测试结果,包含测试所用时间、网络包数量和分片、PPS、吞吐量以及错误数。


2.2 TCP/UDP性能

         工具: iperf netperf等


 启动服务(服务器)

iperf3 -s -i 1 -p 10000
//-s 启动服务器, -i间隔时间 -p监听端口

客户端(客户端)

iperf3 -c 192.168.0.38 -b 1G -t 15 -P 2 -p 10000

参数说明:
    -c 服务器IP地址 
    -b 速度 目标带宽(1G)
    -t 时间
    -P 并发数量
    -p 端口
 
 性能报告

    [ ID] Interval           Transfer     Bitrate         Retr
    [  5]   0.00-15.00  sec  1.10 GBytes   632 Mbits/sec   96             sender
    [  5]   0.00-15.00  sec  1.10 GBytes   631 Mbits/sec                  receiver
    [  7]   0.00-15.00  sec  1.25 GBytes   715 Mbits/sec   64             sender
    [  7]   0.00-15.00  sec  1.25 GBytes   714 Mbits/sec                  receiver
    [SUM]   0.00-15.00  sec  2.35 GBytes  1.35 Gbits/sec  160             sender
    [SUM]   0.00-15.00  sec  2.35 GBytes  1.35 Gbits/sec                  receiver


2.3 HTTP 性能

    工具: ab、webbench 等


 ab的安装 

apt-get install -y apache2-utils

 开启lighttpd服务器(服务端)

lighttpd -f lighttpd.conf 

 客户端测试(客户端)

ab -c 1000 -n 10000 http://192.168.0.30/

参数说明  : -c 并发数,-n请求总数
    

    root@ubuntu:/# ab -c 1000 -n 10000 http://192.168.0.38/
    This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 192.168.0.38 (be patient)
    Completed 1000 requests
    Completed 2000 requests
    Completed 3000 requests
    Completed 4000 requests
    Completed 5000 requests
    Completed 6000 requests
    Completed 7000 requests
    Completed 8000 requests
    Completed 9000 requests
    Completed 10000 requests
    Finished 10000 requests
    
    
    Server Software:        lighttpd/1.4.64
    Server Hostname:        192.168.0.38
    Server Port:            80
    
    Document Path:          /
    Document Length:        1330 bytes
    
    Concurrency Level:      1000
    Time taken for tests:   2.248 seconds
    Complete requests:      10000
    Failed requests:        0
    Total transferred:      15430000 bytes
    HTML transferred:       13300000 bytes
    
    //请求
    Requests per second:    4448.19 [#/sec] (mean)
    //平均延迟224.810
    Time per request:       224.810 [ms] (mean)
    //实际响应时间
    Time per request:       0.225 [ms] (mean, across all concurrent requests)
    //吞吐量6702.69
    Transfer rate:          6702.69 [Kbytes/sec] received
    
    //连接时间  最大 最小 连接 等待 总时间
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        1   79 211.7     31    1080
    Processing:    16   83  70.2     63     987
    Waiting:        6   52  54.7     38     913
    Total:         35  163 219.8     99    1451
    
    //延迟 50%在99ms内完成 90%在263ms内完成
    Percentage of the requests served within a certain time (ms)
      50%     99
      66%    121
      75%    142
      80%    159
      90%    263
      95%    437
      98%   1101
      99%   1122
     100%   1451 (longest request)
    

吞吐量:6702.69 [Kbytes/sec] received   响应时间: 0.225 [ms]


2.4 应用负载

上面都是空测,没有带负载。带负载的测试工具wrk

wrk安装

apt install wrk

同样测试lighttpd性能(服务端)

lighttpd -f lighttpd.conf 

(客户端)

//参数说明: -c并发数1000,-t 表示线程数2
root@ubuntu:/# wrk -c 1000 -t 2 http://192.168.0.38/
Running 10s test @ http://192.168.0.38/
  2 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    83.15ms   58.80ms   1.68s    91.10%
    Req/Sec     6.09k     1.95k   14.41k    73.98%
  120441 requests in 10.06s, 177.60MB read
Requests/sec:  11972.18
Transfer/sec:     17.65MB

每秒请求数 11972.18,吞吐量17.65MB, 平均延迟83.15

与ab相比有很大不同,吞吐量17.65MB而ab只有6MB左右
 


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为了维护世界和平_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值