strange performance behaviour

91 views
Skip to first unread message

g.pra...@fdlservizi.com

unread,
Mar 27, 2018, 4:51:00 AM3/27/18
to google-guice
I have a strange performance behavior with google guice in my project

My company have a project that use google guice and groovy.
I have to admin: I do not know well google guice (it's been chosen from other than me)

i have this case, it's not easy to explain, let's try

I have this classes

a groovy class with this method (Class A)

 public Integer resMesiFatturazionePerAnno(Integer anno) {
       [some code]
        def bollelett = getListByQuery(BollaLetture, """select bl.* from bolla_letture bl, bolla b, fat where
                                                        b.id_centro_subentro = ? and
                                                        b.id_fat = fat.id and
                                                        fat.dt>=? and fat.dt<= ? and
                                                        bl.id_bolla = b.id
                                                        ORDER by bl.dt asc
                                                        """, getCentroSubentroId(), inizioAnno, fineAnno)
       [some code]
    }


other groovy class with this method (CLASS B)

public <T extends BOIf> List<T> getListByQuery(Class<T> c, String query, Object... list) throws java.lang.Exception {
        [some code]
        for (Map h : this.queryToMapList(query, list)) {
            long test1 = System.currentTimeMillis();            
            T bo = Guice.createInjector(new BillModule(), new CacheModule()).getInstance(c);
             System.out.println("ciclomap: "  + (System.currentTimeMillis() - test1));
            [some code]       
         }
        System.out.println("getListByQuery: " + (System.currentTimeMillis()-test));
        return l;
    } 

if you see, the resMesiFatturazionePerAnno method use the getListByQuery method, and getListByQuery have Guice createInjector inside
resMesiFatturazionePerAnno is invoked from codes inside a batch script, so invoken 20/30.000 times over different instance of CLASS A

depends from where i invoke resMesiFatturazionePerAnno in some case i can see that this lines

long test1 = System.currentTimeMillis();            
T bo = Guice.createInjector(new BillModule(), new CacheModule()).getInstance(c);
System.out.println("ciclomap: "  + (System.currentTimeMillis() - test1));

take 10 milliseconds to executes, but if invoked from other circumstance it take 20ms to executes  (in my case 10ms more for EVERY time the getListByQuery it's called it's really big damage)

Can someone help me to find out why this behaviour?

Tavian Barnes

unread,
Mar 27, 2018, 1:39:56 PM3/27/18
to google-guice
Guice.createInjector() is slow, is it possible to avoid calling it in a loop?  E.g. by creating the injector once outside the loop and only calling .getInstance() inside the loop?

g.pra...@fdlservizi.com

unread,
Mar 28, 2018, 6:06:33 AM3/28/18
to google-guice
Thanks for suggestion
Taking the createinjector out of that method (using a singleton) save so much time...

But i suppose the original question is still valid (but now not so important), why 2 different be behavior of the previous code?

Stephan Classen

unread,
Mar 28, 2018, 10:16:44 AM3/28/18
to google...@googlegroups.com
Best guess is that the modules you pass to the injector depend on some external state and runtime for createInjector is different because of this
Reply all
Reply to author
Forward
0 new messages