commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@centras.lt>
Subject Re: [Collections] StaticBucketMap not thread safe
Date Wed, 26 Jun 2002 20:54:15 GMT
Yes, It must test both cases new Integer( i*x )( or new Integer( i + i ) )
and new Integer( nextRandom ) to test hash dispertion.
It is not very trivial to write good test for thing like this.
 And try to run all test cases not in the same process, 20 times for
BusketMap, 20 for HashMap .... .

if( TEST_SOME_MAP )
   map = new SomeMap( capacity );
else if ( TEST_ .......


> I see one difference in the loop code.
>
> Your Version:
>
>         public void run()
>         {
>             long seed = 0;
>             Random rnd = new Random(seed);
>
>             for( int i = 0; i < this.mapCount / 2; i++ )
>             {
>                 this.map.put(new Integer( i ), new Integer( i*5 ) );
>                 this.count++;
>             }
>
>             rnd.setSeed( seed ); // reset pseudo random
>
>             for( int i = 0; i < this.mapCount / 2; i++ )
>             {
>                 Integer value = (Integer)this.map.get( new Integer( i*5
> ) );
>
>                 this.count++;
>             }
>         }
>
> My Version:
>
>         public void run()
>         {
>             long seed = 0;
>             Random rnd = new Random(seed);
>
>             for( int i = 0; i < this.mapCount / 2; i++ )
>             {
>                 this.map.put(new Integer( rnd.nextInt() ), new Integer(
> rnd.nextInt() ) );
>                 this.count++;
>             }
>
>             rnd.setSeed( seed ); // reset pseudo random
>
>             for( int i = 0; i < this.mapCount / 2; i++ )
>             {
>                 Integer value = (Integer)this.map.get( new Integer(
> rnd.nextInt() ));
>                 assertEquals(value.intValue(), rnd.nextInt());
>                 this.count++;
>             }
>         }
>
> Key differences:
>
> Yours declares the random number generator but never uses it.
> Mine tests to see that the values are in fact equal (critical for
> testing race conditions).
>
> > -----Original Message-----
> > From: Juozas Baliuka [mailto:baliuka@centras.lt]
> > Sent: Wednesday, June 26, 2002 4:17 PM
> > To: Jakarta Commons Developers List; bloritsch@apache.org
> > Subject: Re: [Collections] StaticBucketMap not thread safe
> >
> >
> > 1) You must not test Maps in the same process, the first
> > started is faster, because of memory usage.
> > 2) "InitialCapacity" must be the same.
> > 3) Maps must be tested with both "random" and "random_or_not" * x
> >
> > this is with 100 threads:
> >
> >    [junit] Synchronized HashMap took 875ms
> >     [junit] Thats 8.75E-4ms per operation
> >     [junit] BucketMap (5001 buckets) took 609ms
> >     [junit] Thats 6.09E-4ms per operation
> >     [junit] Unsized BucketMap (255 buckets) took 1157ms
> >     [junit] Thats 0.001157ms per operation
> >
> >
> >
> > > > From: Juozas Baliuka [mailto:baliuka@centras.lt]
> > > >
> > > >
> > > > I modified test, both tests show nothing, but this shows how to
> > > > write "bad" and "good" performance tests :)
> > > > Output:
> > >
> > > And what's different besides the number of threads?
> > >
> > > The BucketMap is designed for server environments (i.e. servlet
> > > environments) where having 40-100 threads of execution
> > using one map.
> > >
> > > So how is only 10 better than 100?
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <mailto:commons-dev-help@jakarta.apache.org>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:commons-dev-> unsubscribe@jakarta.apache.org>
> > For
> > additional commands,
> > e-mail: <mailto:commons-dev-help@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message