Is there a way to introduce fake latency in Java RMI calls?
Asked Answered
L

5

5

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.

Lindsley answered 19/7, 2011 at 13:57 Comment(2)
download.oracle.com/javase/1.4.2/docs/api/java/lang/…Solent
Duh, but where do I PUT the sleep? I can't just place it in the method being executed remotely, because there are LOTS of methods being executed remotely. I don't want to sprinkle thread sleeps everywhere, because I might still miss one or two in the codepath I'm currently debugging.Lindsley
M
7

WANem is designed to do just that. It works at the network level so isn't Java- or RMI-specific.

Mesomorph answered 19/7, 2011 at 14:13 Comment(3)
+1 There's tons of programs like this. I've done this before when we needed to find out how much data we were sending over RMI as well as slow things down to speciifc speeds. You can earch for "Network/Bandwidth limiting/throttling", etcElan
Nice, I'm going to check this out in a bit.Lindsley
Turns out this is not a great solution. An entire separate PC has to be devoted to WANem (it only runs off of a Linux bootable CD). I am running both my server and my client on a Windows machine, so I was hoping for a Windows program that would run alongside them.Lindsley
M
1

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.

Macedonia answered 19/7, 2011 at 14:29 Comment(2)
This says it's only an HTTP proxy. RMI runs over a different protocol.Lindsley
Charles also does generic port forwarding.Macedonia
T
0

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.

Trimurti answered 19/7, 2011 at 14:15 Comment(5)
Mm, no, I can't think of a way to do that. My server just has a bunch of objects which implement interfaces which extend the java.rmi.Remote interface, and I call methods on those interfaces. So the proxy would have to implement ALL the same interfaces, and explicitly delegate each call to the server, so lots and lots of extra code.Lindsley
You can do this at the packet level instead. You have a plain socket which writes to a second socket what ever it reads and back again. This doesn't look at the data contained and works for any TCP protocol.Trimurti
The RMI subsystem handles that part, I don't touch the socket code.Lindsley
For the RMI client and server you would use RMI. For the proxy you would use plain TCP sockets. The proxy doesn't even need to know you are using RMI (or how many methods are being proxied)Trimurti
Okay I see what you're getting at. RMI listens on port X, proxy listens on port Y and forwards to port X, and client speaks to port Y. Hmm. As long as I forward all TCP communications I guess that would work.Lindsley
P
0

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/

Persuader answered 20/7, 2011 at 3:26 Comment(0)
W
0

Latency could be introduced by implementing and injecting your own RMISocketFactory via calling setSocketFactory.

Worthless answered 20/1, 2015 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.