UI에서 버튼을 누를 때마다 탄성 검색에 연결되고 쿼리가 실행되는 웹 서비스가 있습니다. 이것은 매번 실행되는 코드입니다. 문제는 잠시 후 간헐적으로 UI가 중단된다는 것입니다. 우리는 Tomcat 서버를 재시작 할 때마다elasticsearch에서 Threadlocals와 관련된 메모리 누수 관련 문제
private static final String CONFIG_CLUSTER_NAME = "cluster.name";
private static final String CLUSTER_NAME = "sample_es";
private static final String[] transportAddress = {
//Machine details
};
private static final int transportPort = 9300;
public static Client initClient(){
settings = ImmutableSettings.settingsBuilder().put(CONFIG_CLUSTER_NAME, CLUSTER_NAME).build();
Client client = new TransportClient(settings);
for (int i=0 ; i < transportAddress.length-1 ; i++){
((TransportClient)client).addTransportAddress(new InetSocketTransportAddress(transportAddress[i], transportPort));
}
logger.info("TransportClient Created");
return client;
}
public static int query(String query) throws Exception
{
Client client = null;
try{
client = initClient();
//Query search code
}catch(Exception e){
e.printStackTrace();
}finally{
if(client != null){
client.close();
logger.info("TransportClient Closed");
}
}
return result_count;
}
, 이것은 우리가 로그에보고 된 오류 메시지입니다. 어떻게 해결해야합니까?
[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom$1] (value
[org.e[email protected]5838ce3e]) and a value of type
[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom] (value
[org[email protected]796c75b1]) but failed to remove it
when the web application was stopped. This is very likely to create a memory leak.
그것 때문에 무슨 일이 일어나고 :
관련없는 있지만, 모든 Elasticsearch
Client
들AutoCloseable
을 구현 당신이 것을 일을 계속하기를 원한다면 당신이 그것을 를 자동 종료하는 코드를 단순화 할 수있는 의미 (자바 7에서 추가) 우리는 모든 쿼리에 대해 새 클라이언트를 만들고 닫습니다. [https://github.com/elasticsearch/elasticsearch/issues/283](https://github.com/elasticsearch/elasticsearch/issues/283) 하나의 연결로 영원히 해결할 수 있습니까? 몇 시간 동안 아무도 그것을 사용하지 않더라도 ES 연결은 계속 유지됩니까? 아니면 부실해 집니까? 그래서 내가 매번 만들고 닫는 이유입니다. –클라이언트를 열린 상태로 유지하는 것이 좋습니다. – pickypg