英文:
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 SolrClient
s 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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论