ElasticSearchのTransportClient 5.4.3にメモリリークがありますか?または、オブジェクトを正しく使用して閉じていないのですか?ElasticSearchのTransportClient 5.4.3にメモリリークがありますか?またはコードに欠陥がありますか?
JRE 1.8.0_66上にあるJenkins(2.68)のクライアントを使用していて、Groovyで自分のコードを書いています。 BulkRequestBuilder
が複数のレコードを送信するために使用されています。コード全体
、これらの4倍の16MBバイト配列は、メモリ内に表示されますが、でもTransportClient.close()メソッドを過ぎて閉じない飽きない:私はもっとゆっくりコードをステップ実行した場合、私はの9Xまで得ることができます https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.htmlここ
は、私が使用しているコードの下にトリミングされたバージョンです:
私は、私は完全に公式ドキュメントを以下だと考えている:
これらの16メガバイトは、そのうちのいくつかは非常に似て、アレイのバイト私が使用しているオブジェクトから@Grapes([
@Grab(group = "org.apache.logging.log4j", module = "log4j-api", version = "2.8.2", initClass = true),
@Grab(group = "org.apache.logging.log4j", module = "log4j-core", version = "2.8.2", initClass = true),
@Grab(group = "org.elasticsearch.client", module = "transport", version = "5.4.3", initClass = true)
])
public class ElasticSearchReport implements Serializable {
pubblic void execute() {
// Data to report.
List<Map<String, Object>> data = ...
// ElasticSearch settings. Do not use sniffing because we want to upload data to the master node.
Settings settings = Settings.builder()
.put("cluster.name", "my-cluster")
.put("client.transport.sniff", false)
.build()
PreBuiltTransportClient preBuiltTransportClient = new PreBuiltTransportClient(settings)
TransportClient client = preBuiltTransportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("my-elastic-search-host"), 9300))
List<String> errors = new LinkedList<String>()
try {
BulkRequestBuilder bulkRequest = client.prepareBulk()
// Build the bulk query with each data entry.
data.each({entry ->
String serialisedEntry = SerializationUtils.toJson(entry)
bulkRequest.add(client.prepareIndex("my-index", "my-type").setSource(serialisedEntry, XContentType.JSON))
})
// Process the response.
bulkRequest.get().getItems().each({response ->
if (response.failed) {
errors.add(response.failure.message)
return
}
final String statusName = response.status().name()
// Check statusName ...
})
if (errors) throw new Exception(...)
} finally {
client.close()
preBuiltTransportClient.close()
}
}
}
、唯一PreBuiltTransportClient
とTransportClient
Closeable
を実装するので、私は明示的に私のfinally
ブロックでそれらをクローズしようとしています。
.withCloseable()
(Groovyのtry-with-resources
に相当)を使用してみましたが、問題の発生を妨げませんでした。
私はおそらく私のbulkRequest.get().getItems().each({response ->
ラインが面白いことをやっていたと思ったので、私は次のようでなく、効果なしにそれを置き換える:
BulkResponse bulkResponse = bulkRequest.get()
BulkItemResponse[] bulkItemResponses = bulkResponse.getItems()
for (int responseIndex = 0; responseIndex < bulkItemResponses.length; responseIndex++) { ... }
は私も運とBulkResponse bulkResponse = bulkRequest.execute().actionGet()
とBulkResponse bulkResponse = bulkRequest.get()
を交換しようとしました。