可能会减慢Java虚拟机的时间吗?
是否可以通过修改OpenJDK的源代码来根据CPU使用情况来减慢Java虚拟机中的时间?我有一个网络模拟(Java 到 ns-3),它消耗实时时间,与挂钟松散同步。然而,由于我在模拟中运行了如此多的客户端,CPU 使用率达到 100%,并且无法保证模拟器中的事件应花费多长时间来处理(即大量超延迟事件)。因此,当网络流量很大时,模拟在大约 40 个节点时达到顶峰,但即便如此,还是有点不确定。理想的解决方案是根据 CPU 减慢时间,但我不确定如何成功地做到这一点。一个较小的解决方案是将时间减慢一些倍(时间透镜?)。
如果有人可以提供一些指导,相关文件的源代码(适用于 Windows)位于 http://pastebin.com /RSQpCdbD。我尝试修改文件的某些部分,但结果并不是很成功。
预先感谢,
克里斯
Is it possible to slow down time in the Java virtual machine according to CPU usage by modification of the source code of OpenJDK? I have a network simulation (Java to ns-3) which consumes real time, synchronised loosely to the wall clock. However, because I run so many clients in the simulation, the CPU usage hits 100% and hard guarantees aren't maintained about how long events in the simulator should take to process (i.e., a high amount of super-late events). Therefore, the simulation tops out at around 40 nodes when there's a lot of network traffic, and even then it's a bit iffy. The ideal solution would be to slow down time according to CPU, but I'm not sure how to do this successfully. A lesser solution is to just slow down time by some multiple (time lensing?).
If someone could give some guidance, the source code for the relevant file in question (for Windows) is at http://pastebin.com/RSQpCdbD. I've tried modifying some parts of the file, but my results haven't really been very successful.
Thanks in advance,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看
VirtualBox
,它允许您从命令行加速或减慢访客时钟。You might look at
VirtualBox
, which allows one to Accelerate or slow down the guest clock from the command line.我不完全确定这是否是您想要的,但是使用 Joda-time 库,您可以完全停止时间。因此,在 Joda 时间内调用 new Date() 或 new DateTime() 将连续返回相同的时间。
因此,您可以在一个线程中通过此调用“停止时间”:
然后您的线程可以休眠 5000 毫秒,然后调用:
因此,只要您的应用程序根据系统内的时间执行其操作,这将“通过将时间每 5 秒向前推进一秒来设置“慢”时间。
但是,正如我所说......我不确定这是否适用于您的环境。
I'm not entirely sure if this is what you want but, with the Joda-time library you can stop time completely. So calls to new Date() or new DateTime() within Joda-time will continously return the same time.
So, you could, in one Thread "stop time" with this call:
Then your Thread could sleep for, say, 5000ms, and then call:
So provided you application is doing whatever it does based on the time within the system this will "slow" time by setting time forwards one second every 5 seconds.
But, as i said... i'm not sure this will work in your environment.