Hi,

I'm profiling H2 running my app's tests and have a few questions about
the hotspots, none of which are H2 implementation problems, but instead
just artifacts of my approach.

So, I'm using a named, in-memory database, e.g.:

    JdbcConnectionPool.create("jdbc:h2:mem:foo", "", "");

The two big hotspots are:

1) Re-playing the 10+ Rails-style migrations that issue CREATE TABLE
   commands to create foo's schema. Doing this once at the start takes
   ~1/4th of the test runtime.

2) Between each test, I flush the database so that each test has a clean
   data set to work this. This looks like:

        for (Alias<?> a : Copy.reverse(AliasRegistry.getAliasesSorted())) {
            Jdbc.update(Registry.getDataSource(), "DELETE FROM {}", 
Wrap.quotes(a.getTableName()));
            if (a.isRootClass()) {
                Jdbc.update(Registry.getDataSource(), "ALTER SEQUENCE {} 
RESTART WITH 1 INCREMENT BY 1;", a.getTableName() + "_id_seq");
            }
        }

With 70 tests, this flush happens 70 times, but 30 tables, that is ~2100 DELETE
FROMs. Each individual one is quick, but in aggregate, all 2100 take roughly
~1/2th of the test runtime.

In postgres, I ended up generating a "flush_test_database" stored procedure
that had all of the DELETEs in it, which meant just one JDBC call and that
really helped perf; but from the H2 stored procedure stuff I've seen, I'd
been using JDBC anyway. Some sort of global "delete all" would be cool,
though granted only useful for dev/test environments.

So, if I could solve these two problems--quickly bootstrapping an in-memory
database with an existing schema (I've seen the backup zip files and will
try that next--I wasn't sure if I could backup/load in-memory databases),
and then flushing all of the data in each setUp, I'd cut my test runtime
by 3/4ths. Which would be great.

If anyone has any tips or tricks, I'd really appreciate it.

Thanks,
Stephen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to