This bears repeating: The LMAX 
Disruptor<http://lmax-exchange.github.io/disruptor/>is a an awesomely cool, 
small, blindingly fast, rocks-old library that is 
great for something like this.

Create an Event class that contains your query.

Create a WorkHandler<Event> class whose onEvent method is called whenever 
there is a query to process.

Create a Disruptor<Event> object with two thread pools, a large enough ring 
buffer (to hold pending queries), and a MULTI_PRODUCER strategy. Create and 
register a number of your WorkHandler objects, one for each thread that you 
want accessing Elasticsearch. This will bound the load on ES. Also set a 
wait strategy: For use with ES I use a BlockingWaitStrategy as a good 
compromise between high performance and low CPU usage (our operations folks 
hate to see 100% CPU even if the CPU is efficiently spinning).

Then start the Disruptor and save the reference to the RingBuffer for your 
publisher threads.

Now you can have a bazillion threads issuing queries. All they do is use 
the 2-phase commit logic to publish: Get a sequence number, then get an 
Event for that sequence, store the query into that Event, and commit the 
Event. Poof!

The RingBuffer handles all the complexity, and is optimized for lockless 
performance where possible. For example, if a burst of requests come in and 
there are many more published events than handled events, then the 
RingBuffer can select a batch of events that are doled out to WorkHandler 
threads without any locking whatsoever. Vastly better than the constant 
lock/get/unlock overhead of a standard Java queue. The Disruptor adds an 
indistinguishably teeny tiny overhead; you won't even know it's there.

When it's time to end the application, there are easy and safe shutdown 
methods to ensure everything is stopped without losing any queries (which 
could also include updates if you need them).

Elasticsearch rocks. The Disruptor rocks. Put 'em together and you can 
blast bazillions of queries at your ES instance and never overload it. And 
by limiting the threads that are banging on ES, you also keep ES performing 
at its sweet spot and not thrashing.

Regards,
Brian

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/030d2ef8-f8b3-4c99-bbd4-2ad7dc606375%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to