Leve.Iteration @TearDown method called one too many times

Alex Averbuch alex.averbuch at neotechnology.com
Mon Jul 25 13:53:08 UTC 2016


Hmmm...
After trying other approaches and then returning to the one described in my
original email everything seems to work fine.
Unless the problem resurfaces please consider this as user error, I
probably did something foolish.

On Mon, Jul 25, 2016 at 3:29 PM, Alex Averbuch <
alex.averbuch at neotechnology.com> wrote:

> FYI, I'm using:
>
>         <dependency>
>             <groupId>org.openjdk.jmh</groupId>
>             <artifactId>jmh-core</artifactId>
>             <version>1.1.3</version>
>         </dependency>
>
>
> On Mon, Jul 25, 2016 at 3:27 PM, Alex Averbuch <
> alex.averbuch at neotechnology.com> wrote:
>
>> Hi,
>> I have a benchmark for measuring database index creation.
>>
>> Summary:
>>   * It is an expensive operation (5+ seconds per invocation), so
>> Mode.SingleShotTime is used
>>   * The database runs 5 warmup iterations & 5 measurement iterations
>>   * Each iteration must create an index from scratch, so the index must
>> be dropped/deleted between iterations
>>   * To delete the index after each iteration a Level.Iteration @TearDown
>> method is used. Inside this method the index is dropped
>>
>> Problem:
>>   * It appears as though the Level.Iteration @TearDown method is being
>> called 1 more time than the @Benchmark method
>>   * This causes the database (and benchmark) to crash, because the
>> database tries to delete an index that does not exist
>>
>> When executing the benchmark code at the bottom of this email, the
>> following is written to console:
>>
>> # Run progress: 0.00% complete, ETA 00:00:00
>> # Fork: 1 of 1
>> # Warmup Iteration   1:
>> CREATE
>> DROP
>> # Warmup Iteration   2:
>> CREATE
>> DROP
>> # Warmup Iteration   3:
>> CREATE
>> DROP
>> # Warmup Iteration   4:
>> CREATE
>> DROP
>> # Warmup Iteration   5:
>> CREATE
>> DROP
>> Iteration   1:
>> CREATE
>> DROP
>> Iteration   2:
>> CREATE
>> DROP
>> Iteration   3:
>> CREATE
>> DROP
>> Iteration   4:
>> CREATE
>> DROP
>> Iteration   5:
>> CREATE
>> DROP
>> DROP                                   <--------- NOTICE THIS ADDITIONAL
>> "DROP"
>>
>>
>>
>> Does this (extra DROP) make sense?
>> Is there any way to prevent it from happening?
>> Thanks in advance!
>>
>>
>> @State( Scope.Benchmark )
>> public class CreateIndex
>> {
>>     protected Database db;
>>
>>     @Setup
>>     public void setUp()
>>     {
>>         db = new Database();
>>         // populate db
>>     }
>>
>>     @TearDown
>>     public void tearDown()
>>     {
>>         db.shutdown();
>>     }
>>
>>     @TearDown( Level.Iteration )
>>     public void dropIndex()
>>     {
>>         System.out.println("DROP");
>>         try ( Transaction tx = db.beginTx() )
>>         {
>>             // drop index
>>             tx.success();
>>         }
>>     }
>>
>>     @Benchmark
>>     @BenchmarkMode( Mode.SingleShotTime )
>>     public void createIndex()
>>     {
>>         System.out.println("CREATE");
>>         try ( Transaction tx = db.beginTx() )
>>         {
>>             // create index
>>             tx.success();
>>         }
>>     }
>> }
>>
>
>


More information about the jmh-dev mailing list