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!

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top