lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Willnauer <>
Subject Re: Flushing Thread
Date Fri, 20 Jul 2012 09:49:03 GMT
hey simon ;)

On Fri, Jul 20, 2012 at 2:29 AM, Simon McDuff <> wrote:
> Thank you Simon Willnauer!
> With your explanation, we`ve decided to control the flushing by spawning another thread.
So the thread is available to still ingest ! :-) (correct me if I'm wrong)We do so by checking
the RAM size provided by Lucene! (Thank you!)By putting the automatic flushing at 1000 megs
and our controlling at 900 megs, we know that the automatic flushing "should" not happen.

it should not. Yet, 1G is a large ram buffer. In my tests I got much
better results with lowish ram buffers like 256MB since that causes
flush to happen more often and it saturates your IO on the machine.
The general goal is to keep the RAM buffer at a level where you almost
constantly flush ie. you maximise the the RAM buffer so that a flush
should happen once you are done with the previous flush. Does that
make sense?

> I know you contribute a lot to the concurrency feature! This is great! I was very excited
to try it!
> We tried the following approaches:Option 1- 6 threads referring to the same IndexWriterOption
2- 6 threads having their own IndexWriter, merge it at the end
> Unfortunately, we found that option 2 scale better. I'm not sure why option 1 didn`t
scale. Is it possible that synchronization between threads is too costly ? ... I don`t have
an answered but it was definitely slower.

can you provide the numbers and what you actually did in your experiment.

> With option 2, we are able to insert between 800 000 - 900 000 documents / sec. (we've
modified lucene to remove some bottleneck)Threads DO NOT ONLY index, it does other stuff before
adding documents.

what are your modifications? 800k documents are a lot! I wonder what
you are indexing, do you have any text you are inverting. I have run
tests on a very strong machine on 4k /doc average doc size and I
couldn't even get 10% of this. So in your case lock contention in the
indexwriter (there are still blocking parts) could be dominating. This
is certainly not what we optimize for. I'd say 99% of the cases the
most of the time is spend in DocumentsWriterPerThread inverting the
document. If that is not the case in your experiment and you are only
measuring thread overhead then I can totally buy your numbers.

> Did you look at the disruptor pattern (by LMAX) ? It helped us a lot to achieve great
performance in multithreaded environment!

I know of the pattern though their usecase is totally different to
ours. The time spend per transaction is super low compared to the
thread overhead so they try to optimize this for high performance
computing. ie. for like 5M transactions per second you enter / leave
locks literally all the freaking time. With IndexWriter you don't have
such a pattern. Large numbers would be like 50k / sec that it 2 orders
of a magnitude less so lock overhead becomes minor since contention is
much lower. If you go and make your documents super super small like
not invert anything or just store you might see an overhead in the
threading model I agree. Our bottleneck is not lock contention here
but IO and that is what we optimized this for. Makes sense?

That said, if you really wanna optimize this you could write your own
DocumentsWriterPerThreadPool and a custom FlushPolicy (both package
private in org.apache.lucene.index) in DWPThreadPool you only maintain
one DWPT and in the FlushPolicy you only track ram consumption of that
DWPT. Once you see that it has filled up you notify another thread
that its time for flush and go out and call commit. You can then over
time find out what is the right RAM buffer to saturate IO, don't
create too many segments to kill performance due to too many
background merges and maximise in memory throughput.

simonw :)

> Thank you
> Simon M.
>> Date: Thu, 19 Jul 2012 21:52:19 +0200
>> Subject: Re: Flushing Thread
>> From:
>> To:
>> hey,
>> On Thu, Jul 19, 2012 at 7:41 PM, Simon McDuff <> wrote:
>> >
>> > Thank you for your answer!
>> >
>> > I read all your blogs! It is always interesting!
>> for details see:
>> and
>> >
>> > My understanding is probably incorrect ...
>> > I observed that if you have only one thread that addDocument, it will not spawn
another thread for flushing, it uses the main thread.
>> every indexing thread can hit a flush. if you only have one thread you
>> will not make progress adding docs while flushing.
>> IW will not create new threads for flushing.
>> > In this case, my main thread is locked. Correct ?
>> >
>> > The concurrent flushing will ONLY work when I have many threads adding documents
? (In that case I will need to put a ringbuffer in front)
>> that is basically correct. You can frequently call commit / or pull a
>> reader from the IW in a different thread before you ram buffer fills
>> up so that flushing happens in a different thread. That could work
>> pretty well if you don't have many deletes to be applied. (if you have
>> many deletes then pull a reader without applying deletes.
>> simon
>> >
>> > Do I understand correctly ? Did I miss something ?
>> >
>> > Simon
>> >
>> >> From:
>> >> Date: Thu, 19 Jul 2012 13:02:42 -0400
>> >> Subject: Re: Flushing Thread
>> >> To:
>> >>
>> >> This has already been fixed on Lucene 4.0 (we now have fully
>> >> concurrent flushing), eg see:
>> >>
>> >>
>> >>
>> >> Mike McCandless
>> >>
>> >>
>> >>
>> >> On Thu, Jul 19, 2012 at 12:54 PM, Simon McDuff <>
>> >> >
>> >> > I see some behavior at the moment when I'm flushing and would like
to know if I can change that.
>> >> >
>> >> >  One main thread is inserting, when it flushes, it blocks.
>> >> >  During that time my main thread is blocking. Instead of blocking,
Could it spawn another thread to do that ?
>> >> >
>> >> > Basically,  would like to have one main thread adding document to my
index, if a flushing needs to occur, spawn another threads but it should never lock the main
 threads. Is it possible ?
>> >> >
>> >> > Is the only solution is to have many threads indexing the data ?
>> >> > In that case Is it true to say ONLY one of them will be busy while
the other is flushing ? (I do understand that if my flushing is taking two much time, they
will both flush... :-))
>> >> >
>> >> > Thank you!
>> >> >
>> >> > Simon
>> >> >
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail:
>> >> For additional commands, e-mail:
>> >>
>> >
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message