Solr Filter Cache (FastLRUCache) 占用内存过多导致内存不足?
我有一个 Solr 设置.一个master和两个slave用于复制.我们的索引中有大约 7000 万份文档.从站有 16 GB 的 RAM.10GB 用于 OS 和 HD,6GB 用于 Solr.
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 并不总是创建这个数组,如果过滤器查询的结果很低,它可以创建其他占用更少内存的东西.如果内存中有 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 配置中的最大过滤器缓存数.我们检查了 solr stats,大多数时候我们只有大约 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.
相关文章