EJB Performance Questions


EJB programming & troubleshooting: EJB Performance Questions

  1. EJB Performance Questions (11 messages)

    What is the best way to return a collection containing 100,000 objects to a JSP for displaying in a table?

    If I have a single server with the web container and EJB container in the same JVM, do session beans need to be remotely accessable?

    How does clustering work (say in JBoss for example)? What role does RMI/IIOP play in clustering? Can you cluster the database? How is CMP used in a clustering environment?

    How does the performance of JBoss compare (in general terms) to commerical J2EE servers?

    Cameron Zemek,
    Software Engineer

    Threaded Messages (11)

  2. EJB Performance Questions[ Go to top ]

    I suggest using "Data Transfer Rowset" pattern to transfer the data in a tabular fashion to Client..
    Hope this helps,
  3. EJB Performance Questions[ Go to top ]

    hmmm. Looks interesting. Is there anything similar that does not need the client to know the name of the database column names? Eg, the RowSet provides the column names so the table gets the heading names from the RowSet.
  4. EJB Performance Questions[ Go to top ]

    To put 100.000 objects in a jsp, certainly don't use entity ejb's. I would make a session ejb that is responsible for reading the part of the 100.000 you currenly want to display. It's interface would contain a method
         List getObjects(int first_index, int number).
    The list would contain serializable java objects, probably a class that represents a row from your table, having public fields (a value object).
    The implementation opens a connection from a datasource (deployment parameter) and performs the sql to select the objects from the database, and java code to turn the resultset into a List of objects. The jsp page looks up the session ejb using jndi, and calls the getObjects() with first_index and number like the user wants it (paging mechanism). Then it iterates over the list and renders each object as a table row.

    Do session beans need to be remotely accessable? No; the app servers will see that the ejb is in the same app server as the web app, and will perform a local java call in stead of a remote call.

    Clustering: I think request (http requests to web apps, or ejb method calls) are dispatched in one central point. The central point knows the replicated services (for example 10 machines running the same web app, and 10 others running the same stateless ejb's) and their jndi name, and uses a kind of round robin to share the load. I have no idea how entity beans can be clustered.

    Databases can be replicated, and the replicas can be synchronized (so that an insert in the first one also happens in the second one), but that is functionality you have to look for in a database forum.
  5. EJB Performance Questions[ Go to top ]

    Please tell me if this is wrong (according to the spec). I programmed a BMP entity bean on JBoss 3.0 that had a finder method that return only the primary keys. Could I not write a finder method that return a collection of value objects?
  6. EJB Performance Questions[ Go to top ]

    For BMP use the Bulk Load Primary Key, but if your using jboss 3.0 use CMP 2 since it is optimized and should cache column data besides the primary keys. Look at Commit Options and the jboss DD for optimizations.

    Anyway for standard RDBMS there is no longer any reason to use BMP. Unless you need some obscure features, and I don't mean ORDER BY( vendors provide that or in EJB 2.1). Group By you would not usually use for getting individual rows anyway.


  7. EJB Performance Questions[ Go to top ]

    If you want to have a bulk load, don't use the BMP because it will result in N+1 database calls if N entity beans are loaded. Instead,try to use CMP if possible because different servers have adopted some optimization techiques to make CMP more effective than BMP. Unless, there are some special reason such as accessing db through stored procedure, try to avoid using BMP.

    With regard to clustering of app server, as far as l know, if app server support sticky load balancing and it is enabled, usually the invocation of web tier to ejb tier will be within same JVM. (if l am wrong, please correct me)

  8. EJB Performance Questions[ Go to top ]

    I don't think I made myself clear. Can a entity bean have a finder method that returns a collection of value objects (aka data transfer objects)? I have done this with JBoss but is it correct according to the specs. This will not result in N+1 database calls because I am not loading the entity beans.
    String query = "SELECT * FROM CUSTOMERS";
    ResultSet rs = stmt.executeQuery(query);
    Collection allCustomers = new ArrayList();
    while (rs.next()) {
      CustomerDTO customer = new CustomerDTO();
    return allCustomers;
  9. EJB Performance Questions[ Go to top ]

    Sorry about the tangent, but finder methods that return Collections that contain Entity Beans. The Bean implementation (BMP) may return Primary Keys, but the container creates a collection of EB based on that collection of keys to the Home Stub.

    For the type of retrieval you are doing you can use a Session Bean that performs the straight SQL and create the DTO's and save the overhead of going thru the container.

    I've done this with EJB 1.0 projects.

  10. EJB Performance Questions[ Go to top ]

    What overhead? The entity bean is doing the same thing that the session bean would. And both session beans and entity beans have the same overhead. I don't understand why I should have to do this in the session bean since it is related to entities. Session beans are good for workflow so the client does have to interact across entity beans (see the EJB Design Patterns book available on this site) and thereby providing a single point of access. However, what I am talking about could be done by directly accessing the entity bean. The entity bean avoids the container overhead when loading the collection of value objects (data transfer objects) by using JDBC.

    I have seen many people recommend using a session bean. But I don't understand why not to do it in an entity bean. As already mentioned if I load entity beans it results in N+1 database calls. But the example I have given does not do this. The question is if it is correct according to the specs for an entity bean finder method to return a collection of value objects (NOT entity beans).
  11. EJB Performance Questions[ Go to top ]

    Answering my own question:
    It appears to me that a finder method (ejbFind) cannot return a collection of value objects. It must return a collection of primary keys if the finder method finds more then one match. However could I add a Home method (eg. getAll()) that returns a collection of value objects. I believe this would make more sense then having a session bean do this.

    I was reading somewhere that CMP has select methods (ejbSelect) that can bulk load data. Can anyone give me some information on this?
  12. EJB Performance Questions[ Go to top ]

    Having read part 2 of the "Master EJB 2" and parts of "EJB Design Patterns" books I now understand where I was getting confused. With local interfaces I should not have the entity bean return value objects (this is an EJB 1.1 pattern). Using CMP can solve the N+1 calls problem, otherwise it is better to use a session bean which directly accesses the database. Sorry I didn't understand earlier posts which explained this.

    Thanks for the help, everyone.