Grails design pattern for parallel queries using dynamic finders -
problem: we're querying our database lot of entries. overall application performance okay. think better if our bottleneck, querying special table, done parallel.
we using dynamic finders like:
object.findallbyobjectcollectionandparentisnullanddeletedbyuserisnull(objectcollection, [sort: 'attr1.number', fetch: [objecttype: 'eager']])
i think solution: dividing query 2 steps.
- the first step loads ids in sorted way.
- the second step (could done in parallel threads) loads objects id , inserts resultset.
i googled hints that, find nothing.
- is possible, makes no sense?
- or there adequate solution in grails standard/extensions?
- if makes sense , there no solution: can give me hint implementing it? but, need ids in sorted manner, explained in example.
we're using grails 2.3.11, hibernate:3.6.10.13 jdk 1.7 under it.
i found solution!
arraylist<long> objectids = attribute.executequery("select o.id object o, objecttype ot o.objectcollection = :oc , o.parent null , o.deletedbyuser null , oc.typeusage = ot order ot.nr asc", [oc: objectcollection]) object[] tmp = new object[objectids.size()] withpool(10, { objectids.eachwithindexparallel { long objectid, -> object o = object.findbyid(objectid, [cache: true]) tmp[i] = } }) (object : tmp) a.merge()
its round 3 times slower!
i think reason is, that
- we have create threads , databaseconnections too.
- after loading objects, need merged our local thread.
but in end - cant use it, beause lazy loaded fields couldn't loaded on demand later. solution read-only objects
Comments
Post a Comment