You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Andrea Gazzarini <an...@gmail.com> on 2013/08/14 09:19:01 UTC

Who's cleaning the Fieldcache?

After doing some replications (replicationOnOptimize) I see

- on master filesystem files that belong to two segments (I suppose the 
oldest is just a commit point)
- on master admin console 
(SolrIndexReader{this=4f2452c6,r=ReadOnlyDirectoryReader@4f2452c6,refCnt=1,*segments=**1*})

but on slave

- on filesystem I see files belonging just to latest segment (which in 
this case is called *_mx*)
- on admin console I see there's just one segment
- on stats page I see (FieldCache) references to both new and previous 
(old) segment (*_mv and _mx*)

entries_count : 11
...
entry#2 : 
'MMapIndexInput(path="/home/agazzarini/solr-indexes/slave-data-dir/cbt/main/data/index/_*mv*.frq")'=>'*title_sort*',class 
org.apache.lucene.search.FieldCache$StringIndex,null=>org.apache.lucene.search.FieldCache$StringIndex#883647064
entry#3 : 
'MMapIndexInput(path="/home/agazzarini/solr-indexes/slave-data-dir/cbt/main/data/index/_*mv*.frq")'=>'*author_sort*',class 
org.apache.lucene.search.FieldCache$StringIndex,null=>org.apache.lucene.search.FieldCache$StringIndex#1606785643
...
entry#7 : 
'MMapIndexInput(path="/home/agazzarini/solr-indexes/slave-data-dir/cbt/main/data/index/_*mx*.frq")'=>'*title_sort*',class 
org.apache.lucene.search.FieldCache$StringIndex,null=>org.apache.lucene.search.FieldCache$StringIndex#144024863
entry#8 : 
'MMapIndexInput(path="/home/agazzarini/solr-indexes/slave-data-dir/cbt/main/data/index/_*mx*.frq")'=>'*author_sort'*,class 
org.apache.lucene.search.FieldCache$StringIndex,null=>org.apache.lucene.search.FieldCache$StringIndex#411802272
...

why? Those are my sort fields and they are occupying a lot of space 
(doubled in this case but I see that sometimes I have three or four 
"old" segment references)

Is there something I can do to remove those old references? I tried to 
reload the core and it seems the old references are discarded (i.e. 
garbage collected) but I believe is not a good workaround, I would avoid 
to reload the core for every replication cycle.

Best
Andrea





Re: Who's cleaning the Fieldcache?

Posted by Andrea Gazzarini <an...@gmail.com>.
Hi Chris, Robert

Thank you very much. First, answers to your questions:

1) which version of Solr are you using?
> 3.6.0

2) is it possibly you have multiple searchers open (ie: one in use
while another one is warming up) when you're seeing these stats?
> No, no multiple searchers.

Now, after one day of experiments, I think I got what's happening. 
Briefly, the behaviour seems to be exactly what Chris described (Weak 
references that are garbage collected when needed). Instead I'm not 
seeing what described by Robert.

This is what I understood aboyut my problem:

- Xms4GB
- sort fields definitely too big...once loaded they got about more than 
2GB of memory

So when replication occurs "new" sort field values (belonging to the new 
replicated segment) are loaded in memory...but before old segment are 
garbage collected on slave (I mean, sort field values belonging to the 
old segment) I have no enough memory (2GB + 2GB...only for sort 
fields)....so et voilĂ : OutOfMemory

What I've done is to reduce unique values of sort fields (now the 
FieldCacheImpl is about 600MB) so there's enough memory for ordinary 
work, for replication stuff and for retaining two different 
FieldCacheImpl references (old and replicated segment)...in this way I 
see exatcly what Chris described: when replication occurs, memory grows 
(on slave) for about 800MB; hereafter the memory has a constant growing 
(very slowly) graph but when it reaches a certain point (about 3.7GB) 
garbage collector run and frees something like 2.2GB. Good, I repeat 
this test a lot of times and the behaviour is always the same.

Thank you very much to both of you
Andrea


On 08/14/2013 11:58 PM, Chris Hostetter wrote:
> : > FieldCaches are managed using a WeakHashMap - so once the IndexReader's
> : > associated with those FieldCaches are no logner used, they will be garbage
> : > collected when and if the JVMs garbage collector get arround to it.
> : >
> : > if they sit arround after you are done with them, they might look like the
> : > ytake upa log of memory, but that just means your JVM Heap has that memory
> : > to spare and hasn't needed to clean them up yet.
> :
> : I don't think this is correct.
> :
> : When you register an entry in the fieldcache, it registers event
> : listeners on the segment's core so that when its close()d, any entries
> : are purged rather than waiting on GC.
> :
> : See FieldCacheImpl.java
>
> Ah ... sweet.  I didn't realize that got added.
>
> (In any case: it looks like a WeakHashMap is still used in case the
> listeners never get called, correct?)
>
> But bassed on the details from the OP's first message, it looks like he's
> running Solr 3.x (there's mentions of "SolrIndexReader" which fromat what
> i can tell was gone by 4.0) so perhaps this is an older version before all
> the kinks were worked out in the reader close listeners used by
> fieldcache?  (I'm noticing things like LUCENE-3644 in particular)
>
> Andrea:
>
> 1) which version of Solr are you using?
> 2) is it possibly you have multiple searchers open (ie: one in use
> while another one is warming up) when you're seeing these stats?
>
>
>
> -Hoss


Re: Who's cleaning the Fieldcache?

Posted by Robert Muir <rc...@gmail.com>.
On Wed, Aug 14, 2013 at 5:58 PM, Chris Hostetter
<ho...@fucit.org> wrote:
>
> : > FieldCaches are managed using a WeakHashMap - so once the IndexReader's
> : > associated with those FieldCaches are no logner used, they will be garbage
> : > collected when and if the JVMs garbage collector get arround to it.
> : >
> : > if they sit arround after you are done with them, they might look like the
> : > ytake upa log of memory, but that just means your JVM Heap has that memory
> : > to spare and hasn't needed to clean them up yet.
> :
> : I don't think this is correct.
> :
> : When you register an entry in the fieldcache, it registers event
> : listeners on the segment's core so that when its close()d, any entries
> : are purged rather than waiting on GC.
> :
> : See FieldCacheImpl.java
>
> Ah ... sweet.  I didn't realize that got added.
>
> (In any case: it looks like a WeakHashMap is still used in case the
> listeners never get called, correct?)
>

I think it might be the other way around: i think it was weakmap
before always, the close listeners were then added sometime in 3.x
series, so we registered purge events "as an optimization".

But one way to look at it is: readers should really get closed, so why
have the weak map and not just a regular hashmap.

Even if we want to keep the weak map (seriously i dont care, and i
dont want to be the guy fielding complaints on this), I'm going to
open with an issue with a patch that removes it and fails tests in
@afterclass if there is any entries. This way its totally clear
if/when/where anything is "relying on GC" today here and we can at
least look at that.

Re: Who's cleaning the Fieldcache?

Posted by Chris Hostetter <ho...@fucit.org>.
: > FieldCaches are managed using a WeakHashMap - so once the IndexReader's
: > associated with those FieldCaches are no logner used, they will be garbage
: > collected when and if the JVMs garbage collector get arround to it.
: >
: > if they sit arround after you are done with them, they might look like the
: > ytake upa log of memory, but that just means your JVM Heap has that memory
: > to spare and hasn't needed to clean them up yet.
: 
: I don't think this is correct.
: 
: When you register an entry in the fieldcache, it registers event
: listeners on the segment's core so that when its close()d, any entries
: are purged rather than waiting on GC.
: 
: See FieldCacheImpl.java

Ah ... sweet.  I didn't realize that got added.

(In any case: it looks like a WeakHashMap is still used in case the 
listeners never get called, correct?)

But bassed on the details from the OP's first message, it looks like he's 
running Solr 3.x (there's mentions of "SolrIndexReader" which fromat what 
i can tell was gone by 4.0) so perhaps this is an older version before all 
the kinks were worked out in the reader close listeners used by 
fieldcache?  (I'm noticing things like LUCENE-3644 in particular)

Andrea: 

1) which version of Solr are you using?
2) is it possibly you have multiple searchers open (ie: one in use 
while another one is warming up) when you're seeing these stats?



-Hoss

Re: Who's cleaning the Fieldcache?

Posted by Robert Muir <rc...@gmail.com>.
On Wed, Aug 14, 2013 at 5:29 PM, Chris Hostetter
<ho...@fucit.org> wrote:
>
> : why? Those are my sort fields and they are occupying a lot of space (doubled
> : in this case but I see that sometimes I have three or four "old" segment
> : references)
> :
> : Is there something I can do to remove those old references? I tried to reload
> : the core and it seems the old references are discarded (i.e. garbage
> : collected) but I believe is not a good workaround, I would avoid to reload the
> : core for every replication cycle.
>
> You don't need to reload the core to get rid of the old FieldCaches -- in
> fact, there is nothing about reloading the core that will garuntee old
> FieldCaches get removed.
>
> FieldCaches are managed using a WeakHashMap - so once the IndexReader's
> associated with those FieldCaches are no logner used, they will be garbage
> collected when and if the JVMs garbage collector get arround to it.
>
> if they sit arround after you are done with them, they might look like the
> ytake upa log of memory, but that just means your JVM Heap has that memory
> to spare and hasn't needed to clean them up yet.

I don't think this is correct.

When you register an entry in the fieldcache, it registers event
listeners on the segment's core so that when its close()d, any entries
are purged rather than waiting on GC.

See FieldCacheImpl.java

Re: Who's cleaning the Fieldcache?

Posted by Chris Hostetter <ho...@fucit.org>.
: why? Those are my sort fields and they are occupying a lot of space (doubled
: in this case but I see that sometimes I have three or four "old" segment
: references)
: 
: Is there something I can do to remove those old references? I tried to reload
: the core and it seems the old references are discarded (i.e. garbage
: collected) but I believe is not a good workaround, I would avoid to reload the
: core for every replication cycle.

You don't need to reload the core to get rid of the old FieldCaches -- in 
fact, there is nothing about reloading the core that will garuntee old 
FieldCaches get removed.

FieldCaches are managed using a WeakHashMap - so once the IndexReader's 
associated with those FieldCaches are no logner used, they will be garbage 
collected when and if the JVMs garbage collector get arround to it.

if they sit arround after you are done with them, they might look like the 
ytake upa log of memory, but that just means your JVM Heap has that memory 
to spare and hasn't needed to clean them up yet.


-Hoss