File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to simulate slow server connections?

 
Michael Murphy
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 312
Java MS IE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic