弹性搜索请求的高延迟

时间:2017-07-11 17:02:39

标签: elasticsearch indexing time latency

我正在使用传输客户端来索引数据。这是一个小型测试程序:

@Test
public void LatencyTest() throws Exception {
    // warmup
    for (int i = 0; i < 10; i++) {
        client.prepareGet("ts_head", "doc", "latency_test_id").get();
    }

    List<Long> times = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        final long t1 = System.nanoTime();
        final IndexResponse response = client.prepareIndex("ts_head", "doc", "latency_test_id").setSource("{}", XContentType.JSON).get();
        final long t2 = System.nanoTime();
        times.add(t2 - t1);
    }
    final double average = times.stream().mapToLong(v -> v).average().getAsDouble();
    System.out.println("Average time: " + (average / 1_000_000f) + "ms");
}

输出为:Average time: 79.3905588ms,看起来非常慢。它通过具有千兆位连接的本地网络访问由2个节点(均为主节点)组成的集群。网络本身似乎没有高延迟:

$ ping -U 172.***
PING 172.*** (172.***) 56(84) bytes of data.
64 bytes from 172.***: icmp_seq=1 ttl=128 time=0.324 ms
64 bytes from 172.***: icmp_seq=2 ttl=128 time=0.280 ms
64 bytes from 172.***: icmp_seq=3 ttl=128 time=0.348 ms
64 bytes from 172.***: icmp_seq=4 ttl=128 time=0.306 ms

通过HTTP索引也很慢:

$ curl -w "@curl-format.txt" -X POST -s "http://172.***:9200/ts_head/doc/latency_test_id" --data '{}'
{"_index":"ts_head","_type":"doc","_id":"latency_test_id","_version":211,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false}    time_namelookup:  0,001381
       time_connect:  0,135607
    time_appconnect:  0,000000
   time_pretransfer:  0,136056
      time_redirect:  0,000000
 time_starttransfer:  0,283840
                    ----------
         time_total:  0,284044

现在我的问题是:我做错了什么? Elasticsearch肯定能够更快地编制索引,对吗?

为了进行测试,我还读取了数据,并报告了"took": 1,但仍然过于持续超过100毫秒才能通过curl响应。

0 个答案:

没有答案