we are using open search java client 2.14.0 , we are observing that in heap memory the response are getting retained -org.opensearch.client.transport.httpclient5.internal.HeapBufferedAsyncEntityConsumer . Earlier after every request the memory used to come down but now it is gradually climbing and finally it forces microservices to restart
This is very weird but it looks like the response is never being consumed? Could you please share the snippet(s) how the client is being used? Thank you
List<Hit<Map<String,Object>>> hits = response.hits().hits(); return hits.stream() .map(hit → { Map<String, Object> data = Optional.ofNullable(hit.source()).orElse(new HashMap<>()); data.put(“_id”, hit.id()); return data; }) .map(map → replaceKey(map, request)).collect(Collectors.toList());
This is how we are reading the response
this is the common function we call to get the response please find below the triggering code
SearchResponse<Map<String,Object>> searchResponse = elasticSearchClient.search(searchRequest);
after consuming the data we are directly freeing the memory by setting searchResponse as null
searchResponse = null;
as per our use case we can’t a predefined dto as we have 10 different index with grouping response so that is why we are taking it to map . we are converting it to map but we are freeing it up after the useage
reta is there an explicit way to free up memory held by the response , we searched the documentation couldn’t find anyting . client.close will free it up but we would like to get something which would explictly clear the memory after every search
Thanks reta we can try that option couple of querries
is there any GC specific options need to be set for better performance
java client currently it is singleton it would be closed only when the microservice is pull down . we are thinking about testing the behavior by opening new client per request and after processing the responsewe are thinking about closing it would it creates any performance issue