什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

huangapple go评论66阅读模式
英文:

What launches the Connection evictor thread and what can be done to avoid these threads to accumulate?

问题

我的Java程序在Linux下运行,使用SOLR 7.4索引多个目录(通过Samba从不同的Windows服务器挂载)。它逐个更新不同的索引(每个索引对应一个被索引的目录),并无限循环。

在我的开发机上运行时,我使用VisualVM连接了它,并发现线程数量不断增加:

什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

根据这篇帖子,我理解这与内存泄漏有关(我也在试图找到内存泄漏问题)。

VisualVM显示连接清除线程不断累积,并且全部处于睡眠状态:

什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

但是这篇帖子指出,睡眠线程不会对系统增加任何负载(因为它们是空闲的),因此它们不会引起内存泄漏。

所以我的问题是:

我应该将这种行为视为一个问题吗?如果是这样,在源代码中我应该查看哪些部分?因为我不使用HTTP连接(我已阅读使用连接清除器的部分),因为所有目录都是通过操作系统本地挂载的。

非常感谢任何帮助 什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

英文:

My Java program runs under linux and indexes several directories (that are mounted via samba from different windows servers) with SOLR 7.4. It updates the different indexes (one index per indexed directory) one after the other and loops back infinitely.

While running on my dev machine I attached VisualVM to it and saw that the number of threads keeps increasing :

什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

I understand from this post that it has something to do with memory leak (that I am also trying to find).

VisualVM shows that Connection evictor threads keep accumulating and are all in sleeping state :

什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

But this post tells that sleeping threads won't add any load to the system (because they are idle), so they will not cause memory leak.

So my questions are :

Should I consider this behaviour as a problem, and if so where should I look at in the source code since I don't use http connection (which I read uses connection evictor) as all directories are locally mounted by the OS ?

Any help appreciated 什么启动了连接清理线程,有什么方法可以避免这些线程的累积?

答案1

得分: 1

简要回答我的问题:

是的,在生产环境中拥有这么多连接驱逐线程是一个问题,因为我认为这在一段时间后导致了内存溢出。

对我来说,问题是因为我创建了太多的 SolrClient,而实际上只需要一个(所有的核心都在同一台服务器上)。

因此,代替之前的代码:

solrClient = new HttpSolrClient.Builder(
                getSolrHomePath() + "/"+ getCoreName()
        ).
                build();

其中 getSolrHomePath() 返回路径到 solr-X.Y.Z/server/solr

我现在使用

commonSolrClient = new HttpSolrClient.Builder(
                getSolrHomePath() 
        ).
                build();

当我需要对一个核心进行 query 时,我将核心名称作为第一个参数传递给 query 函数。添加/删除方法也是一样的!

英文:

To answer my own question briefly :

Yes having so many Connection Eviction threads is a problem on production since I assume it caused an OOM after a while.

For me the problem occured because I created too many SolrClients whereas a single one was needed (all the cores are on the same server).

So instead of

solrClient = new HttpSolrClient.Builder(
                getSolrHomePath() + "/" + getCoreName()
        ).
                build();

where getSolrHomePath() returns the path to solr-X.Y.Z/server/solr.

I now use

commonSolrClient = new HttpSolrClient.Builder(
                getSolrHomePath() 
        ).
                build();

and when I need to query a core I pass the core name as first parameter to the query function. Same for add/delete methods!

huangapple
  • 本文由 发表于 2020年8月14日 21:51:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63414102.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定