in grails app i'm using technologies excited i'm having problems performance, describe cenario:
- one table 4m+ entires;
- i'm using event bus api;
- grails 2.2.3;
- mysql db;
when client create new room, alloc created too.
pseudo-code: room { hasmany = aloccs: alloc } look code (is not real code, same equality):
@listener(topic="topicaloccreator") def aloccreator(eventmessage<long> message) { localdate start = new datetime().tolocaldate() localdate end = new datetime().plusyears(2).plusmonths(6).tolocaldate() localdate tmp = start room room = room.get(message.data) list channels = channel.list while(tmp.compareto(end) <= 0) { for(channel in channels) { room.addtoalocs(new aloc(0, 0, tmp.todate(), channel)) } tmp = tmp.plusdays(1) } //end of method } this codes works fine, generated lot of alloc objects , put in hibernate session.
what it's correct way job, using flush? batch? - call method assync.
this codes work fine until (07/14) during days slow, 1.30 min insert 10k of alloc in database;
thanks lot suggestions.
because allocs set (default grails collection type when define hasmany relationship), grails has load whole collection memory before insert can happen in order guarantee uniqueness.
take @ bert beckwith's presentation on performance implications of using gorm collections.
i think have couple of options. dispense collection reference entirely, , define classes this:
class alloc { room room } class room { //no reference child allocs } alternatively, define allocs collection bag:
class alloc { static belongsto = [room: room] } class room { collection allocs static hasmany = [allocs: alloc] } in case there's no need uniqueness check , addto... method won't need load every alloc instance memory. will, however, responsible maintaining uniqueness yourself...
Comments
Post a Comment