Solr筛选器缓存(FastLRUCache)占用太多内存并导致内存不足? [英] Solr Filter Cache (FastLRUCache) takes too much memory and results in out of memory?

查看:461
本文介绍了Solr筛选器缓存(FastLRUCache)占用太多内存并导致内存不足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Solr设置.一个主设备和两个从设备进行复制.我们索引中有大约7,000万个文档.从站具有16 GB的RAM. OS和HD为10GB,Solr为6GB.

I have a Solr setup. One master and two slaves for replication. We have about 70 Millions documents in index. The slaves have 16 GBs of RAM. 10GBs for the OS and HD, 6GBs for Solr.

但有时,从站内存不足.当我们在内存不足之前下载转储文件时,我们可以看到该类:

But from time to time, the slaves are out of memory. When we downloaded the dump file just before it was out of memory, we could see that the class :

org.apache.solr.util.ConcurrentLRUCache$Stats @ 0x6eac8fb88

正在使用多达5Gb的内存.我们广泛使用过滤器缓存,命中率为93%.这是solrconfig.xml中的过滤器缓存的xml

is using up to 5Gb of memory. We are using filter caches extensively, it has a 93% hit ratio. And here's the xml for the filter cache in solrconfig.xml

<property name="filterCache.size" value="2000" />
<property name="filterCache.initialSize" value="1000" />
<property name="filterCache.autowarmCount" value="20" />

<filterCache class="solr.FastLRUCache"
             size="${filterCache.size}"
             initialSize="${filterCache.initialSize}"
             autowarmCount="${filterCache.autowarmCount}"/>

查询结果具有相同的设置,但是使用的是LRUCache,它仅使用大约35mb的内存.需要修复的配置有什么问题,还是我只需要更多的内存用于过滤器缓存?

The query results have the same settings, but is using the LRUCache and it only uses about 35mb of the memory. Is there something wrong with the configuration which needs to be fixed, or do I just need more memory for the filter cache?

推荐答案

在一位朋友告诉我过滤器缓存的工作原理之后,很清楚为什么我们会时不时地遇到内存不足的错误.

After a friend told me how roughly the filter caches works, it become clear why we get out of memory errors from time to time.

那么过滤器缓存的作用是什么? 基本上,它会创建一个类似于位数组的东西,告诉哪些文档与过滤器匹配.像这样的东西:

So what does the filter cache do? Basically it creates something like a bit array which tell which documents matched the filter. Some something like:

cache = [1, 0, 0, 1, .. 0]

1表示命中,0表示没有命中.因此,对于该示例,这意味着筛选器缓存与第0个和第3个文档匹配.因此,高速缓存有点像一个位数组,具有总文档的长度.假设我有5000万文档,那么数组长度将为5000万,这意味着一个过滤器缓存将占用ram中的50.000.000位.

1 means it hits, and 0 means no hit. So for the example, it means the filter cache matches the 0th and 3rd documents. So a cache is kind of like an array of bit, with the length of the total documents. So let's say I have 50 millions docs, so the array length will be 50 millions, which means one filter cache will take up 50.000.000 bit in the ram.

因此我们指定了2000个过滤器缓存,这意味着它将占用的RAM大致为:

So we specified we want 2000 filter cache, it means the RAM it will take is roughly:

50.000.000 * 2000 = 100.000.000.000 bit 

如果将其转换为Gb.将会是:

If you convert it to Gb. It will be:

100.000.000.000 bit / 8 (to byte) / 1000 (to kb) / 1000 (to mb) / 1000 (to gb) = 12,5 Gb

因此,仅过滤器缓存所需的总RAM大约为12Gb.这意味着如果Solr仅具有6Gb堆空间,则将无法创建2000个过滤器缓存.

So the total RAM needed just by the filter cache is roughly 12Gb. And it means if the Solr only have 6Gb Heap Space, it will not be able to create 2000 filter caches.

是的,我知道Solr并不总是创建此数组,并且如果过滤查询的结果很低,它可以创建其他占用更少内存的东西.如果它在ram中有2000个缓存,则此计算仅大致说明了过滤器缓存的上限是多少.在其他更好的情况下,它可能会更低.

Yes, I know Solr doesn't always create this array, and if the result of the filter query is low, it can just create something else which take up less memory. This calculation just says roughly how much the upper limit of the filter cache is, if it has 2000 caches in the ram. It can be lower in other better cases.

因此,一种解决方案是减少solr config中的最大筛选器高速缓存数.我们检查了solr统计信息,大多数时候我们只有大约600个过滤器高速缓存,因此我们可以将过滤器高速缓存的数量减少到最大数量.

So one solution is to lower the number of maximum filter caches in solr config. We checked solr stats, most of the time we only have about 600 filter caches, so we can reduce the filter caches number to that as the maximum.

另一种选择当然是增加RAM.

Another option is to of course add more RAM.

这篇关于Solr筛选器缓存(FastLRUCache)占用太多内存并导致内存不足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆