1 Reply Latest reply on Apr 2, 2004 10:59 PM by nraghuram

    read-ahead cache preload doesn't work with JSP/CMP

    baijingyu

      I have a application which was deployed on OC4J application server and now need to be migrated to JBoss. After I change all the CMP ejb beans and successfully depoyed to JBoss 3.2.3 I found that the speed is extremly slow. By using profiling tool I found it was a JBoss CMP beans cause the peformance issue. Every time a JSp call CMP bean's get method will cause a database SQL call (n+1 issue). the simple snippet is like:

      Object objRef = initialContext.lookup("ejb/LocalSessionActivitiesEJB");
      SessionActivitiesHome home = (SessionActivitiesHome) objRef;
      Collection collection = home.findAll();
      for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
      SessionActivities sa= (SessionActivities) iterator.next();
      String id = sa.getName();
      }

      The detailed log related to cache act(enable TRACE):
      ==================================
      JSP call to CMP:

      Executing SQL: SELECT t0_s.ID FROM SESSION_ACTIVITIES t0_s
      Add finder results: entity=SessionActivities results=[[.101.], [.102.], [.647.]] readahead=[JDBCReadAheadMetaData : strategy=on-load, pageSize=240, eagerLoadGroup=*]
      RESET PERSISTENCE CONTEXT: id=[.101.]
      load data: entity=SessionActivities pk=[.101.]
      No preload data found: entity=SessionActivities pk=[.101.]
      Default eager-load for entity: readahead=null
      Executing SQL: SELECT MANDATORY_IND, COMPLETED_IND, ACT_COMMENTS, PLANNED_START_DATE, PLANNED_END_DATE, ACTUAL_START_DATE, ACTUAL_END_DATE, SESSACT_SEQ, SESSACT_TYPE, ROLE_ROLE, SESSACTTYP_ID, SESS_ID, AGEN_UID, TASK_1_ID, SESSUSR_USERID, SWIN_ID, EXTWIN_ID FROM SESSION_ACTIVITIES WHERE (ID=?)
      Set parameter: index=1, jdbcType=INTEGER, value=101
      RESET PERSISTENCE CONTEXT: id=[.102.]
      load data: entity=SessionActivities pk=[.102.]
      No preload data found: entity=SessionActivities pk=[.102.]
      Default eager-load for entity: readahead=null
      Executing SQL: SELECT MANDATORY_IND, COMPLETED_IND, ACT_COMMENTS, PLANNED_START_DATE, PLANNED_END_DATE, ACTUAL_START_DATE, ACTUAL_END_DATE, SESSACT_SEQ, SESSACT_TYPE, ROLE_ROLE, SESSACTTYP_ID, SESS_ID, AGEN_UID, TASK_1_ID, SESSUSR_USERID, SWIN_ID, EXTWIN_ID FROM SESSION_ACTIVITIES WHERE (ID=?)
      Set parameter: index=1, jdbcType=INTEGER, value=102
      Store command NOT executed. Entity is not dirty: pk=[.102.]
      ...

      ======================
      Session bean call to CMP

      Executing SQL: SELECT t0_s.ID FROM SESSION_ACTIVITIES t0_s
      Add finder results: entity=SessionActivities results=[[.101.], [.102.], [.647.]] readahead=[JDBCReadAheadMetaData : strategy=on-load, pageSize=240, eagerLoadGroup=*]
      RESET PERSISTENCE CONTEXT: id=[.101.]
      load data: entity=SessionActivities pk=[.101.]
      No preload data found: entity=SessionActivities pk=[.101.]
      Eager-load for entity: readahead=[JDBCReadAheadMetaData : strategy=on-load, pageSize=240, eagerLoadGroup=*]
      Executing SQL: SELECT ID, MANDATORY_IND, COMPLETED_IND, ACT_COMMENTS, PLANNED_START_DATE, PLANNED_END_DATE, ACTUAL_START_DATE, ACTUAL_END_DATE, SESSACT_SEQ, SESSACT_TYPE, ROLE_ROLE, SESSACTTYP_ID, SESS_ID, AGEN_UID, TASK_1_ID, SESSUSR_USERID, SWIN_ID, EXTWIN_ID FROM SESSION_ACTIVITIES WHERE (ID=?) OR (ID=?) OR (ID=?)
      Set parameter: index=1, jdbcType=INTEGER, value=101
      Set parameter: index=2, jdbcType=INTEGER, value=102
      ...(other Set parameter )
      Add preload data: entity=SessionActivities pk=[.101.] field=mandatory_ind
      Add preload data: entity=SessionActivities pk=[.101.] field=completed_ind
      ...(other Add preload )

      RESET PERSISTENCE CONTEXT: id=[.102.]
      load data: entity=SessionActivities pk=[.101.]
      Preloading data: entity=SessionActivities pk=[.101.] cmpField=agen_uid
      Preloading data: entity=SessionActivities pk=[.101.] cmpField=sess_id
      ... (other Preloading)

      ...

      ==================================

      OC4J doean't have this issue before and will cache the database data even call a CMP from JSP but it seems JBoss will ONLY cache (using on-find or on-load strateg) database data when you call a CMP withing the same EJB container which mean you have to call a CMP from a session bean. I noticed here that JSP page can get Local EJB home and interface and EJB contaoner should smart enough to enable cache. Who can confirm that this is a not bug and I need some extra configuratrion? I hope I don't have to rewrite the old code to change all calls from JSP/ CMP to JSP/Session bean /CMP and this will be a nightmare to me(huge change). All I want is the running version and reasonable peformance. Is any way I can avoid to change the whole jsp file and enjoy the JBoss CMp cache benefit? Thanks in advance.

        • 1. Re: read-ahead cache preload doesn't work with JSP/CMP
          nraghuram

          Caching of data depends on the entity bean's container configuration and the transaction context.
          If the commit option is set to 'B' or 'C' data is loaded from the db every time a new transaction starts. Are your method calls all happening in one transaction.
          It is only with commit option A that there is genuine caching.
          If your commit option is 'B' or 'C' and your method calls are not happening in a single transaction you will not get any caching benefits.
          Raghu