如何在运行时测量网络吞吐量 [英] How to measure network throughput during runtime

查看:369
本文介绍了如何在运行时测量网络吞吐量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在运行时最好地衡量网络吞吐量。我正在编写客户端/服务器应用程序(都在java中)。服务器定期通过套接字向客户端发送(压缩媒体数据的)消息。我想调整服务器使用的压缩级别以匹配网络质量。

I'm wondering how to best measure network throughput during runtime. I'm writing a client/server application (both in java). The server regularly sends messages (of compressed media data) over a socket to the client. I would like to adjust the compression level used by the server to match the network quality.

所以我想测量一大块数据的时间(比如说500kb)需要完全接触客户,包括两者之间的所有延迟。像Iperf这样的工具似乎不是一个选项,因为他们通过创建自己的流量进行测量。

So I would like to measure the time a big chunk of data (say 500kb) takes to completely reach the client including all delays in between. Tools like Iperf don't seem to be an option because they do their measurements by creating their own traffic.

我能想到的最好的想法是:以某种方式确定客户端和服务器的时钟差异,包括服务器发送每条消息的时间戳,然后让客户端向服务器报告此时间戳与客户端收到消息的时间之间的差异。然后,服务器可以确定消息到达客户端所花费的时间。

The best idea I could come up with is: somehow determine the clock difference of client and server, include a server send timestamp with each message and then have the client report back to the server the difference between this timestamp and the time the client received the message. The server can then determine the time it took a message to reach the client.

有更简单的方法吗?有没有这个库?

Is there an easier way to do this? Are there any libraries for this?

推荐答案

一个简单的解决方案:

在发送定义数量的包之前,在服务器上保存时间戳。

Save a timestamp on the server before you send a defined amount of packages.

然后将包发送到客户端,让客户端报告回服务器收到最后一个包裹。

Then send the packages to the client and let the client report back to the server when it has recieved the last package.

当客户回答时,在服务器上保存一个新的时间戳。

Save a new timestamp on the server when the client has answered.

所有你现在需要确定RTT并从两个时间戳之间的差值中减去RTT / 2.

all you need to to now is determine die RTT and substract RTT/2 from the difference between the two timestamps.

这应该可以让您获得相当准确的测量结果。

This should get you a fairly accurate measurement.

这篇关于如何在运行时测量网络吞吐量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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