Discussion:
strange performance behaviour
g***@fdlservizi.com
2018-03-27 08:51:00 UTC
Permalink
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?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/51ebdb6b-5928-4c4e-afa2-7ae58a22644f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tavian Barnes
2018-03-27 17:39:56 UTC
Permalink
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?
Post by g***@fdlservizi.com
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?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/04f171ec-9277-493e-87e0-7e533ad12f33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@fdlservizi.com
2018-03-28 10:06:33 UTC
Permalink
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?
Post by Tavian Barnes
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?
Post by g***@fdlservizi.com
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?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b8cb8183-50d5-4d39-8d00-68f97afd3557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-03-28 14:16:37 UTC
Permalink
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
Post by g***@fdlservizi.com
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?
Post by Tavian Barnes
Guice.createInjector() is slow, is it possible to avoid calling it in
a
Post by Tavian Barnes
loop? E.g. by creating the injector once outside the loop and only
calling
Post by Tavian Barnes
.getInstance() inside the loop?
Post by g***@fdlservizi.com
I have a strange performance behavior with google guice in my
project
Post by Tavian Barnes
Post by g***@fdlservizi.com
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
Post by Tavian Barnes
Post by g***@fdlservizi.com
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
Post by Tavian Barnes
Post by g***@fdlservizi.com
bolla_letture bl, bolla b, fat where
b.id_centro_subentro = ? and
b.id_fat =
fat.id
Post by Tavian Barnes
Post by g***@fdlservizi.com
and
fat.dt>=?
and
Post by Tavian Barnes
Post by g***@fdlservizi.com
fat.dt<= ? and
bl.id_bolla
=
Post by Tavian Barnes
Post by g***@fdlservizi.com
b.id
ORDER by
bl.dt asc
Post by Tavian Barnes
Post by g***@fdlservizi.com
""",
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,
Post by Tavian Barnes
Post by g***@fdlservizi.com
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
Post by Tavian Barnes
Post by g***@fdlservizi.com
method, and getListByQuery have Guice createInjector inside
resMesiFatturazionePerAnno is invoked from codes inside a batch
script,
Post by Tavian Barnes
Post by g***@fdlservizi.com
so invoken 20/30.000 times over different instance of CLASS A
depends from where i invoke resMesiFatturazionePerAnno in some case
i can
Post by Tavian Barnes
Post by g***@fdlservizi.com
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));
Post by Tavian Barnes
Post by g***@fdlservizi.com
take 10 milliseconds to executes, but if invoked from other
circumstance
Post by Tavian Barnes
Post by g***@fdlservizi.com
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?
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/b8cb8183-50d5-4d39-8d00-68f97afd3557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/E3D44091-03AA-45A1-96EC-5AB4F8962ADA%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Loading...