如何测量网络性能(如何对网络协议进行基准测试) [英] How to measure network performance (how to benchmark network protocol)

查看:35
本文介绍了如何测量网络性能(如何对网络协议进行基准测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,有一点背景.分布式版本控制系统 (DVCS) 有许多不同的比较,它们比较存储库的大小或操作的基准速度.我还没有找到任何可以对各种 DVCS 和所使用的各种协议的网络性能进行基准测试的方法……除了测量涉及克隆"、拉取"/获取"或推送"等网络的操作(命令)的速度.

我想知道你会如何进行这样的比较;如何测量应用程序的网络性能,或如何对网络协议进行基准测试.我在这里设想还测量性能对网络带宽和网络延迟(ping 时间)的依赖性;一些协议以更多往返交换(协商)的形式牺牲延迟,以发送所需的最少最终包".

如果可能,我更喜欢只涉及一台计算机的解决方案.我希望看到在 Linux 上运行的开源解决方案.但我也欢迎更通用的答案.

首选操作系统: Linux
首选语言: C、Perl、shell 脚本

<小时>

可能的测量:

  • 在一个会话中从服务器到客户端以及从客户端到服务器传输的总字节数;这也可以用来衡量协议的开销(带宽)
  • 一个事务中的往返次数(连接)(延迟)
  • 网络运行速度(克隆/拉取/推送所需的时间)与网络带宽和网络延迟(ping 时间)的相关性

如何进行这样的测量(这样的基准)?

<小时>

2009 年 2 月 6 日添加:
最简单的基准(测量)将是 time 命令的网络版本,即运行的命令会给我传输的字节数,以及在执行给定命令期间的往返次数/网络连接数.

<小时>

2009 年 9 月 6 日添加:
示例上述time命令的网络版本解决方案的假想输出可能如下所示:

$ ntime git clone -q git://git.example.com/repo.git...发送的字节数:nnn (nn kiB),接收的字节数:nnn (nn kiB),平均值:nn.nn KB/snn 读取,nn 写入

请注意,这只是一个示例输出,详细说明了人们可能想要获取的信息.

<小时>

2009 年 9 月 6 日添加:
看起来我想要的一些东西可以使用 dummynet 来实现,这个工具(最初)用于测试网络协议...

解决方案

如果我对你的理解正确,你基本上对 Linux 'strace' (简介) 用于特定网络的系统调用?

可能是分析器和调试器的组合,用于网络应用程序(即ntrace"),提供各种可选测量的详细分析?

在 Linux 下,strace 实用程序主要基于Linux内核,即ptrace(进程跟踪) API:

使用ptrace,应该可以获取大部分你感兴趣的数据.

在 Windows 上,您可能需要查看 detours为了拦截/重定向 Winsock API 调用以进行检查/基准测试.

如果您真的不需要那么多低级信息,您也可以直接使用 strace(在 linux 上)并仅使用它来跟踪某些系统调用,例如考虑以下仅跟踪调用的行open 系统调用(使用附加的 -o FILE 参数,您可以将所有输出重定向到输出文件):

strace -e trace=open -o results.log

通过向 strace 传递一个额外的 -v 标志,您可以增加它的详细程度以获取更多信息(当使用 git 等由许多较小的 shell 实用程序和独立工具组成的 SCM 时,您可能还想查看使用 -f 标志来跟踪分叉进程).

所以,您会感兴趣的是所有与 sockets,即:

  • 接受
  • 绑定
  • 连接
  • getpeername
  • getsockname
  • getsockopt
  • 听听
  • 接收
  • recvfrom
  • 发送
  • 发送到
  • setsockopt
  • 关机
  • 插座
  • 套接字对

(虽然一开始,您可能只想研究处理 send.../recv... 调用)

为了简化这一点,您还可以使用network"作为参数进行跟踪,这将跟踪所有与网络相关的调用:

<块引用>

-e trace=network:跟踪所有网络相关的系统调用.

因此,相应的 strace 调用可能如下所示:

strace -v -e trace=accept,bind,connect,getpeername,getsockname,getsockopt,listen,recv,recvfrom,send,sendto setsockopt,shutdown,socket,socketpair -o results.log -f git pull

当程序运行完毕后,你主要想检查日志文件来评估数据,这可以通过使用正则表达式轻松实现.

例如,在 linux shell 中运行以下命令时:strace -v -o wget.log -e trace=connect,recv,recvfrom,send,sendto wget http://www.google.com

生成的日志文件包含如下消息:

  • recv(3, "HTTP/1.0 302 Found Location: htt"..., 511, MSG_PEEK) = 511
  • 发送至(4, "242613^206*J"...,20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20

查看这两个系统调用的手册页,很明显 511 和 20 分别是传输的字节数.如果您还需要详细的时序信息,可以将 -T 标志传递给 strace:

<块引用>

-T -- 打印每个系统调用所花费的时间

另外,你可以通过传递 -c 标志来获取一些统计信息:

<块引用>

-c:计算每个系统调用的时间、调用和错误,并报告程序摘要出口.在 Linux 上,这会尝试显示系统时间(在内核中运行的 CPU 时间)独立于挂钟时间.如果 -c 与 -f 或 -F(如下)一起使用,则仅聚合保留所有跟踪过程的总数.

如果您还需要检查实际处理的数据,您可能需要查看读/写说明符:

<块引用>

-e read=set:对从文件中读取的所有数据执行完整的十六进制和 ASCII 转储指定集合中列出的描述符.例如,查看文件上的所有输入活动描述符 3 和 5 使用 -e read=3,5.请注意,这与正常情况无关跟踪由选项 -e trace=read 控制的 read(2) 系统调用.-e write=set:对写入文件的所有数据执行完整的十六进制和 ASCII 转储指定集合中列出的描述符.例如,查看文件上的所有输出活动描述符 3 和 5 使用 -e write=3,5.请注意,这与正常情况无关跟踪由选项 -e trace=write 控制的 write(2) 系统调用.

您还可以自定义字符串的最大长度:

<块引用>

-s strsize:指定要打印的最大字符串大小(默认为 32).注意文件名不被视为字符串,总是完整打印

或者将字符串转储为十六进制:

<块引用>

-xx:以十六进制字符串格式打印所有字符串.

因此,在大部分情况下使用 strace 似乎是一种很好的混合方法,因为它很容易做到,但仍然有大量可用的低级信息,如果您发现需要额外的低级信息,您可能需要考虑扩展 strace 或使用 sourceforge 上的 strace 项目提交相应的功能请求.p>

但是,考虑更多,实现相当简单的网络流量基准测试的一种较少涉及且与平台无关的方式,将是在客户端和实际服务器之间使用某种形式的中间层:服务器这基本上是计量、分析流量并将其重定向到真实服务器.

很像代理服务器(例如 SOCKS),因此所有流量都通过隧道传输您的分析器,进而可以累积统计数据和其他指标.

这样的基本版本可能只需使用 netcat 和一些 shell 脚本就可以轻松组合在一起,但是更复杂的版本可能会受益于使用 perl 或 python.

对于 SOCKS 服务器的 python 实现,您可能需要查看 pysocks.p>

此外,python 当然还有 twisted:

<块引用>

Twisted 是一个用 Python 编写的事件驱动的网络引擎并在 MIT 许可下获得许可.

如果您确实需要更多低级信息,那么您可能真的想研究拦截系统调用.

如果您还需要特定协议的效率数据,您可能需要查看 tcpdump.

First, a bit of a background. There are many various comparisons of distributed version control systems (DVCS) which compare size of repository, or benchmark speed of operations. I haven't found any that would benchmark network performance of various DVCS, and various protocols used... beside measuring speed of operations (commands) involving network like 'clone', 'pull'/'fetch' or 'push'.

I'd like to know then how would you make such comparison; how to measure network performance of an application, or how to benchmark network protocol. I envision here among others also measuring dependence of performance on both bandwidth of network and latency (ping time) of network; some protocols sacrifice latency in the form of more round-trip exchanges (negotiation) to send minimal required final "pack".

I would prefer solutions involving only one computer, if possible. I'd like to see open source solutions, working on Linux. But I would also welcome more generic answers.

Preferred OS: Linux
Preferred languages: C, Perl, shell script


Possible measurements:

  • total number of bytes transferred from server to client and from client to server in one session; this can also be used to measure overhead of protocol (bandwidth)
  • number of round-trips (connections) in one transaction (latency)
  • dependency of speed of network operation (time it takes to clone/pull/push) from network bandwidth, and from network latency (ping time)

How to make such measurements (such benchmarks)?


Added 02-06-2009:
A simplest benchmark (measurement) would be a network version of time command, i.e. command which run would give me number of bytes transferred, and number of round trips / network connections during execution of a given command.


Added 09-06-2009:
Example imaginary output for mentioned above solution of network version of time command could look like the following:

$ ntime git clone -q git://git.example.com/repo.git
...
bytes sent: nnn (nn kiB), bytes received: nnn (nn kiB), avg: nn.nn KB/s
nn reads, nn writes

Note that it is only an example output, detailing kind of information one might want to get.


Added 09-06-2009:
It looks like some of what I want can be acheived using dummynet, tool (originally) for testing networking protocols...

解决方案

If I am understanding you correctly, you are basically interested in something like Linux 'strace' (Introduction) for network-specific system calls?

Possibly a combination of a profiler and a debugger, for network applications (i.e. 'ntrace'), providing a detailed analysis of various optional measurements?

Under Linux, the strace utility is largely based on functionality that is provided by the Linux kernel, namely the ptrace (process tracing) API:

Using ptrace, it should be possible to obtain most of the data that you're interested in.

On Windows, you'll probably want to look into detours in order to intercept/redirect Winsock API calls for inspection/benchmarking purposes.

If you don't really need all that much low level information, you can probably also directly use strace (on linux) and only use it to trace certain system calls, for example consider the following line which would only trace calls to the open syscall (Using the additional -o FILE parameter, you can redirect all output to an output file):

strace -e trace=open -o results.log

By passing an additional -v flag to strace, you can increase its verbosity to get additional information (when working with SCMs like git that are composed of many smaller shell utilities and standalone tools, you'll probably also want to look into using the -f flag in order to also follow forked processes).

So, what you would be interested in, is all syscalls that are related to sockets, namely:

  • accept
  • bind
  • connect
  • getpeername
  • getsockname
  • getsockopt
  • listen
  • recv
  • recvfrom
  • send
  • sendto
  • setsockopt
  • shutdown
  • socket
  • socketpair

(in the beginning, you'll probably only want to look into dealing with the send.../recv... calls, though)

To simplify this, you can also use "network" as parameter to trace, which will trace all network-related calls:

-e trace=network: Trace all the network related system calls.

So, a corresponding strace invocation could look like this:

strace -v -e trace=accept,bind,connect,getpeername,getsockname,getsockopt,listen,recv,recvfrom,send,sendto setsockopt,shutdown,socket,socketpair -o results.log -f git pull

When the program is finished running, you'll then mainly want to examine the log file to evaluate the data, this can then be easily achieved by using regular expressions.

For example, when running the following in a linux shell: strace -v -o wget.log -e trace=connect,recv,recvfrom,send,sendto wget http://www.google.com

The resulting log file contains messages like these:

  • recv(3, "HTTP/1.0 302 Found Location: htt"..., 511, MSG_PEEK) = 511
  • sendto(4, "242613^206*J"..., 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20

Looking at the man pages for these two system calls, it's obvious that 511 and respectively 20 are the number of bytes that are transferred. If you also need detailed timing information, you can pass the -T flag to strace:

-T -- print time spent in each syscall

In addition, you can get some statistics by passing the -c flag:

-c: Count time, calls, and errors for each system call and report a summary on program exit. On Linux, this attempts to show system time (CPU time spent running in the kernel) independent of wall clock time. If -c is used with -f or -F (below), only aggregate totals for all traced processes are kept.

If you also need to examine the actual data processed, you may want to look into the read/write specifiers:

-e read=set: Perform a full hexadecimal and ASCII dump of all the data read from file descriptors listed in the specified set. For example, to see all input activity on file descriptors 3 and 5 use -e read=3,5. Note that this is independent from the normal tracing of the read(2) system call which is controlled by the option -e trace=read. -e write=set: Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the specified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.

You can also customize the max length of strings:

-s strsize: Specify the maximum string size to print (the default is 32). Note that filenames are not considered strings and are always printed in full

Or have strings be dumped as hex:

-xx: Print all strings in hexadecimal string format.

So, using strace for much of this, seems like a good hybrid approach, because it is very easy to do, but still there's a good amount of low level information available, if you find that you need additional low level information, you may want to consider extending strace instead or filing corresponding feature requests with the strace project on sourceforge.

However, thinking some more about it, a less involved and more platform-agnostic way of implementing a fairly simple network traffic benchmark, would be to use some form of intermediate layer, in between the client and the actual server: a server that's basically metering, analyzing and redirecting the traffic to the real server.

Pretty much like a proxy server (e.g SOCKS), so that all traffic is tunneled through your analyzer, which can in turn accumulate statistics and other metrics.

A basic version of something like this could probably be easily put together just by using netcat and some shell scripts, more complex versions may however benefit from using perl or python instead.

For a python implementation of a SOCKS server, you may want to look into pysocks.

Also, there's of course twisted for python:

Twisted is an event-driven networking engine written in Python and licensed under the MIT license.

If you do need to have more low level information, you'll probably really want to look into intercepting system calls, though.

If you also need protocol-specific efficiency data, you might want to look into tcpdump.

这篇关于如何测量网络性能(如何对网络协议进行基准测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆