java - 如何测量单向延迟?

标签 java networking latency

我想测量吞吐量从我的客户端到我的服务器所花费的时间。目前我只能测量完整的行程(从客户端到服务器再回到客户端)我可以通过测量我们发送数据包之前的时间和我们从服务器接收回来的时间来测量它。从技术上讲,如果我要划分整个行程时间,我会得到每个单程吞吐量的平均值。

但是,如果某些吞吐量实际上像这样需要更长的时间才能到达怎么办:

enter image description here

在我创建的图像中,从客户端到服务器的吞吐量是 30 毫秒,从服务器到客户端是 90 毫秒。如果数据有这样的到达率,那么测量整个往返行程并将其除以 2 将不会给出准确的单向到达时间。如何准确测量单程到达时间?

最佳答案

How can i accurately measure one-way arrival times

TL;DR - 你不能

这实际上是一个非常深刻的哲学问题,在物理学的核心(宇宙的底层“金属”)中没有答案。物理学并不明确知道光的单向速度,只知道双向速度。迄今为止,我们设计的任何实验都无法回答这个问题。参见 The One-Way Speed of Light .

Although the average speed over a two-way path can be measured, the one-way speed in one direction or the other is undefined (and not simply unknown), unless one can define what is "the same time" in two different locations. To measure the time that the light has taken to travel from one place to another it is necessary to know the start and finish times as measured on the same time scale. This requires either two synchronized clocks, one at the start and one at the finish, or some means of sending a signal instantaneously from the start to the finish. No instantaneous means of transmitting information is known. Thus the measured value of the average one-way speed is dependent on the method used to synchronize the start and finish clocks. This is a matter of convention.

您可以通过同步时钟在非相对论情况下任意接近,但您如何知道时钟保持同步?对于您的情况,您必须同意在同一时间信号上同步,但传播延迟会引入数十到数百毫秒的延迟和抖动。

因此,如果您想将单向时间确定为低于时钟抖动的准确度,那您就不走运了。这是我的一个 Linux 系统上 ntpq peer 的输出。

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*unifi.versadns. 71.66.197.233    2 u  289 1024  377    2.298   -0.897   0.747
+eterna.binary.n 68.97.68.79      2 u  615 1024  377   42.258   -3.640   0.430
+homemail.org    139.78.97.128    2 u  160 1024  377   45.257   -0.209   0.391
-time.skylineser 130.207.244.240  2 u  418 1024  103   24.829    2.066   1.376

如果两个系统使用相同的主时钟进行同步并且有足够的时间使延迟和抖动稳定下来,您可能能够将单向时间限制在 5 毫秒以内。

关于java - 如何测量单向延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66554023/

相关文章:

java - 将 double 组列表转换为整数数组列表

c++ - setsockopt 返回 -1 : errno is set to 0

parallel-processing - MPI 延迟测量

java - 我如何通过 servlet 将文件上传到带有 blob 对象的数据库中

java - 读写锁保护映射上的缓慢迭代 : read lock, 并发映射或复制?

ubuntu - 在虚拟机上使用 Netem 延迟数据包

perl - 是否有一些关于 Perl 网络编程的最新教程?

debian - 这种延迟的来源是什么?

java - 在低延迟应用程序中处理大整数

java - 如何在 iOS 上使用 appium 查找应用程序版本