有没有办法在 Java RMI 调用中引入假延迟?
我想要诊断当我的客户端与世界另一端的服务器通信时发生的瓶颈。我想在本地计算机上运行服务器并模拟延迟。有没有办法可以在所有远程调用中注入短暂的线程睡眠?我不确定哪个远程调用是瓶颈,所以我需要将它们全部延迟。
第二次尝试澄清:我不想将线程睡眠复制粘贴到每个远程方法中,因为有很多很多远程方法。我正在尝试找到一种方法将睡眠注入 RMI 子系统,以便所有通过 RMI 的调用都会被延迟。
In want to diagnose a bottleneck which happens when my client is talking to a server on the other side of the world. I'd like to run the server on my local machine and simulate the latency. Is there a way I can inject a brief thread-sleep in all remote calls? I'm not sure which remote call is the bottleneck, so I need to delay them all.
Second attempt to clarify: I don't want to copy-paste thread sleeps into every single remote method, because there are lots and lots of remote methods. I'm trying to find a way to inject a sleep into the RMI subsystem so all calls over RMI will be delayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
WANem 就是为了做到这一点而设计的。它在网络级别工作,因此不是 Java 或 RMI 特定的。
WANem is designed to do just that. It works at the network level so isn't Java- or RMI-specific.
Charles 代理服务器有一项功能,可以向连接添加限制/延迟:
http:// www.charlesproxy.com/documentation/proxying/throtdling/
我对 Charles 非常满意——非常值得花 50 美元购买一个许可证。
The Charles Proxy server has a feature where it can add throttling/latency to a connection:
http://www.charlesproxy.com/documentation/proxying/throttling/
I have been very pleased with Charles -- well worth the $50 for a license.
你能写一个代理服务器吗?客户端与代理通信,代理对服务器进行相同的方法调用。这样您就可以重新配置客户端,但不需要更改代码。代理可以添加延迟并记录呼叫和响应。
Can you write a proxy server? The client talks to the proxy, the proxy makes the same method call to the server. This way you reconfigure the client but don't need to change the code. The proxy can add delays and log the calls and response.
有一个适用于 Windows 的应用程序,称为 SoftPerfect Connection Emulator。模拟延迟以及必要时的损失或带宽限制。请参阅http://www.softperfect.com/products/connectionemulator/
There is an application for Windows called SoftPerfect Connection Emulator. Simulates latency and if necessary losses or bandwidth limit. See http://www.softperfect.com/products/connectionemulator/
可以通过调用 setSocketFactory。
Latency could be introduced by implementing and injecting your own RMISocketFactory via calling setSocketFactory.