Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分页查询totalCount过大造成OOM #62

Closed
xiejinsong opened this issue Sep 5, 2022 · 5 comments
Closed

分页查询totalCount过大造成OOM #62

xiejinsong opened this issue Sep 5, 2022 · 5 comments
Labels

Comments

@xiejinsong
Copy link

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList.(ArrayList.java:153)
at com.ejlchina.searcher.SearchResult.(SearchResult.java:32)
at com.ejlchina.searcher.implement.DefaultBeanSearcher.search(DefaultBeanSearcher.java:69)
at com.ejlchina.searcher.implement.DefaultBeanSearcher.search(DefaultBeanSearcher.java:32)

/**
 * Constructs an empty list with the specified initial capacity.
 *
 * @param  initialCapacity  the initial capacity of the list
 * @throws IllegalArgumentException if the specified initial capacity
 *         is negative
 */
public ArrayList(int initialCapacity) {
    if (initialCapacity > 0) {
        this.elementData = new Object[initialCapacity];
    } else if (initialCapacity == 0) {
        this.elementData = EMPTY_ELEMENTDATA;
    } else {
        throw new IllegalArgumentException("Illegal Capacity: "+
                                           initialCapacity);
    }
}
@troyzhxu
Copy link
Owner

troyzhxu commented Sep 8, 2022

totalCount 不会造成 OOM,每页查询条数太大才可能会。

@xiejinsong
Copy link
Author

3.6版分页查询初始化SearchResult并没有初始化dataList长度,升级到3.8.1初始化SearchResult会初始化dataList长度大小为totalCount,ArrayList内部初始化数组会占用16 + totalCount * 4

SearchResult result = new SearchResult<>(totalCount, summaries);
BeanMeta beanMeta = searchSql.getBeanMeta();
SqlResult.ResultSet listResult = sqlResult.getListResult();

public SearchResult(Number totalCount, Number[] summaries) {
this(new ArrayList<>(totalCount.intValue()));
this.totalCount = totalCount;
this.summaries = summaries;
}

@troyzhxu troyzhxu added the bug label Sep 16, 2022
@troyzhxu
Copy link
Owner

多谢反馈,马上修复

@troyzhxu
Copy link
Owner

troyzhxu commented Sep 16, 2022

这是 v3.8.1 出现的 BUG, v3.8.2 已发布,修复了该问题。

@xiejinsong
Copy link
Author

感谢,前段时间适配到aliyun ots多元索引,大大提升了开发效率。最近打算参考cube.js,将beansearcher做成olap引擎与前端的粘粘层。很棒~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants