如何衡量服务器代码的性能和TCP RTT?

时间:2011-05-23 19:54:46

标签: performance sockets tcp benchmarking tcptrace

我创建了一个基本的TCP服务器,它以协议缓冲区格式读取传入的二进制数据,并将二进制消息作为响应写入。我想对往返时间进行基准测试。

我尝试了iperf,但无法让它多次发送相同的输入文件。是否有另一个基准工具可以重复发送二进制输入文件?

5 个答案:

答案 0 :(得分:9)

如果您可以访问linux或unix机器 1 ,则应使用tcptrace。您需要做的就是在使用wiresharktcpdump文件进行捕获时循环进行二进制流量测试。

获得.pcap文件 2 后,使用tcptrace -xtraffic <pcap_filename> 3 进行分析。这将生成两个文本文件,该pcap中所有连接的平均RTT统计信息显示在名为traffic_stats.dat的文本的底部。

[mpenning@Bucksnort tcpperf]$ tcptrace -xtraffic willers.pcap
mod_traffic: characterizing traffic
1 arg remaining, starting with 'willers.pcap'
Ostermann's tcptrace -- version 6.6.1 -- Wed Nov 19, 2003

16522 packets seen, 16522 TCP packets traced
elapsed wallclock time: 0:00:00.200709, 82318 pkts/sec analyzed
trace file elapsed time: 0:03:21.754962
Dumping port statistics into file traffic_byport.dat
Dumping overall statistics into file traffic_stats.dat
Plotting performed at 15.000 second intervals
[mpenning@Bucksnort tcpperf]$
[mpenning@Bucksnort tcpperf]$ cat traffic_stats.dat


Overall Statistics over 201 seconds (0:03:21.754962):
4135308 ttl bytes sent, 20573.672 bytes/second
4135308 ttl non-rexmit bytes sent, 20573.672 bytes/second
0 ttl rexmit bytes sent, 0.000 bytes/second
16522 packets sent, 82.199 packets/second
200 connections opened, 0.995 conns/second
11 dupacks sent, 0.055 dupacks/second
0 rexmits sent, 0.000 rexmits/second
average RTT: 67.511 msecs        <------------------
[mpenning@Bucksnort tcpperf]$

此示例中使用的.pcap文件是我在循环通过从我的某个服务器提取数据的expect脚本时生成的捕获。这就是我生成循环的方式......

#!/usr/bin/python
from subprocess import Popen, PIPE
import time

for ii in xrange(0,200):
    # willers.exp is an expect script
    Popen(['./willers.exp'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    time.sleep(1)

您可以根据服务器的accept()性能和测试持续时间调整循环之间的休眠时间。

<小时/>

结束注意:

  1. A Knoppix Live-CD会做
  2. 过滤仅捕获测试流量
  3. 如果您使用其他选项,
  4. tcptrace能够提供非常详细的每插槽统计信息...
  5. ================================
    [mpenning@Bucksnort tcpperf]$ tcptrace -lr willers.pcap
    1 arg remaining, starting with 'willers.pcap'
    Ostermann's tcptrace -- version 6.6.1 -- Wed Nov 19, 2003
    
    16522 packets seen, 16522 TCP packets traced
    elapsed wallclock time: 0:00:00.080496, 205252 pkts/sec analyzed
    trace file elapsed time: 0:03:21.754962
    TCP connection info:
    200 TCP connections traced:
    TCP connection 1:
            host c:        myhost.local:44781
            host d:        willers.local:22
            complete conn: RESET    (SYNs: 2)  (FINs: 1)
            first packet:  Tue May 31 22:52:24.154801 2011
            last packet:   Tue May 31 22:52:25.668430 2011
            elapsed time:  0:00:01.513628
            total packets: 73
            filename:      willers.pcap
       c->d:                              d->c:
         total packets:            34           total packets:            39
         resets sent:               4           resets sent:               0
         ack pkts sent:            29           ack pkts sent:            39
         pure acks sent:           11           pure acks sent:            2
         sack pkts sent:            0           sack pkts sent:            0
         dsack pkts sent:           0           dsack pkts sent:           0
         max sack blks/ack:         0           max sack blks/ack:         0
         unique bytes sent:      2512           unique bytes sent:     14336
         actual data pkts:         17           actual data pkts:         36
         actual data bytes:      2512           actual data bytes:     14336
         rexmt data pkts:           0           rexmt data pkts:           0
         rexmt data bytes:          0           rexmt data bytes:          0
         zwnd probe pkts:           0           zwnd probe pkts:           0
         zwnd probe bytes:          0           zwnd probe bytes:          0
         outoforder pkts:           0           outoforder pkts:           0
         pushed data pkts:         17           pushed data pkts:         33
         SYN/FIN pkts sent:       1/1           SYN/FIN pkts sent:       1/0
         req 1323 ws/ts:          Y/Y           req 1323 ws/ts:          Y/Y
         adv wind scale:            6           adv wind scale:            1
         req sack:                  Y           req sack:                  Y
         sacks sent:                0           sacks sent:                0
         urgent data pkts:          0 pkts      urgent data pkts:          0 pkts
         urgent data bytes:         0 bytes     urgent data bytes:         0 bytes
         mss requested:          1460 bytes     mss requested:          1460 bytes
         max segm size:           792 bytes     max segm size:          1448 bytes
         min segm size:            16 bytes     min segm size:            32 bytes
         avg segm size:           147 bytes     avg segm size:           398 bytes
         max win adv:           40832 bytes     max win adv:           66608 bytes
         min win adv:            5888 bytes     min win adv:           66608 bytes
         zero win adv:              0 times     zero win adv:              0 times
         avg win adv:           14035 bytes     avg win adv:           66608 bytes
         initial window:           32 bytes     initial window:           40 bytes
         initial window:            1 pkts      initial window:            1 pkts
         ttl stream length:      2512 bytes     ttl stream length:        NA
         missed data:               0 bytes     missed data:              NA
         truncated data:            0 bytes     truncated data:            0 bytes
         truncated packets:         0 pkts      truncated packets:         0 pkts
         data xmit time:        1.181 secs      data xmit time:        1.236 secs
         idletime max:          196.9 ms        idletime max:          196.9 ms
         throughput:             1660 Bps       throughput:             9471 Bps
    
         RTT samples:              18           RTT samples:              24
         RTT min:                43.8 ms        RTT min:                 0.0 ms
         RTT max:               142.5 ms        RTT max:                 7.2 ms
         RTT avg:                68.5 ms        RTT avg:                 0.7 ms
         RTT stdev:              35.8 ms        RTT stdev:               1.6 ms
    
         RTT from 3WHS:          80.8 ms        RTT from 3WHS:           0.0 ms
    
         RTT full_sz smpls:         1           RTT full_sz smpls:         3
         RTT full_sz min:       142.5 ms        RTT full_sz min:         0.0 ms
         RTT full_sz max:       142.5 ms        RTT full_sz max:         0.0 ms
         RTT full_sz avg:       142.5 ms        RTT full_sz avg:         0.0 ms
         RTT full_sz stdev:       0.0 ms        RTT full_sz stdev:       0.0 ms
    
         post-loss acks:            0           post-loss acks:            0
         segs cum acked:            0           segs cum acked:            9
         duplicate acks:            0           duplicate acks:            1
         triple dupacks:            0           triple dupacks:            0
         max # retrans:             0           max # retrans:             0
         min retr time:           0.0 ms        min retr time:           0.0 ms
         max retr time:           0.0 ms        max retr time:           0.0 ms
         avg retr time:           0.0 ms        avg retr time:           0.0 ms
         sdv retr time:           0.0 ms        sdv retr time:           0.0 ms
    ================================
    

答案 1 :(得分:2)

你总是可以在像iperf这样的程序中使用shell循环。另外,假设iperf可以从文件(因此stdin)或ttcp等程序读取,可以允许shell循环将文件捕获N次到iperf / ttcp。

如果你想要一个发送文件的程序,等待你的二进制响应,然后发送该文件的另一个副本,你可能需要自己编写代码。

答案 2 :(得分:1)

您需要在客户端应用程序中测量往返时间,或监控来自客户端的网络流量以及到达客户端以获取完整的时间间隔。测量服务器的时间将排除服务器中的任何内核级延迟和所有网络传输时间。

答案 3 :(得分:0)

请注意,随着负载的增加,TCP性能会下降。如果您要在高负载下进行测试,则需要专业工具,这些工具可以扩展到数千(甚至在某些情况下数百万)新连接/第二或并发建立的TCP连接。

我在我的博客上写了一篇关于此内容的文章(如果这被认为是广告,请随意删除,但我认为这与此主题相关):http://synsynack.wordpress.com/2012/04/09/realistic-latency-measurement-in-the-application-layers

答案 4 :(得分:0)

作为一个非常简单的高级工具,我想到了netcat ...所以像time (nc hostname 1234 < input.binary | head -c 100)这样的假设响应是100字节长。