Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Distributed Java and the fly likes How to simulate slow server connections? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "How to simulate slow server connections?" Watch "How to simulate slow server connections?" New topic
Author

How to simulate slow server connections?

Michael Murphy
Greenhorn

Joined: Jan 14, 2011
Posts: 5
I am trying to write a bogus server to run on one particular box, which simply wastes time accepting connections to simulate a bogged down box:




I have a test client that takes the current system in millis, and opens a socket to this guy above, and then closes it and gets the time for the socket.accept() above to actually happen.

Here is the problem: The stupid server does NOT actually sleep before accepting the next connection despite the obvious Thread.sleep() call above. (Assume good value for sleepTime).

Why does it not actually sleep between accepting connections and make the client wait to set up the TCP connection?

Michael Murphy
Greenhorn

Joined: Jan 14, 2011
Posts: 5
I have noticed that the socket open times to this server CORRELATE but do not match the expected times based on the Thread.sleep above.
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

You may try the following.
* Use an ArrayList<Socket> to store all the connections from the clients
* Write a Thread that will sleep for the duration you require and when it awakes, removes the topmost connection, releases it and goes back to sleep for an increasingly longer duration. Repeat this cycle until there are no more connections.
You may observe that, the server will begin to slow down in responding.


S.D. MADHAN
Not many get the right opportunity !
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hello Michael,

you can use this little free tool to simulate network latency. You can then let your client simply connect to the tool and the tool to the server.
the tool will handle the latency as you configure it.

ZIP: TMnetSim Network Simulator version 2.4 for x64 (600KB)
I have found this to be very useful.
Hope it helps you too!


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
 
 
subject: How to simulate slow server connections?