用Java测量内部网络速度/带宽 [英] Measuring Internal Network Speed/Bandwidth in Java

查看:922
本文介绍了用Java测量内部网络速度/带宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用java监控内部网络的速度。我以为我可以使用两部分系统与服务器和客户端。我不需要响应时间,例如ping生成的内容,以及上传和下载的实际速度(mbps)。

I need to be able to monitor the speed of my internal network using java. I was thinking I could use a two part system with a server and a client. I do not need need response time such as what is generated with ping but and actual speed in mbps for upload and download.

我的想法是让服务器向客户端发送一个数据包或一系列数据包然后回复,然后服务器将计算这两者之间的网络速度点。有没有人知道如何实现这个?

My idea would be to have the Server send a packet or series of packets to the client which then replies and then the Server would calculate the speed of the network between those two points. Does anyone have any idea how I could implement this?

提前谢谢你。

推荐答案

嗯,这是一个有趣的问题。我希望你喜欢阅读......: - )

Hmm, an interesting problem. I hope you like reading... :-)

我很想知道如何使用监控工具。在
工作时,系统管理员在房间里只有几个大屏幕,
显示一个包含大量网络统计数据的网页,并且不断更新

I'd be interested to know how the monitoring tool would be used. At work, the sysadmins just have a couple of large screens in the room, showing a webpage containing loads of network stats, with it constantly updating.

我的描述的其余部分假定网络监控工具将是如上所述使用的
。如果你只是想在网络上的两个随机主机之间进行ad-hoc
测试,我只需使用rsync来
传输一个相当大的文件(大约1 - 2MB)。我确信还有
其他文件传输工具也可以计算传输速度。

The rest of my description assumes the network monitoring tool would be used as described above. If you just want to be able to do an ad-hoc test between two random hosts on your network, I'd just use rsync to transfer a reasonably large file (about 1 - 2MB). I'm sure there are other file transfer tools that calculate the transfer speed too.

实现此目的时,(尤其是在大型网络中),必须
,以最大限度地降低测试充斥网络的风险,从而阻碍实际使用它的人
(或程序)。你不想因为你在测试中进行
而被指责为
大幅放缓(或者更糟糕的是停电)。您的系统管理员不会感谢您...

When implementing this, (especially within a large network) you must minimise the risk that the test floods the network, hampering the people (or programs) actually using it. You don't want to be blamed for a massive slowdown (or worse, an outage) just because you were conducting a test. Your sysadmins won't thank you...

我将按照以下方式构建该工具:

I'd architect the tool in the following way:


  1. Bob是一个服务器,通过以下
    参与个人'测试':

  1. Bob is a server which participates in an individual 'test' by doing the following:


  1. Bob收到客户的请求。该请求说明客户端将要发送多少数据。

  2. 如果建议发送的数据量不是太大,请等待数据。否则Bob立即拒绝请求并结束通信。

  3. 收到所需的字节数后,回复所有接收所需的时间。 Bob终止通信。


  • Alice是显示测量结果的组件
    (通过网页或其他)。 Alice是一个长期存在的流程
    (可能是一个Web服务器),配置为定期连接到
    Bob服务器列表。对于每个配置的Bob:

  • Alice is the component that displays the result of the measurements taken (via a webpage or otherwise). Alice is a long lived process (maybe a web server), configured to periodically connect to a list of Bob servers. For each configured Bob:


    1. 向Bob发送一个请求,其中包含Alice即将发送的数据量

    2. 尽可能快地向Bob发送指定数量的数据。

    3. 等待Bob的回复,并计算网络速度。

    4. '显示'此Bob实例的结果。您可以选择
      来显示汇总结果。例如,过去20次测试中每次
      的平均结果,以消除任何异常...

    1. Send Bob a request with the amount of data Alice is about to send.
    2. Send Bob the specified amount of data, as fast as possible.
    3. Await the reply from Bob, and compute the network speed.
    4. 'Display' the result for this instance of Bob. You may choose to display an aggregate result. For example, the average result for each of the last 20 tests, to iron out any anomalies...


  • 在进行特定测试时,Alice应报告任何失败。例如。
    '无法与Bob'建立TCP连接,或'Bob
    过早终止转移'或其他任何内容......

  • When conducting a given test, Alice should report any failures. E.g. 'a TCP connection could not be established with Bob', or 'Bob prematurely terminated the transfer' or whatever else...

    将Bob服务器分散到您(可能很大的)
    网络中的战略位置,并将Alice配置为使用它们。对于Bob的每个实例,你应该配置

    Scatter Bob servers to strategic locations in your (possibly large) network, and configure Alice to go them. For each instance of Bob, you should configure


    1. 测试之间的时间间隔。

    2. '余地'(我会稍微解释一下)。

    3. 每次测试发送给Bob的数据量。

    4. Bob的地址(duh)。

    1. The time interval in between tests.
    2. The 'leeway' (I'll explain this in a bit).
    3. The amount of data to send to Bob for each test.
    4. Bob's address (duh).


  • 您希望错开给定Alice尝试的测试。你
    不希望Alice同时触发所有Bob服务器的测试,从而
    充斥你的网络,可能会给出结果偏差等等。
    允许将来在随机时间进行测试。对于
    示例,如果测试间隔是每10分钟,则配置1分钟的'余地'
    ,这意味着下一次测试可能发生在9到11
    分钟之间的任何时间。

  • You want to 'stagger' the tests that a given Alice will attempt. You don't want Alice to trigger the test to all Bob servers at once, thereby flooding your network, possibly giving skewed results and so forth. Allow the test to occur at a randomised time in the future. For example, if the test interval is every 10 minutes, configure a 'leeway' of 1 minute, meaning the next test might occur anywhere between 9 and 11 minutes' time.

    如果一次要运行多个Alice,则总
    个实例数应该很小。你拥有的Alices越多,你干扰网络的
    就越多。同样,您不希望对中断负责

    If there is to be more than one Alice running at a time, the total number of instances should be small. The more Alices you have, the more you interfere with the network. Again, you don't want to be responsible for an outage.

    Alice应在单个测试中发送的数据量应为
    小。 500KB?您可能希望给定的测试运行不超过
    10秒。如果测试时间过长,可能会让Bob超时。

    The amount of data Alice should send in an individual test should be small. 500KB? You probably want a given test to run for no more than 10 seconds. Maybe get Bob to timeout if the test takes too long.

    我故意省略了要使用的传输(TCP ,UDP,无论如何)
    ,因为根据传输你会遇到问题,而且我不知道你想要如何处理这些问题的
    。例如,您必须考虑如何使用UDP处理丢弃的数据报。你计算的
    结果是什么?你不会遇到TCP的这个问题,因为
    会自动重传丢弃的数据包。使用TCP,如果两个端点
    彼此相距很远,那么你的
    吞吐量将被人为地降低。这里有一些
    信息

    I've deliberately omitted the transport to use (TCP, UDP, whatever) because you'll get issues depending on the transport, and I don't know how you want to handle those issues. For example, you'd have to consider how to handle dropped datagrams with UDP. What result would you compute? You don't get this issue with TCP, because it automatically retransmits dropped packets. With TCP, your throughput will be artificially low if the two endpoints are far away from each other. Here's some info on it.

    如果你有耐心阅读这篇文章,我希望它有所帮助!

    If you had the patience to read this far, I hope it helped!

    这篇关于用Java测量内部网络速度/带宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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