4

Is it possible to limit bandwidth of the Tomcat server? I need it to simulate site work on slow (dial-up) Internet connection. All tests are made in localhost.

Thanks for all!

ILYA
  • 495
  • 6
  • 18

3 Answers3

2

This is easily feasible in Tomcat by creating a valve.

Create a class that extends the ValveBase class from tomcat.

The code inside should be something like that:

/**
 * {@inheritDoc}
 */
@Override
public void invoke(final Request request, final Response response) 
                   throws IOException, ServletException {

    if (randomDelay != 0) {
        long delay = minDelay + randomizer.nextInt(randomDelay);
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("sleeping for " + delay + " ms");
            }
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("someone wake me up : " + e.getMessage());
            }
        }
    }

    // let's continue !
    getNext().invoke(request, response);
}

Compile it in a jar you'll drop in the tomcat lib directory (usually {catalina.home}/lib).

Finally add the valve declaration in you server.xml:

<Server ...>
  <Service name="Catalina">
   <Engine name="Catalina" defaultHost="localhost">
     (...)
     <Host name="localhost" ...>
       <Valve className="tools.tomcat.RandomDelayValve" />

HIH

poussma
  • 7,033
  • 3
  • 43
  • 68
1

It's not possible in Tomcat, you should look somewhere outside for an HTTP proxy providing such functionality and tunnel your tests through that proxy. In worst case write such a proxy yourself, shouldn't take more than a dozen lines of code.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
1

You can do this with jmeter see this: - http://jmeter.512774.n5.nabble.com/httpclient-socket-http-cps-td524481.html

See also this:

Community
  • 1
  • 1
UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116