Performance-Tuning Entity Beans

來源:互聯網
上載者:User

(from Mastering EJB2)

There is a great deal of fear, uncertainty, and doubt (FUD) in the industry
about entity beans. Many organizations are using them improperly, creating
performance issues. Here are some tips and tricks to make your entity beans
high performing:

■ Entity beans should not be called directly from remote clients, but rather
  from session or entity beans located in the same process. Because of this,
  you should always call entity beans through their local interfaces, not
  their remote interfaces.
 
■ Use your container's caching options as much as possible. If your beans
  are read-only, instruct your container to keep them cached permanently. If
  they are read-mostly or read-write, many containers have algorithms to
  deal with this. Remember: Memory is cheap.

■ Be sure your transactions run on the server, are as short as possible, and
  encapsulate all of the entity bean operations you'd like to participate in
  that transaction. This is important because the JDBC occurs at the begin-
  ning and end of transactions. If you have a transaction occurring for each
  entity bean get/set operation, you are performing SQL hits on each
  method call. The best way to perform transactions with entity beans is to
  wrap all your entity bean calls within a session bean method. Deploy both
  the session and entity beans with the container-managed transaction
  attribute of Required. Ths creates a transaction in the session bean that
  encapsulates all entity beans in the same transaction.

■ Consider having your container batch JDBC updates all at once at the end
  of the transaction. That way, if you perform many JDBC operations in a
  single transaction, you only need one network call to the database.
 
■ For performance, use container managed persistence, if possible. As con-
  voluted as it may sound, container managed persistence can actually be
  higher-performing than bean managed persistence. Just make sure that
  you're using a good persister that gives you great flexiblity when
  performing O/R mapping.

■ If you are not going to access your entire entity bean's data on each trans-
  action, lazy-load some of your fields rather than loading it all when the
  entity bean is first accessed. You can lazy-load your fields programmati-
  cally using BMP by fine-tuning your JDBC code, or you can lazy-load
  your fields declaratively using CMP if your container tools support it.
 
■ If you'r using CMP, instruct your container to persist fields in bulk. For
  example, BEA Weblogic has the notion of field groups. This empowers
  you to define groups of fields (even across relationships) that persist
  together, reducing the amount of SQL required.

■ If you're using CMP, use your container tools to force the container to
  have your finder methods automatically load your bean, rather than hav-
  ing finders and loading happen separately, resulting in two SQL state-
  ments. The only time you should not do this is if you're not going to read
  data from your entity bean (for example, setting fields, but not getting
  fields).
 
■ Send output to a good loggin/tracing system, such as a loggin
  message-driven bean. This allows you to understand the methods that
  are causing bottlenecks, such as repeated loads or stores.
 
■ Use a performance-profiling toll to identify bottlenecks, such as Opti-
  mizeIt or JProbe. If your program is hanging on the JDBC driver, chances
  are the database is your bottleneck.
 
Performance-tuning your entity beans opens up the possibility to create fine-
grained entity beans that model a single row in the database, as well as coarse-
grained entity beans that model a complex set of data spanning multiple tables.
   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.