Search code examples
performancerestclientrestlet

How to speed up the restlet client to get response?


I use restlet client to send rest request to the server.

public class RestHandler {
    protected ClientResource resource       = null;
    protected Client         client         = null;

    public void connect(final String address,
                       final Protocol protocol){
        final Context context = new Context();
        if (client == null) {
            logger.info("Create Client.");
            client = new Client(context, protocol);
        }
        resource = new ClientResource(context, new Reference(protocol, address));
        resource.setNext(client);
        resource.setEntityBuffering(true);
    }
}

In its child class, use resource.get()/post/put/delete to send rest request.

I found the response come back so slow at the first time(5-10s).

And then it go faster in the next few requests.

But after waiting about 10min I send the request again, it become slow again.

Is there any way to make the response come back faster?


Solution

  • You can try to use another client connector. It can be the cause of your problem, especially if you use the default one. Notice that the default one should be used for development only.

    This page gives you all the available client connectors: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/base/connectors.

    Regarding client connectors, you can configure properties to tune them. To use a client connector, simply put the corresponding Restlet extension within your classpath. Perhaps can you make a try with the extension org.restlet.ext.httpclient.

    This answer could help you regarding connector configuration and properties: Restlet HTTP Connection Pool.

    Hope it helps you, Thierry