我只是在ES中创建连接的以下方法:
public static Client getClient() {
if (client == null) {
synchronized (mutex) {
settings = ImmutableSettings.settingsBuilder().put(CONFIG_CLUSTER_NAME, CLUSTER_NAME).build();
client = new TransportClient(settings);
for (String address : transportAddress ) {
((TransportClient) client).addTransportAddress(new InetSocketTransportAddress(address, transportPort));
}
logger.info("Elastic search client initialized");
}
}
logger.info("Returning the existing client");
return client;
}
但对于这个应用程序,当我在该主机上运行netstat时,我看到了很多打开的连接:
tcp 0 0 ::ffff:*.*.*.*:59380 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:48829 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:42944 ::ffff:*.*.*.*:9300 TIME_WAIT -
tcp 0 0 ::ffff:*.*.*.*:42838 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:8080 ::ffff:*.*.*.*:57649 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:55154 ::ffff:*.*.*.*:3306 ESTABLISHED 6552/java
tcp 0 1 ::ffff:*.*.*.*:36889 ::ffff:*.*.*.*:9300 FIN_WAIT1 -
tcp 0 0 ::ffff:*.*.*.*:42829 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:37169 ::ffff:*.*.*.*:9300 TIME_WAIT -
tcp 0 0 ::ffff:*.*.*.*:59390 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:58283 ::ffff:*.*.*.*:9300 TIME_WAIT -
tcp 0 0 ::ffff:*.*.*.*:59383 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 0 ::ffff:*.*.*.*:55855 ::ffff:*.*.*.*:9300 TIME_WAIT -
tcp 0 0 ::ffff:*.*.*.*:48823 ::ffff:*.*.*.*:9300 ESTABLISHED 6552/java
tcp 0 1 ::ffff:*.*.*.*:36884 ::ffff:*.*.*.*:9300 FIN_WAIT1 -
我已经删除了IP ....但是还有更多的打开连接。
问题:
如何手动关闭所有这些连接?
连接创建是否有错误?
有时,即使ES正在运行并且也是从java应用程序创建连接,它也不会从ES获得任何响应。重新启动java应用程序后,它返回同一查询的结果。感觉就像现有的连接已经成为现实。因此,当我重新启动应用程序时,它会创建一个新连接。我又开始回复了。过了一会儿,一旦停止。我该如何分析?
答案 0 :(得分:1)
Elasticsearch为每个节点创建多个连接(这在服务器 - 客户端应用程序中非常常见)。
在早期的ES版本中,有三种不同的连接类:
然后添加了ping,现在ES有5种类型的连接(你可以检查它们here):
使用配置前缀 transport.connections_per_node 的设置创建传输客户端时,可以控制每个节点的每个连接数。因此,例如,您可以使用transport.connections_per_node.reg
更改用于常规操作的通道数答案 1 :(得分:0)
通过
连接Elastic搜索和Java的简单方法Client desclient=null;
//应用弹性搜索设置
Settings settingsdesc = ImmutableSettings.settingsBuilder().put("cluster.name","esclustername").build(); desclient = new TransportClient(settingsdesc).addTransportAddress(new InetSocketTransportAddress("xx.xx.xx.xx",9300));
//终止连接
desclient.close();