简体   繁体   English

如何加快Restlet客户端获得响应?

[英]How to speed up the restlet client to get response?

I use restlet client to send rest request to the server. 我使用restlet客户端将休息请求发送到服务器。

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. 在其子类中,使用resource.get()/ post / put / delete发送休息请求。

I found the response come back so slow at the first time(5-10s). 我发现响应在第一时间(5-10秒)回复得如此之慢。

And then it go faster in the next few requests. 然后在接下来的几个请求中它运行得更快。

But after waiting about 10min I send the request again, it become slow again. 但是,等待约10分钟后,我再次发送了请求,请求再次变慢。

Is there any way to make the response come back faster? 有什么方法可以使响应更快地返回?

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 . 该页面为您提供了所有可用的客户端连接器: 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. 要使用客户端连接器,只需将相应的Restlet扩展名放在类路径中即可。 Perhaps can you make a try with the extension org.restlet.ext.httpclient . 也许您可以尝试使用扩展名org.restlet.ext.httpclient

This answer could help you regarding connector configuration and properties: Restlet HTTP Connection Pool . 该答案可以帮助您了解连接器的配置和属性: Restlet HTTP连接池

Hope it helps you, Thierry 希望对您有帮助,蒂埃里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM