You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ahmet Arslan <io...@yahoo.com.INVALID> on 2015/01/05 14:10:58 UTC

Re: IndexSearcher.setSimilarity thread-safety


anyone?



On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan <io...@yahoo.com.INVALID> wrote:
Hi all,

Javadocs says "IndexSearcher instances are completely thread safe, meaning multiple threads can call any of its
methods, concurrently"

Is this true for setSimilarity() method?

What happens when every thread uses different similarity implementations?

Thanks,
Ahmet

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: IndexSearcher.setSimilarity thread-safety

Posted by Trejkaz <tr...@trypticon.org>.
On Tue, Jan 6, 2015 at 1:40 AM, Barry Coughlan <b....@gmail.com> wrote:
> Ideally the similarity field would not be mutable to indicate this, but I
> suppose this would make the constructors very awkward.

IndexSearcher(IndexReader, IndexSearcherConfig) wouldn't be all that
bad and we're at least already used to it with IndexWriter's
constructors.

TX

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: IndexSearcher.setSimilarity thread-safety

Posted by Ahmet Arslan <io...@yahoo.com.INVALID>.

Thanks for the explanation, Uwe.


On Monday, January 5, 2015 7:30 PM, Uwe Schindler <uw...@thetaphi.de> wrote:
Hi,

The documentation may be a bit incorrect, but in general it means: IndexSearcher is thread safe in regards to "searching". Getters/Setters are generally not thread safe for most classes. The documentation is mainly to prevent people from synchronizing any external calls, because this would be a disaster to do!

About your problem: Please use a new IndexSearcher for each different similarity. IndexSearcher is a very chaep object (it is just a Wrapper around the IndexReader), so it is only important to keep the IndexReader open. But for simplification, I would personally create a new IndexSearcher instance for every search request (...and I always do this).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Barry Coughlan [mailto:b.coughlan2@gmail.com]
> Sent: Monday, January 05, 2015 3:40 PM
> To: java-user@lucene.apache.org; Ahmet Arslan
> Subject: Re: IndexSearcher.setSimilarity thread-safety
> 
> Hi Ahmet,
> 
> The IndexSearcher is "thread-safe", it's just that the similarity field is shared
> between threads. I think that to most people it is implied that the similarity is
> not thread-local, as this would be surprising behavior.
> 
> Ideally the similarity field would not be mutable to indicate this, but I
> suppose this would make the constructors very awkward.
> 
> Barry
> 
> On Mon, Jan 5, 2015 at 2:02 PM, Ahmet Arslan <io...@yahoo.com.invalid>
> wrote:
> 
> > Hi Barry,
> >
> > Thanks for chiming in. Then javadocs needs correction, right?
> >
> > "multiple threads can call any of its methods, concurrently"
> >
> > Ahmet
> >
> >
> > On Monday, January 5, 2015 3:28 PM, Barry Coughlan
> > <b....@gmail.com>
> > wrote:
> > Just had a glance at the IndexSearcher code.
> >
> > Changing the similarity would not cause any failures. However the
> > change may not be immediately seen by all threads because the variable
> > is non-volatile (I'm open to correction on that...).
> >
> > If you need multiple threads to have different Similarity
> > implementations then you will need separate IndexSearcher instances.
> > You can use a single IndexReader for the IndexSearchers
> >
> > Barry
> >
> >
> > On Mon, Jan 5, 2015 at 1:10 PM, Ahmet Arslan
> > <io...@yahoo.com.invalid>
> > wrote:
> >
> > >
> > >
> > > anyone?
> > >
> > >
> > >
> > > On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan
> > > <io...@yahoo.com.INVALID> wrote:
> > > Hi all,
> > >
> > > Javadocs says "IndexSearcher instances are completely thread safe,
> > meaning
> > > multiple threads can call any of its methods, concurrently"
> > >
> > > Is this true for setSimilarity() method?
> > >
> > > What happens when every thread uses different similarity
> implementations?
> > >
> > > Thanks,
> > > Ahmet
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org

> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: IndexSearcher.setSimilarity thread-safety

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

The documentation may be a bit incorrect, but in general it means: IndexSearcher is thread safe in regards to "searching". Getters/Setters are generally not thread safe for most classes. The documentation is mainly to prevent people from synchronizing any external calls, because this would be a disaster to do!

About your problem: Please use a new IndexSearcher for each different similarity. IndexSearcher is a very chaep object (it is just a Wrapper around the IndexReader), so it is only important to keep the IndexReader open. But for simplification, I would personally create a new IndexSearcher instance for every search request (...and I always do this).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Barry Coughlan [mailto:b.coughlan2@gmail.com]
> Sent: Monday, January 05, 2015 3:40 PM
> To: java-user@lucene.apache.org; Ahmet Arslan
> Subject: Re: IndexSearcher.setSimilarity thread-safety
> 
> Hi Ahmet,
> 
> The IndexSearcher is "thread-safe", it's just that the similarity field is shared
> between threads. I think that to most people it is implied that the similarity is
> not thread-local, as this would be surprising behavior.
> 
> Ideally the similarity field would not be mutable to indicate this, but I
> suppose this would make the constructors very awkward.
> 
> Barry
> 
> On Mon, Jan 5, 2015 at 2:02 PM, Ahmet Arslan <io...@yahoo.com.invalid>
> wrote:
> 
> > Hi Barry,
> >
> > Thanks for chiming in. Then javadocs needs correction, right?
> >
> > "multiple threads can call any of its methods, concurrently"
> >
> > Ahmet
> >
> >
> > On Monday, January 5, 2015 3:28 PM, Barry Coughlan
> > <b....@gmail.com>
> > wrote:
> > Just had a glance at the IndexSearcher code.
> >
> > Changing the similarity would not cause any failures. However the
> > change may not be immediately seen by all threads because the variable
> > is non-volatile (I'm open to correction on that...).
> >
> > If you need multiple threads to have different Similarity
> > implementations then you will need separate IndexSearcher instances.
> > You can use a single IndexReader for the IndexSearchers
> >
> > Barry
> >
> >
> > On Mon, Jan 5, 2015 at 1:10 PM, Ahmet Arslan
> > <io...@yahoo.com.invalid>
> > wrote:
> >
> > >
> > >
> > > anyone?
> > >
> > >
> > >
> > > On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan
> > > <io...@yahoo.com.INVALID> wrote:
> > > Hi all,
> > >
> > > Javadocs says "IndexSearcher instances are completely thread safe,
> > meaning
> > > multiple threads can call any of its methods, concurrently"
> > >
> > > Is this true for setSimilarity() method?
> > >
> > > What happens when every thread uses different similarity
> implementations?
> > >
> > > Thanks,
> > > Ahmet
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: IndexSearcher.setSimilarity thread-safety

Posted by Barry Coughlan <b....@gmail.com>.
Hi Ahmet,

The IndexSearcher is "thread-safe", it's just that the similarity field is
shared between threads. I think that to most people it is implied that the
similarity is not thread-local, as this would be surprising behavior.

Ideally the similarity field would not be mutable to indicate this, but I
suppose this would make the constructors very awkward.

Barry

On Mon, Jan 5, 2015 at 2:02 PM, Ahmet Arslan <io...@yahoo.com.invalid>
wrote:

> Hi Barry,
>
> Thanks for chiming in. Then javadocs needs correction, right?
>
> "multiple threads can call any of its methods, concurrently"
>
> Ahmet
>
>
> On Monday, January 5, 2015 3:28 PM, Barry Coughlan <b....@gmail.com>
> wrote:
> Just had a glance at the IndexSearcher code.
>
> Changing the similarity would not cause any failures. However the change
> may not be immediately seen by all threads because the variable is
> non-volatile (I'm open to correction on that...).
>
> If you need multiple threads to have different Similarity implementations
> then you will need separate IndexSearcher instances. You can use a single
> IndexReader for the IndexSearchers
>
> Barry
>
>
> On Mon, Jan 5, 2015 at 1:10 PM, Ahmet Arslan <io...@yahoo.com.invalid>
> wrote:
>
> >
> >
> > anyone?
> >
> >
> >
> > On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan
> > <io...@yahoo.com.INVALID> wrote:
> > Hi all,
> >
> > Javadocs says "IndexSearcher instances are completely thread safe,
> meaning
> > multiple threads can call any of its
> > methods, concurrently"
> >
> > Is this true for setSimilarity() method?
> >
> > What happens when every thread uses different similarity implementations?
> >
> > Thanks,
> > Ahmet
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: IndexSearcher.setSimilarity thread-safety

Posted by Ahmet Arslan <io...@yahoo.com.INVALID>.
Hi Barry,

Thanks for chiming in. Then javadocs needs correction, right?

"multiple threads can call any of its methods, concurrently"

Ahmet


On Monday, January 5, 2015 3:28 PM, Barry Coughlan <b....@gmail.com> wrote:
Just had a glance at the IndexSearcher code.

Changing the similarity would not cause any failures. However the change
may not be immediately seen by all threads because the variable is
non-volatile (I'm open to correction on that...).

If you need multiple threads to have different Similarity implementations
then you will need separate IndexSearcher instances. You can use a single
IndexReader for the IndexSearchers

Barry


On Mon, Jan 5, 2015 at 1:10 PM, Ahmet Arslan <io...@yahoo.com.invalid>
wrote:

>
>
> anyone?
>
>
>
> On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan
> <io...@yahoo.com.INVALID> wrote:
> Hi all,
>
> Javadocs says "IndexSearcher instances are completely thread safe, meaning
> multiple threads can call any of its
> methods, concurrently"
>
> Is this true for setSimilarity() method?
>
> What happens when every thread uses different similarity implementations?
>
> Thanks,
> Ahmet
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: IndexSearcher.setSimilarity thread-safety

Posted by Barry Coughlan <b....@gmail.com>.
Just had a glance at the IndexSearcher code.

Changing the similarity would not cause any failures. However the change
may not be immediately seen by all threads because the variable is
non-volatile (I'm open to correction on that...).

If you need multiple threads to have different Similarity implementations
then you will need separate IndexSearcher instances. You can use a single
IndexReader for the IndexSearchers

Barry

On Mon, Jan 5, 2015 at 1:10 PM, Ahmet Arslan <io...@yahoo.com.invalid>
wrote:

>
>
> anyone?
>
>
>
> On Thursday, December 25, 2014 4:42 PM, Ahmet Arslan
> <io...@yahoo.com.INVALID> wrote:
> Hi all,
>
> Javadocs says "IndexSearcher instances are completely thread safe, meaning
> multiple threads can call any of its
> methods, concurrently"
>
> Is this true for setSimilarity() method?
>
> What happens when every thread uses different similarity implementations?
>
> Thanks,
> Ahmet
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>