-
15. Re: Big performance problem
mkotsbak Apr 13, 2002 7:23 PM (in response to jl1)> I agree. I have also seen this, and I am sure it can
> be made better, by using "IN"-sql-statement or
> joining. I have reported this as a bug
> (http://sourceforge.net/tracker/?func=detail&aid=53273
> &group_id=22866&atid=376685).
> It is assigned, but not resolved.
Bug #532734 (the url seems to be just for my login) -
16. Re: Big performance problem
wchao Apr 14, 2002 10:32 AM (in response to jl1)I'm having the same problem. It's a pretty serious issue. I'm getting the same behavior with returning a Collection of objects from a find query. The CMP engine queries (id = 1) or (id = 2) or ... or (id = n) on the first query, then (id = 1) or ... or (id = n - 1) on the second query, all the way down to (id = 1) on the nth query, which means n*(n-1)/2 = 1/2*(n^2 - n) queries are being done! Any reason the implementation is not optimized at least for the simple findAll and findByXXX (where XXX is a single column) cases? I'm not quite clear why JBoss doesn't just do a single "select * from tableName where (id = {x})" for each unique instance of the primary key, which is n queries. It wouldn't be blazingly fast, but would be livable.
-
17. Re: Big performance problem
wchao Apr 14, 2002 1:11 PM (in response to jl1)I solved my problem. I was accessing the EJBs from a client (a servlet). Dain suggested I used transactions, which was a big help. Thanks Dain! Now there is just one query instead of (n*(n-1)/2) + 1 and things are very efficient. In case anybody else has the same problem, I just used explicit transactions like so:
InitialContext jndiContext = new InitialContext();
UserTransaction utx = (UserTransaction)jndiContext.lookup("java:comp/UserTransaction");
utx.begin();
...
// code that fetches EJB objects and copies them to value objects
...
utx.commit();
The commented part would just be something like myEJBCollection = myEJBHome.findByXXX(aColumnValue), and then you'd iterate through and copy out the values you need from the EJBs. -
18. Re: Big performance problem
mkotsbak Apr 14, 2002 1:18 PM (in response to jl1)> I solved my problem. I was accessing the EJBs from a
> client (a servlet). Dain suggested I used
> transactions, which was a big help. Thanks Dain! Now
> there is just one query instead of (n*(n-1)/2) + 1
> and things are very efficient. In case anybody else
> has the same problem, I just used explicit
> transactions like so:
>
> InitialContext jndiContext = new InitialContext();
> UserTransaction utx =
> (UserTransaction)jndiContext.lookup("java:comp/UserTra
> saction");
> utx.begin();
> ...
> // code that fetches EJB objects and copies them to
> value objects
> ...
> utx.commit();
>
> The commented part would just be something like
> myEJBCollection = myEJBHome.findByXXX(aColumnValue),
> and then you'd iterate through and copy out the
> values you need from the EJBs.
I hope you run the VO-filling code in a session bean, not from the servlet. You should, and then you don't need to do start an explicit transaction, but it will be started when the sessionbean-method is called. -
19. Re: Big performance problem
wchao Apr 14, 2002 1:49 PM (in response to jl1)Right now it's a stop-gap measure. I plan to implement a Session EJB that does the lookup and copying to value objects. You're right that it will obviate the need for manual transactions. I'll just specify a transaction attribute of "Required" in the Session EJB. The other benefit is that less data will travel over the connection. I'll probably use the DynaBean interface from the Apache project to make it easy to specify exactly what fields I want.
-
20. Re: Big performance problem
mkotsbak Apr 14, 2002 1:58 PM (in response to jl1)Where can I find some doc on DynaBean?
-
21. Re: Big performance problem
wchao Apr 14, 2002 3:08 PM (in response to jl1)http://jakarta.apache.org/commons/beanutils.html
Grab the nightly download. It will include javadocs. It's a pretty useful package. You don't have to create separate one-off classes for each and every value object you want. It also ties in really well with Struts. -
22. Re: Big performance problem
lasterra Apr 14, 2002 10:31 PM (in response to jl1)Maybe an entry in the FAQ Forum to explain better where people should do reads from database using finders????
This will help me (and i think other people) a lot. I think the documentation is not very clever about how to use transactions and commit options.
Regards, Enrique. -
23. Re: Big performance problem
jl1 Apr 15, 2002 3:31 AM (in response to jl1)Hello,
I am also using the read-ahead stuff in jbosscmp-jdbc.xml:
<read-ahead>
on-load
<page-size>1000</page-size>
<eager-load-group>*</eager-load-group>
</read-ahead>
<list-cache-max>1000</list-cache-max>
But it does not seem to be processed since the behavior is the same, no SQL statement is executed before the first call to a get method, even when I define on-find.
Thanks,
Jerome. -
24. Re: Big performance problem
pajama Apr 16, 2002 1:03 AM (in response to jl1)If you use "Required" transaction level for the Session Beans wrapping the Entity Beans, what is the transaction level for the Entity Beans? None?
Thanks in advance...
Ricardo -
25. Re: Big performance problem
jl1 Apr 16, 2002 3:04 AM (in response to jl1)I believe required is ok, unless you need a new transaction for each entity bean. If you use required for both the session bean and the entity beans, then on call a new transaction will be started for the session bean and entity calls will be encapsulated within that transaction.
Regards,
Jerome.