简体   繁体   English

Java-Windows Server 2008上的MulticastSocket问题

[英]java - MulticastSocket problems on Windows Server 2008

I have a java application which uses a few MulticastSocket instances to listen to a few UDP multicast feeds. 我有一个Java应用程序,它使用一些MulticastSocket实例来侦听一些UDP多播提​​要。 Each such socket is handled by a dedicated thread. 每个此类套接字均由专用线程处理。
The thread reads each Datagram, parses it's content and writes to log (log4j) the packet's sequence id (long) and the timestamp the Datagram was received. 线程读取每个数据报,解析其内容,并将数据包的序列ID(长)和接收到数据报的时间戳记写入日志(log4j)。

When I try to run 2 instances of the same application on a Windows Server 2008 R2, with 2 * 6 cores and compare the 2 logs created by the 2 applications, I notice that quite frequently the timing of the packets isn't the same. 当我尝试在具有2 * 6内核的Windows Server 2008 R2上运行同一应用程序的2个实例,并比较由2个应用程序创建的2个日志时,我注意到,数据包的计时经常不同。

Most packets are received by the 2 apps at the same time (milis), but frequently there's a difference of about 1-7ms diff between the reception time of the same packet by the 2 apps. 两个应用程序同时接收大多数数据包(以毫秒为单位),但两个应用程序对同一数据包的接收时间通常相差约1-7毫秒。

I tried allocating more buffers in the NIC, and also made the socket read buffer bigger. 我尝试在NIC中分配更多缓冲区,并使套接字读取缓冲区更大。 In addition I tried minimizing GC runs and I also use -verbose:gc and can see that GC times and the problematic timing diff does not occur at the same time. 另外,我尝试最小化GC运行,并且我还使用-verbose:gc,可以看到GC时间和有问题的计时差异不会同时发生。 This allows me to assume that my problem isn't GC related. 这使我可以假设我的问题与GC不相关。

No drop packets problem was observed, and a bandwidth problem is not likely. 没有观察到丢包问题,也不太可能出现带宽问题。

Ideas / Opinions are welcome. 欢迎提出想法/意见。 Thanks. 谢谢。

By default Windows timer interrupt frequency is 100 Hz (1 tick per 10ms). 默认情况下,Windows计时器中断频率为100 Hz(每10毫秒1个滴答)。 It means that OS cannot guarantee that Java threads will get woken up at higher precision. 这意味着OS无法保证Java线程会以更高的精度被唤醒。

Here's an excerpt from a prominent James Holmes article about timing in Java - it could be your case: 这是摘自James Holmes著名文章的有关Java时间的摘录-可能是您的情况:

for Windows users, particularly on dual-core or multi-processor systems (and it seems most commonly on x64 AMD systems) if you see erratic timing behaviour either in Java, or other applications (games, multi-media presentations) on your system, then try adding the /usepmtimer switch in your boot.ini file. 对于Windows用户,尤其是在双核或多处理器系统上(在x64 AMD系统上最常见),如果您看到Java或系统上其他应用程序(游戏,多媒体演示)的计时行为不稳定,然后尝试在您的boot.ini文件中添加/ usepmtimer开关。

PS: by no means I'm credible in the field of Windows performance optimization, also starting from Windows 2008 HPET is supported, but how it is related to timer interrupt frequency is a mystery to me. PS:绝对不是我在Windows性能优化方面的可信度,也从Windows 2008 HPET开始受支持,但是它与计时器中断频率的关系对我来说还是个谜。

7毫秒对于6核计算机来说是非常好的结果,并且Java的漂移将比垃圾收集器启动时的漂移高得多。请不要忘记Java运行时也有它自己的开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM