performance - HttpClient 和 LocalServerTestBase 真的很慢

标签 performance testing apache-httpclient-4.x

我正在尝试对使用 HttpClient 版本 4.5 的类编写测试。我写的测试真的很慢,所以我试图找出问题所在。我可以编写一个测试来证明我的问题:

public class RequeteurRESTTest extends LocalServerTestBase {

    private String startServer(String urlSuffix, HttpRequestHandler handler) throws Exception{
        this.serverBootstrap.registerHandler(urlSuffix, handler);
        HttpHost target = start();
        String serverUrl = "http://localhost:" + target.getPort();
        return serverUrl;
    }

    @Test
    public void testCase() throws Exception{
        String baseURL = startServer("/api", new HttpRequestHandler() {
            @Override
            public void handle(HttpRequest request, HttpResponse response,     HttpContext context) throws HttpException, IOException {
                response.setStatusCode(HttpStatus.SC_OK);
            }
        });

        HttpClient httpClient;
        httpClient = HttpClients.custom().build();

        HttpGet method = new HttpGet(baseURL + "/api");
        HttpResponse response = httpClient.execute(method);
    }
}

我遇到的问题是指令:

httpClient.execute(method)

执行需要10 秒。这很慢,但我不明白为什么这么慢。我在测试中是否犯了任何错误,或者忘记了什么?

最佳答案

这很可能是因为您未对响应对象执行任何操作。至少应该关闭它。

关于performance - HttpClient 和 LocalServerTestBase 真的很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37206739/

相关文章:

c# - 是否可以记录序列化从 Web 服务返回的对象所花费的时间?

mysql - 高 CPU - 怎么办

java - 如何使用 Apache HttpClient 将参数添加到 HTTP header

java - SSL 协议(protocol)异常 : handshake alert: unrecognized_name: client-side code workaround?

java - 使用 HttpClient 4.1 解码分块数据

python : how to speed up this file loading

javascript - 监控特定的 js 事件以及作为自动化测试的一部分执行它们所花费的时间?

c# - 以编程方式创建测试

c++ - 谷歌测试框架 : is better to use shadowing or virtual methods?

reactjs - 单击 testcafe 中的到达下拉菜单