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 Cass Costello <ca...@gmail.com> on 2006/07/22 21:20:01 UTC
OpenBitSet performance question
Hello all,
I'm newish to both Lucene and Solr, but I'm loving learning both. I was
intrigued by the comments in the OpenBitSet javadocs...
<snip>
OpenBitSet is faster than java.util.BitSet in most operations and *much*
faster at calculating cardinality of sets and results of set operations.
</snip>
...so I decided to see for myself and concocted a couple tests, which
consistently result in...
Took 421ms to get 5000 bitset intersection counts
Took 1465ms to get 5000 openbitset intersection counts
...and I'm wondering what I've done wrong. The results are consistent
across differenct jvms and different hardware setups. I'm using the 7/22
nightly of Solr. See my test code below.
FYI, my interest in Solr/Lucene stems from a need to create a facetted
browse experience with 10s of thousands of facets derived from millions of
documents.
Thanks for your time,
Cass Costello
package playground.cass;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.apache.solr.util.OpenBitSet;
public class TestsBitSetOperations extends TestCase {
public TestsBitSetOperations(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testMultipleOpenBitSetAndsSpeed() {
int i = 0;
try {
//create 5000 openbitsets, put them all in a single map
Map<String,OpenBitSet> bsMap = new HashMap<String,OpenBitSet>();
OpenBitSet bs;
for ( ; i < 5000; i++ ) {
bs = new OpenBitSet( 500000 );
bs.fastSet( 5000 );
bsMap.put( String.valueOf(i), bs );
}
//our comparsion openbitset
OpenBitSet bs2 = new OpenBitSet( 500000 );
bs2.fastSet( 5000 );
// ensure jvm warmup
Set<String> set = bsMap.keySet();
for ( String key : set ) {
OpenBitSet.intersectionCount( bs2, bsMap.get( key ) );
}
// meat of the test
long start = System.currentTimeMillis();
for ( String key : set ) {
long count = OpenBitSet.intersectionCount( bs2, bsMap.get(
key ) );
}
long finish = System.currentTimeMillis();
System.out.println( "Took " + (finish-start) + "ms to get 5000
openbitset intersection counts" );
} catch ( Throwable t ) {
t.printStackTrace( System.out );
System.out.println( i );
}
}
public void testMultipleBitSetAndsSpeed() {
int i = 0;
try {
//create 5000 bitsets, put them all in a single map
Map<String,BitSet> bsMap = new HashMap<String,BitSet>();
BitSet bs;
for ( ; i < 5000; i++ ) {
bs = new BitSet( 500000 );
bs.set( 5000 );
bsMap.put( String.valueOf(i), bs );
}
BitSet bs2 = new BitSet( 500000 );
bs2.set( 5000 );
//ensure jvm warmup
Set<String> set = bsMap.keySet();
for ( String key : set ) {
BitSet copy = (BitSet)bs2.clone();
copy.and( bsMap.get( key ) );
}
BitSet copy;
// meat of the test
long start = System.currentTimeMillis();
for ( String key : set ) {
copy = (BitSet)bs2.clone();
copy.and( bsMap.get( key ) );
long count = copy.cardinality();
}
long finish = System.currentTimeMillis();
System.out.println( "Took " + (finish-start) + "ms to get 5000
bitset intersection counts" );
} catch ( Throwable t ) {
t.printStackTrace( System.out );
System.out.println( i );
}
}
}
Re: OpenBitSet performance question
Posted by Cass Costello <ca...@gmail.com>.
Ok, I've restructured the tests and am now seeing performance differences
very close to the claims in the javadocs. Thanks much, Yonik and Hoss.
Took 953ms to get 5000 bitset intersection counts
Took 516ms to get 5000 openbitset intersection counts
New code...
public void testMultipleOpenBitSetAndsSpeed() {
int i = 0;
try {
//create 5000 openbitsets, put them all in a single map
Map<String,OpenBitSet> bsMap = new HashMap<String,OpenBitSet>();
OpenBitSet bs;
for ( ; i < 5000; i++ ) {
bs = new OpenBitSet( 500000 );
for ( int x = 0; x < 500000; x = x + 2 ) {
bs.fastSet( x );
}
bsMap.put( String.valueOf(i), bs );
}
//our comparsion openbitset
OpenBitSet bs2 = new OpenBitSet( 500000 );
for ( int x = 1; x < 500000; x = x + 5 ) {
bs2.fastSet( x );
}
// ensure jvm warmup
Set<String> set = bsMap.keySet();
for ( String key : set ) {
OpenBitSet.intersectionCount( bs2, bsMap.get( key ) );
}
// meat of the test
long start = System.currentTimeMillis();
for ( String key : set ) {
OpenBitSet.intersectionCount( bs2, bsMap.get( key ) );
}
long finish = System.currentTimeMillis();
System.out.println( "Took " + (finish-start) + "ms to get 5000
openbitset intersection counts" );
} catch ( Throwable t ) {
t.printStackTrace( System.out );
System.out.println( i );
}
}
public void testMultipleBitSetAndsSpeed() {
int i = 0;
try {
//create 5000 bitsets, put them all in a single map
Map<String,BitSet> bsMap = new HashMap<String,BitSet>();
BitSet bs;
for ( ; i < 5000; i++ ) {
bs = new BitSet( 500000 );
for ( int x = 0; x < 500000; x = x + 2 ) {
bs.set( x );
}
bsMap.put( String.valueOf(i), bs );
}
BitSet bs2 = new BitSet( 500000 );
for ( int x = 1; x < 500000; x = x + 5 ) {
bs2.set( x );
}
//ensure jvm warmup
Set<String> set = bsMap.keySet();
for ( String key : set ) {
BitSet copy = (BitSet)bs2.clone();
copy.and( bsMap.get( key ) );
}
BitSet copy;
// meat of the test
int count = 0;
long start = System.currentTimeMillis();
for ( String key : set ) {
copy = (BitSet)bs2.clone();
copy.and( bsMap.get( key ) );
copy.cardinality();
}
long finish = System.currentTimeMillis();
System.out.println( "Took " + (finish-start) + "ms to get 5000
bitset intersection counts" );
} catch ( Throwable t ) {
t.printStackTrace( System.out );
System.out.println( i );
}
}
On 7/22/06, Yonik Seeley <ys...@gmail.com> wrote:
>
> You are essentially testing sets of size 5000 against sets of size
> 500,000.
> BitSet keeps track of the largest bit you set (which is 5000) and
> doesn't actually calculate the intersection or the populationCount
> beyond that. OpenBitSet does not (it tries to do the minimum
> necessary and make everything as fast as possible.)
>
> So if you changed the single bit you set from 5000 to 499,999, you
> should see very different results.
>
> In any case, if one is only going to set a single bit, there are much
> faster ways of calculating intersection sizes ;-)
>
> -Yonik
>
>
> On 7/22/06, Cass Costello <ca...@gmail.com> wrote:
> > Hello all,
> >
> > I'm newish to both Lucene and Solr, but I'm loving learning both. I was
> > intrigued by the comments in the OpenBitSet javadocs...
> >
> > <snip>
> > OpenBitSet is faster than java.util.BitSet in most operations and *much*
> > faster at calculating cardinality of sets and results of set operations.
> > </snip>
> >
> > ...so I decided to see for myself and concocted a couple tests, which
> > consistently result in...
> >
> > Took 421ms to get 5000 bitset intersection counts
> > Took 1465ms to get 5000 openbitset intersection counts
> >
> > ...and I'm wondering what I've done wrong. The results are consistent
> > across differenct jvms and different hardware setups. I'm using the
> 7/22
> > nightly of Solr. See my test code below.
> >
> > FYI, my interest in Solr/Lucene stems from a need to create a facetted
> > browse experience with 10s of thousands of facets derived from millions
> of
> > documents.
> >
> > Thanks for your time,
> > Cass Costello
> >
> >
> > package playground.cass;
> >
> > import java.util.BitSet;
> > import java.util.HashMap;
> > import java.util.Map;
> > import java.util.Set;
> > import junit.framework.TestCase;
> > import org.apache.solr.util.OpenBitSet;
> >
> > public class TestsBitSetOperations extends TestCase {
> > public TestsBitSetOperations(String arg0) {
> > super(arg0);
> > }
> >
> > protected void setUp() throws Exception {
> > super.setUp();
> > }
> >
> > protected void tearDown() throws Exception {
> > super.tearDown();
> > }
> >
> > public void testMultipleOpenBitSetAndsSpeed() {
> >
> >
> > int i = 0;
> > try {
> > //create 5000 openbitsets, put them all in a single map
> > Map<String,OpenBitSet> bsMap = new
> HashMap<String,OpenBitSet>();
> > OpenBitSet bs;
> > for ( ; i < 5000; i++ ) {
> > bs = new OpenBitSet( 500000 );
> > bs.fastSet( 5000 );
> > bsMap.put( String.valueOf(i), bs );
> > }
> >
> > //our comparsion openbitset
> > OpenBitSet bs2 = new OpenBitSet( 500000 );
> > bs2.fastSet( 5000 );
> >
> > // ensure jvm warmup
> > Set<String> set = bsMap.keySet();
> > for ( String key : set ) {
> > OpenBitSet.intersectionCount( bs2, bsMap.get( key ) );
> > }
> >
> > // meat of the test
> > long start = System.currentTimeMillis();
> > for ( String key : set ) {
> > long count = OpenBitSet.intersectionCount( bs2,
> bsMap.get(
> > key ) );
> > }
> > long finish = System.currentTimeMillis();
> >
> > System.out.println( "Took " + (finish-start) + "ms to get
> 5000
> > openbitset intersection counts" );
> >
> > } catch ( Throwable t ) {
> > t.printStackTrace( System.out );
> > System.out.println( i );
> > }
> > }
> >
> > public void testMultipleBitSetAndsSpeed() {
> >
> >
> > int i = 0;
> > try {
> > //create 5000 bitsets, put them all in a single map
> > Map<String,BitSet> bsMap = new HashMap<String,BitSet>();
> > BitSet bs;
> > for ( ; i < 5000; i++ ) {
> > bs = new BitSet( 500000 );
> > bs.set( 5000 );
> > bsMap.put( String.valueOf(i), bs );
> > }
> >
> > BitSet bs2 = new BitSet( 500000 );
> > bs2.set( 5000 );
> >
> > //ensure jvm warmup
> > Set<String> set = bsMap.keySet();
> > for ( String key : set ) {
> > BitSet copy = (BitSet)bs2.clone();
> > copy.and( bsMap.get( key ) );
> > }
> >
> > BitSet copy;
> >
> > // meat of the test
> > long start = System.currentTimeMillis();
> > for ( String key : set ) {
> > copy = (BitSet)bs2.clone();
> > copy.and( bsMap.get( key ) );
> > long count = copy.cardinality();
> > }
> > long finish = System.currentTimeMillis();
> >
> > System.out.println( "Took " + (finish-start) + "ms to get
> 5000
> > bitset intersection counts" );
> >
> > } catch ( Throwable t ) {
> > t.printStackTrace( System.out );
> > System.out.println( i );
> > }
> >
> > }
> >
> >
> > }
>
Re: OpenBitSet performance question
Posted by Yonik Seeley <ys...@gmail.com>.
You are essentially testing sets of size 5000 against sets of size 500,000.
BitSet keeps track of the largest bit you set (which is 5000) and
doesn't actually calculate the intersection or the populationCount
beyond that. OpenBitSet does not (it tries to do the minimum
necessary and make everything as fast as possible.)
So if you changed the single bit you set from 5000 to 499,999, you
should see very different results.
In any case, if one is only going to set a single bit, there are much
faster ways of calculating intersection sizes ;-)
-Yonik
On 7/22/06, Cass Costello <ca...@gmail.com> wrote:
> Hello all,
>
> I'm newish to both Lucene and Solr, but I'm loving learning both. I was
> intrigued by the comments in the OpenBitSet javadocs...
>
> <snip>
> OpenBitSet is faster than java.util.BitSet in most operations and *much*
> faster at calculating cardinality of sets and results of set operations.
> </snip>
>
> ...so I decided to see for myself and concocted a couple tests, which
> consistently result in...
>
> Took 421ms to get 5000 bitset intersection counts
> Took 1465ms to get 5000 openbitset intersection counts
>
> ...and I'm wondering what I've done wrong. The results are consistent
> across differenct jvms and different hardware setups. I'm using the 7/22
> nightly of Solr. See my test code below.
>
> FYI, my interest in Solr/Lucene stems from a need to create a facetted
> browse experience with 10s of thousands of facets derived from millions of
> documents.
>
> Thanks for your time,
> Cass Costello
>
>
> package playground.cass;
>
> import java.util.BitSet;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.solr.util.OpenBitSet;
>
> public class TestsBitSetOperations extends TestCase {
> public TestsBitSetOperations(String arg0) {
> super(arg0);
> }
>
> protected void setUp() throws Exception {
> super.setUp();
> }
>
> protected void tearDown() throws Exception {
> super.tearDown();
> }
>
> public void testMultipleOpenBitSetAndsSpeed() {
>
>
> int i = 0;
> try {
> //create 5000 openbitsets, put them all in a single map
> Map<String,OpenBitSet> bsMap = new HashMap<String,OpenBitSet>();
> OpenBitSet bs;
> for ( ; i < 5000; i++ ) {
> bs = new OpenBitSet( 500000 );
> bs.fastSet( 5000 );
> bsMap.put( String.valueOf(i), bs );
> }
>
> //our comparsion openbitset
> OpenBitSet bs2 = new OpenBitSet( 500000 );
> bs2.fastSet( 5000 );
>
> // ensure jvm warmup
> Set<String> set = bsMap.keySet();
> for ( String key : set ) {
> OpenBitSet.intersectionCount( bs2, bsMap.get( key ) );
> }
>
> // meat of the test
> long start = System.currentTimeMillis();
> for ( String key : set ) {
> long count = OpenBitSet.intersectionCount( bs2, bsMap.get(
> key ) );
> }
> long finish = System.currentTimeMillis();
>
> System.out.println( "Took " + (finish-start) + "ms to get 5000
> openbitset intersection counts" );
>
> } catch ( Throwable t ) {
> t.printStackTrace( System.out );
> System.out.println( i );
> }
> }
>
> public void testMultipleBitSetAndsSpeed() {
>
>
> int i = 0;
> try {
> //create 5000 bitsets, put them all in a single map
> Map<String,BitSet> bsMap = new HashMap<String,BitSet>();
> BitSet bs;
> for ( ; i < 5000; i++ ) {
> bs = new BitSet( 500000 );
> bs.set( 5000 );
> bsMap.put( String.valueOf(i), bs );
> }
>
> BitSet bs2 = new BitSet( 500000 );
> bs2.set( 5000 );
>
> //ensure jvm warmup
> Set<String> set = bsMap.keySet();
> for ( String key : set ) {
> BitSet copy = (BitSet)bs2.clone();
> copy.and( bsMap.get( key ) );
> }
>
> BitSet copy;
>
> // meat of the test
> long start = System.currentTimeMillis();
> for ( String key : set ) {
> copy = (BitSet)bs2.clone();
> copy.and( bsMap.get( key ) );
> long count = copy.cardinality();
> }
> long finish = System.currentTimeMillis();
>
> System.out.println( "Took " + (finish-start) + "ms to get 5000
> bitset intersection counts" );
>
> } catch ( Throwable t ) {
> t.printStackTrace( System.out );
> System.out.println( i );
> }
>
> }
>
>
> }
Re: OpenBitSet performance question
Posted by Cass Costello <ca...@gmail.com>.
>
> DocSets will be your friend ... the fact that Solr will choose between
> HashDocSets and BitDocSets depending on how many set docs there are in a
> particular set is your friend's really cool roomate, and the filterCache
> will be your friend's really sweet apartment -- both of which will make
> your friend even more fun to hang out with.
Lol - well, who wouldn't want a friend like that? Thanks for the feedback,
Hoss. I'll read through the links and get back to the list once I've
restructured my tests.
On 7/22/06, Chris Hostetter <ho...@fucit.org> wrote:
>
>
> : Took 421ms to get 5000 bitset intersection counts
> : Took 1465ms to get 5000 openbitset intersection counts
> :
> : ...and I'm wondering what I've done wrong. The results are consistent
> : across differenct jvms and different hardware setups. I'm using the
> 7/22
> : nightly of Solr. See my test code below.
>
> Yonik may have more insight into this, but i believe what you are seeing
> is because you only have one bit "set" in each "bit set" and that's not a
> situation OpenBitSet has been optimized for -- in Solr, if you had a set
> of documents that small, it would most likely be modeled with a HasDocSet
> instead of BitDocSet.
>
> the fact that all of your intersections are of two sets that are "equal"
> (bit #5000 is set in every set) may also be triggering some shortcircuting
> optimization in BitSet.and (but that's purely hypothetical speculation)
>
>
> Try running your test with a larger number of more randomly distributed
> set bits and see how the results change. If you are interested, you can
> find Yonik's orriginal performance testing utility here...
>
> http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/util/BitSetPerf.java?view=log
>
> ...searching all Lucene mailing lists (not just SOlr lists) for
> discussions about OpenBitSets will also point out some other tests some
> people tried, as well as some discussion about hypothetical tests (or
> different distributions of set bits) that were discussed but never
> executed (as far as i know) ...
>
> http://www.nabble.com/forum/Search.jtp?forum=44&local=y&query=OpenBitSet
>
> : FYI, my interest in Solr/Lucene stems from a need to create a facetted
> : browse experience with 10s of thousands of facets derived from millions
> of
> : documents.
>
> DocSets will be your friend ... the fact that Solr will choose between
> HashDocSets and BitDocSets depending on how many set docs there are in a
> particular set is your friend's really cool roomate, and the filterCache
> will be your friend's really sweet apartment -- both of which will make
> your friend even more fun to hang out with.
>
>
>
> -Hoss
>
>
Re: OpenBitSet performance question
Posted by Chris Hostetter <ho...@fucit.org>.
: Took 421ms to get 5000 bitset intersection counts
: Took 1465ms to get 5000 openbitset intersection counts
:
: ...and I'm wondering what I've done wrong. The results are consistent
: across differenct jvms and different hardware setups. I'm using the 7/22
: nightly of Solr. See my test code below.
Yonik may have more insight into this, but i believe what you are seeing
is because you only have one bit "set" in each "bit set" and that's not a
situation OpenBitSet has been optimized for -- in Solr, if you had a set
of documents that small, it would most likely be modeled with a HasDocSet
instead of BitDocSet.
the fact that all of your intersections are of two sets that are "equal"
(bit #5000 is set in every set) may also be triggering some shortcircuting
optimization in BitSet.and (but that's purely hypothetical speculation)
Try running your test with a larger number of more randomly distributed
set bits and see how the results change. If you are interested, you can
find Yonik's orriginal performance testing utility here...
http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/util/BitSetPerf.java?view=log
...searching all Lucene mailing lists (not just SOlr lists) for
discussions about OpenBitSets will also point out some other tests some
people tried, as well as some discussion about hypothetical tests (or
different distributions of set bits) that were discussed but never
executed (as far as i know) ...
http://www.nabble.com/forum/Search.jtp?forum=44&local=y&query=OpenBitSet
: FYI, my interest in Solr/Lucene stems from a need to create a facetted
: browse experience with 10s of thousands of facets derived from millions of
: documents.
DocSets will be your friend ... the fact that Solr will choose between
HashDocSets and BitDocSets depending on how many set docs there are in a
particular set is your friend's really cool roomate, and the filterCache
will be your friend's really sweet apartment -- both of which will make
your friend even more fun to hang out with.
-Hoss