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.

  1. the first step loads ids in sorted way.
  2. the second step (could done in parallel threads) loads objects id , inserts resultset.

i googled hints that, find nothing.

  1. is possible, makes no sense?
  2. or there adequate solution in grails standard/extensions?
  3. 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

  1. we have create threads , databaseconnections too.
  2. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -