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

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

问题描述

首先,有一点背景知识.分布式版本控制系统(DVCS)有许多不同的比较,它们比较存储库的大小或基准操作速度.除了测量涉及"clone","pull"/"fetch"或"push"之类的网络的操作(命令)速度之外,我还没有找到能对各种DVCS的网络性能和使用的各种协议进行基准测试的任何工具. /p>

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

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

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


可能的度量标准:

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

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


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


添加了09-06-2009:
上面提到的time网络版本的网络解决方案的示例假想输出如下所示:

$ 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

请注意,这只是一个示例输出,其中详细列出了人们可能想要获得的信息.


添加了09-06-2009:
看起来可以使用 dummynet (最初用于测试网络协议的工具)实现我想要的某些功能...

解决方案

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

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

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

使用ptrace,应该可以获取您感兴趣的大多数数据.

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

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

strace -e trace=open -o results.log

通过向strace传递附加的-v标志,可以增加其详细程度以获取其他信息(当使用由许多较小的Shell实用程序和独立工具组成的git之类的SCM时,您可能还需要研究使用-f标志,以便还可以跟踪分叉的进程.

因此,您感兴趣的是与 sockets ,即:

  • 接受
  • 绑定
  • 连接
  • getpeername
  • getsockname
  • getsockopt
  • recv
  • recvfrom
  • 发送
  • 发送到
  • setsockopt
  • 关闭
  • 插座
  • socketpair

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

为简化此操作,您还可以使用网络"作为跟踪参数,它将跟踪所有与网络相关的呼叫:

-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 \ r \ n位置:htt" ...,511,MSG_PEEK)= 511
  • sendto(4,"\ 24 \ 0 \ 0 \ 0 \ 26 \ 0 \ 1 \ 3 ^ \ 206 * J \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0" ..., 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项目提交相应的功能请求.. >

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

非常类似于代理服务器(例如 SOCKS ),以便所有流量都通过隧道传输您的分析仪,然后可以累积统计信息和其他指标.

仅通过使用netcat和一些shell脚本就可以很容易地将类似的基本版本组合在一起,但是更复杂的版本可能会受益于使用perl或python.

对于SOCKS服务器的python实现,您可能需要研究 pysocks .

>

此外,当然还有扭曲了的python:

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\r\nLocation: htt"..., 511, MSG_PEEK) = 511
  • sendto(4, "\24\0\0\0\26\0\1\3^\206*J\0\0\0\0\0\0\0\0"..., 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天全站免登陆