SlideShare a Scribd company logo
1/47
Solr sparse faceting
Everything counts in large amounts
@TokeEskildsen
State and University Library, Denmark
https://tokee.github.io/lucene-solr/
2/47
Presentation tech level
3/47
Nothing To Fear
● 500TB+ web resources from Danish Net Archive
● Estimated 50TB Solr index data when finished
● 3 machines of 16 CPU cores, 256GB RAM, 25 * 900GB SSD
– Each machine holds: 25 Solrs
● Each Solr holds: 1 optimized shard with 900GB / 250M docs
● Shards build externally, one at a time
● (Optimizations also relevant for smaller setups)
4/47
Pipeline
counter = new int[ordinals]
for docID: result.getDocIDs()
for ordinal: getOrdinals(docID)
counter[ordinal]++
for ordinal = 0 ; ordinal < counters.length ; ordinal++
priorityQueue.add(ordinal, counter[ordinal])
ord term counter
0 A 0
1 B 3
2 C 0
3 D 1006
4 E 1
5 F 1
6 G 0
7 H 0
8 I 3
5/47
6/47
7/47
Recycle
counter = pool.getCounter()
for docID: result.getDocIDs()
for ordinal: getOrdinals(docID)
counter[ordinal]++
for ordinal = 0 ; ordinal < counters.length ; ordinal++
priorityQueue.add(ordinal, counter[ordinal])
pool.release(counter)
8/47
9/47
10/47
11/47
Counting
counter = pool.getCounter()
for docID: result.getDocIDs()
for ordinal: getOrdinals(docID)
counter[ordinal]++
for ordinal = 0 ; ordinal < counters.length ; ordinal++
priorityQueue.add(ordinal, counter[ordinal])
pool.release(counter)
ord term counter
0 A 0
1 B 3
2 C 0
3 D 1006
4 E 1
5 F 1
6 G 0
7 H 0
8 I 3
12/47
ord counter
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
tracker
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
13/47
ord counter
0 0
1 0
2 0
3 1
4 0
5 0
6 0
7 0
8 0
tracker
3
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
14/47
ord counter
0 0
1 1
2 0
3 1
4 0
5 0
6 0
7 0
8 0
tracker
3
1
N/A
N/A
N/A
N/A
N/A
N/A
N/A
15/47
ord counter
0 0
1 1
2 0
3 2
4 0
5 0
6 0
7 0
8 0
tracker
3
1
N/A
N/A
N/A
N/A
N/A
N/A
N/A
16/47
ord counter
0 0
1 3
2 0
3 1006
4 1
5 1
6 0
7 0
8 3
tracker
3
1
8
4
5
N/A
N/A
N/A
N/A
17/47
counter = pool.getCounter()
for docID: result.getDocIDs()
for ordinal: getOrdinals(docID)
if counter[ordinal]++ == 0 && tracked < maxTracked
tracker[tracked++] = ordinal
if tracked < maxTracked
for i = 0 ; i < tracked ; i++
priorityQueue.add(tracker[i], counter[tracker[i]])
else
for ordinal = 0 ; ordinal < counter.length ; ordinal++
priorityQueue.add(ordinal, counter[ordinal])
Sparse counting
ord counter
0 0
1 3
2 0
3 1006
4 1
5 1
6 0
7 0
8 3
tracker
3
1
8
4
5
N/A
N/A
N/A
N/A
18/47
19/47
Get the Balance Right
Phase 1) All shards perform faceting
The Merger calculates top-X terms
Phase 2) The term counts are requested from the shards
that did not return them in phase 1
for term: query.getTerms()
result.add(term, searcher.numDocs(
query(field:term), base.getDocIDs()
).hitCount)
20/47
Pit of Pain™
21/47
Alternative fine counting
counter = pool.getCounter()
for docID: result.getDocIDs()
for ordinal: getOrdinals(docID)
counter.increment(ordinal)
for term: query.getTerms()
result.add(term, counter.get(getOrdinal(term)))
}Same as phase 1
22/47
Stripped
counter = pool.getCounter(key)
for term: query.getTerms()
result.add(term, counter.get(getOrdinal(term)))
23/47
Plain of Platitude™
24/47
250,000,000 docs / 900GB, optimized
Field References Max docs/term Terms
domain 250,000,000 3,000,000 1,100,000
url 250,000,000 56,000 200,000,000
links 5,800,000,000 5,000,000 610,000,000
25/47
Term distributions
domain 1.1M url 200M links 600M
26/47
Clean
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:26:18 2015
27/47
World Full Of Nothing
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 14:55:25 2015
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 14:56:08 2015
domain: 4 MB
url: 780 MB
links: 2350 MB
int[ordinals] PackedInts(ordinals, maxBPV)
domain: 3 MB (72%)
url: 420 MB (53%)
links: 1760 MB (75%)
28/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:26:18 2015
Platonic ideal Harsh reality
Plane 4
Plane 3
Plane 2
Plane 1
Construction Time Again
29/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
30/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
L: 1 ≣ 000001
31/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000010
32/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000010
L: 3 ≣ 000011
33/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000010
L: 3 ≣ 000011
L: 4 ≣ 000100
L: 5 ≣ 000101
L: 6 ≣ 000110
L: 7 ≣ 000111
...
L: 12 ≣ 001100
34/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015Plane 4
Plane 3
Plane 2
Plane 1
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000010
L: 3 ≣ 000011
L: 4 ≣ 000100
L: 5 ≣ 000101
L: 6 ≣ 000110
L: 7 ≣ 000111
...
L: 12 ≣ 001100
if counter[ordinal]++ == 0 && tracked < maxTracked
tracker[tracked++] = ordinal
?
35/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Now This is Fun
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:38:49 2015
Plane 1
Plane 2
Plane 3
Plane 4
36/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Plane 1
Plane 2
Plane 3
Plane 4
L: 0 ≣ 000000
37/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Plane 1
Plane 2
Plane 3
Plane 4
L: 0 ≣ 000000
L: 1 ≣ 000001
38/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Plane 1
Plane 2
Plane 3
Plane 4
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000011
39/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Plane 1
Plane 2
Plane 3
Plane 4
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000011
L: 3 ≣ 000101
40/47
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Plane 1
Plane 2
Plane 3
Plane 4
L: 0 ≣ 000000
L: 1 ≣ 000001
L: 2 ≣ 000011
L: 3 ≣ 000101
L: 4 ≣ 000111
L: 5 ≣ 001001
L: 6 ≣ 001011
L: 7 ≣ 001101
...
L: 12 ≣ 010111
41/47
The Bottom Line
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 22:39:03 2015
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 14:55:25 2015
Title:/home/te/Dropbox/sb/net/pack_tra
Creator:Dia v0.97.2
CreationDate:Wed May 20 14:56:08 2015
domain: 4 MB
url: 780 MB
links: 2350 MB
domain: 3 MB (72%)
url: 420 MB (53%)
links: 1760 MB (75%)
domain: 1 MB (30%)
url: 66 MB ( 8%)
links: 311 MB (13%)
int[ordinals] PackedInts(ordinals, maxBPV) N-plane-z
42/47
43/47
Kitchen sink
250,000,000 docs / 900GB, optimized
Field References Max docs/term Terms
domain 250,000,000 3,000,000 1,100,000
url 250,000,000 56,000 200,000,000
links 5,800,000,000 5,000,000 610,000,000
x 9 shards
x 3 concurrent requests
44/47
Shouldn't Have Done That
45/47
Some Great Reward
8GB heap per
900GB shard
46/47
Dream On
● Threaded counting
● Monotonically increasing tracker for nplane-z
● Regexp filtering
● Fine count skipping
● Counter capping
47/47
Nothing's Impossible

More Related Content

PDF
How To Crack RSA Netrek Binary Verification System
PDF
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
PPTX
What the &~#@&lt;!? (Pointers in Rust)
PPTX
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
PPTX
SSL Failing, Sharing, and Scheduling
PDF
[JS EXPERIENCE 2018] Javascript Event Loop além do setInterval - Derek Stavis
PDF
Debugging TV Frame 0x0D
PDF
Introduction to Homomorphic Encryption
How To Crack RSA Netrek Binary Verification System
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
What the &~#@&lt;!? (Pointers in Rust)
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
SSL Failing, Sharing, and Scheduling
[JS EXPERIENCE 2018] Javascript Event Loop além do setInterval - Derek Stavis
Debugging TV Frame 0x0D
Introduction to Homomorphic Encryption

What's hot (20)

PDF
Вениамин Гвоздиков: Особенности использования DTrace
PPTX
The Internet
PPTX
Managing Memory
PDF
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
PPTX
Secure and privacy-preserving data transmission and processing using homomorp...
PPTX
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
PPTX
Kernel-Level Programming: Entering Ring Naught
PPTX
Making a Process (Virtualizing Memory)
PPTX
7 tcp-congestion
PDF
Brace yourselves, leap second is coming
PDF
RxJava In Baby Steps
PPT
Wepwhacker !
PDF
The Ring programming language version 1.5.4 book - Part 26 of 185
PPTX
DAW: Duplicate-AWare Federated Query Processing over the Web of Data
PDF
Data recovery using pg_filedump
PPTX
4 transport-sharing
PDF
The Ring programming language version 1.8 book - Part 30 of 202
PDF
Verification of Concurrent and Distributed Systems
PPTX
Getting started cpp full
Вениамин Гвоздиков: Особенности использования DTrace
The Internet
Managing Memory
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
Secure and privacy-preserving data transmission and processing using homomorp...
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Kernel-Level Programming: Entering Ring Naught
Making a Process (Virtualizing Memory)
7 tcp-congestion
Brace yourselves, leap second is coming
RxJava In Baby Steps
Wepwhacker !
The Ring programming language version 1.5.4 book - Part 26 of 185
DAW: Duplicate-AWare Federated Query Processing over the Web of Data
Data recovery using pg_filedump
4 transport-sharing
The Ring programming language version 1.8 book - Part 30 of 202
Verification of Concurrent and Distributed Systems
Getting started cpp full
Ad

Similar to Solr sparse faceting (12)

PDF
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
PPT
Faceting optimizations for Solr
PDF
Faceted Search with Lucene
PDF
Learn How to Master Solr1 4
PDF
Solr 3.1 and beyond
PDF
Introduction to solr
PDF
Consuming RealTime Signals in Solr
PPTX
Lots of facets, fast
PDF
Apache Solr 1.4 – Faster, Easier, and More Versatile than Ever
PDF
Webinar: Faster Log Indexing with Fusion
PPTX
SolrCloud in Public Cloud: Scaling Compute Independently from Storage - Ilan ...
PPTX
Building Search & Recommendation Engines
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Faceting optimizations for Solr
Faceted Search with Lucene
Learn How to Master Solr1 4
Solr 3.1 and beyond
Introduction to solr
Consuming RealTime Signals in Solr
Lots of facets, fast
Apache Solr 1.4 – Faster, Easier, and More Versatile than Ever
Webinar: Faster Log Indexing with Fusion
SolrCloud in Public Cloud: Scaling Compute Independently from Storage - Ilan ...
Building Search & Recommendation Engines
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Empathic Computing: Creating Shared Understanding
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Empathic Computing: Creating Shared Understanding
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Solr sparse faceting

Editor's Notes

  • #3: Highly scientific. Very happy with Solr faceting for general work. Principles primarily, applicable to non-Solr settings.
  • #4: State &amp; University + Royal Library. Harvest 4 times/year. Hardware: Save money. Static shards. Generation 1: 25 shards. Generation 2: Currently 9 shards. We&amp;apos;ll use this. Apologies for small sample. 100GB free cache mem (0.5%-1.23% of index size) Danish Net Archive: http://netarkivet.dk/in-english/ Next: We need aggregations, so faceting. String faceting is focus here.
  • #5: Bird&amp;apos;s eye view of vanilla Solr fc-faceting. 1) Allocate counter 2) Update counter 3) Extract top-X DocValues all the way. Works really well for a few million values. Next: Performance: 200M values.
  • #6: Not time series, but bucketed by result size. Most real-world results in the lower end. Non-warmed, random queries, limit=25. 3 concurrent searches. 200M values. Note the high variance for same-size result sets.
  • #7: Standard JRE 1.7 garbage collector – no tuning. Full GC means delay for the client. Standard GC means higher CPU load.
  • #8: Upon release, the counter is cleared by the pool. Faster than re-allocating. Optionally the clearing is done in the background by a dedicated thread.
  • #9: Without and with reuse of counters. Probably possible to reduce full GC on reuse.
  • #10: With and without reuse of counters. The last we see of vanilla Solr (the tricks are stacked)
  • #11: Quartiles plot. Box is 75%, median and 25%. Lower median with reuse. Smaller variance with reuse. Downside: Static overhead. Next: Why the 500ms lower bound?
  • #12: Vanilla Solr extraction of top-X terms scales linear to the number of unique terms. Previous chart: 200M terms = 200M counters. Next: Track the changes.
  • #16: No change as ord 3 has already been incremented.
  • #18: Problem: Random memory access. Slower beyond ~8% (so turn off automatically).
  • #19: Non-sparse &amp; sparse. Downside: 8% overhead. Next: Few Solr&amp;apos;s stand alone - SolrCloud.
  • #20: With distributed faceting, fine counting is necessary.
  • #21: Pit of Pain coined by Andy Jackson, UKWA. 1K-10K very high, due to the highest chance of fine-counting. &amp;lt; 100: Every shard probably returned all know terms. &amp;gt; 100K: Most of the terms in top-X probably returned by most shards. 10M+: True load starts to show (rare). Note: 1M cardinality field. We count just skip finecounting, but we don&amp;apos;t want to cheat that much. Next: What to do about it?
  • #22: Simple strategy: As phase 1 was fast, just repeat it and lookup the specific terms.
  • #23: Since we already did the counting in phase 1, we&amp;apos;ll just re-use the filled counter structure. Cleanup problem handled by background thread.
  • #24: Yes, re-use and sparse multipliers does stack. Downside: Not much. Maybe large result sets? Next: From performance to memory: Counter representation.
  • #25: A typical shard from Net Archive Search v2. References are from documents to terms. High-cardinality in different ways. We want to facet on url and links to visualize connectivity hotspots. Next: All counters are not equal.
  • #26: Common theme: Many with max count 1.
  • #27: We flip the visualization. Squares are counter-bits needed.
  • #28: int[ordinals] uses 4 bytes/counter. PackedInts uses as many bits per value as is needed to represent the highest value of any counter.This works well for fields with a low max count (such as url), but not so well for fields with a high max count (domain and links). Note: The int[ordinals] is not to scale. It really goes up to 32.
  • #29: Black squares are counter value bits. Blue squares signify if the counter it belongs to is so large that it continues on the next plane. All previous blue squares must be counted. This requires a fast rank function to work (3% overhead). Creation is slow! Full term-iteration. Amortized plane-accesses for increments in n-plane is 2 (1 + 50% chance of p2 + 25% chance of p3 + ...). Each plane-shift requires rank lookup and overflow-bit lookup: 2 memory reads Details at https://sbdevel.wordpress.com/2015/03/13/n-plane-packed-counters-for-faceting/
  • #30: Start with 0.
  • #31: Set first bit. No overflow -&amp;gt; no problem.
  • #32: Plane 1 overflows for L. Count blue overflow bits: There are 5. At position 5 in Plane 2, update the bits.
  • #36: This works very well as most counters have a max of 1.
  • #37: This works very well as most counters have a max of 1.
  • #38: This works very well as most counters have a max of 1.
  • #39: This works very well as most counters have a max of 1.
  • #40: This works very well as most counters have a max of 1.
  • #41: This works very well as most counters have a max of 1.
  • #42: N-plane-z instantiations beyond the first re-uses the overflow bits. Lowest possible: 0.7MB (15%), 27.9MB (4%), 132.3MB (6%)
  • #43: Single shard. 640M values. Obvious speed degradation that follows space savings. Insignificant with small result sets due to sparse. TODO: Worst case (*:*) array: packed: nplanez Next: Scale it up.
  • #44: I can&amp;apos;t see how this could possibly go wrong.
  • #45: Worst case: About 50 billion references to 9 billion values must be processed. (10 minutes) Two strategies presents themselves: Threading for exact counts and sampling. Threading is currently implemented.
  • #46: Screenshot taken immediately after kitchen sink test.
  • #47: Available on GitHub. Currently Solr 4.8, promise to go for 4.10.4 Real Soon Now. 5.x later.