有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么我在Solr上做的每一个查询都会占用我10s MB的堆内存?

每次调用Solr服务时,我都很难理解是什么消耗了我的java堆内存:
在我的web应用程序中,我有一个调用servlet的前端,它用以下代码发送SolrQuery:

public class SolrService extends Application {
public static String url = Config.SOLR_HOST + ":" + Config.SOLR_SERVER_PORT;
final static HttpSolrServer solr = new HttpSolrServer(SolrService.url+"/"+Config.SOLR_INDEX+"/"+Config.SOLR_TYPE);

//in another class
SolrQuery query = new SolrQuery(q); 
        query.setStart(0); 
        query.setRows(limitRows);
        query.addSortField("score", ORDER.desc);
QueryResponse response;

        response = SolrService.solr.query(query,SolrRequest.METHOD.POST);
SolrDocumentList results = response.getResults();
 SolrDocument doc = results.get(i);
//the response is then extracted in maps and returned

每次我做一个请求,我的Java堆内存都会大幅增加。以下是java堆内存在0次查询完成时的屏幕: this is the minimum space the Solr server takes after a fresh restart

三(3)次询问后 The three queries called the piece of code that you saw

在尝试了core的管理页面上建议的optimize之后,堆下降了很多:初始堆的1/10: enter image description here

但这不是一个解决方案(可能是暂时的,但我不知道如何称呼它;可能通过一些URL?)
我已经看到,在查询中强制使用最大数量的结果,堆内存的增加会更小

我能做什么?我能去哪里看


共 (1) 个答案

  1. # 1 楼答案

    你的solr缓存有可能占据堆吗

    看起来是这样的:在第一次查询中增加,但在一段时间后保持不变

    因此,如果堆大小增加相同,可以运行一个带有缓存自动预热的优化。你可以尝试减少缓存设置。这是不推荐的,但只是为了找到原因

    看看这里,你可以找到堆增长的一些原因:https://wiki.apache.org/solr/SolrPerformanceProblems#How_much_heap_space_do_I_need.3F