`

Hibernate, Toplink Essentials, Openjpa, Eclipselink (jpa implementation compare)

阅读更多

http://www.chrisshayan.com/my/index.php?option=com_content&view=article&id=70:jpa-implementations-comparison-hibernate-toplink-essentials-openjpa-eclipselink-&catid=42:technologies&Itemid=65

 

Summary
This article is a response to the lack of information on the net about the performance differences among the 4 most well known Java Persistence API (JPA) implementations: Toplink Essentials , EclipseLink , Hibernate and OpenJPA .
Besides results and conclusions, the full test code is also available in case you want to repeat the test yourself.

I wrote a relatively simple program which executes some queries and inserts in a MySQL database through JPA. Four fixed-time tests were done with exactly the same code, just changing the JPA implementation library and the persistence.xml. I monitored the resources used by the JVM and counted the inserts and queries executed during the tests. Finally, I show here my conclusions and also the results of these tests, so that you can draw your own. I consider the differences found among the different implementations truly relevant.
For the tests performed for this article, nothing except JPA was used. No web pages, no web or application server. Just java threads, JPA and MySQL. I give more details in the next sections.


Note : In case you are using JPA with Axis and/or the Google Web Toolkit (GWT), this other article focused on working with JPA, Axis and GWT could be of interest for you.

Description of hardware and software

The tests have been done in an Acer Extensa 5620G laptop, with a pentium Core 2 Duo T5250 Processor with 2 Gb Ram DDR2, being monitored by a standard PC.
For the tests I have used the following software:
  • Ubuntu 8.10 Intrepid Ibex
  • MySQL database, version 5.0 (installed from the official Ubuntu repositories).
  • Java Virtual Machine 1.6
  • Driver jdbc for MySQL 5.1.
  • Eclipse Ganymede
  • The employees database example for MySQL, courtesy of Patrick Crews and Giuseppe Maxia (url below in the references section)
  • JConsole for resources monitoring
  • GIMP 2 to capture screens
The database and the JVM were running in the Acer machine. But both JConsole and GIMP were executed in a PC (also equiped with Ubuntu 8.10) connected via tcp/ip to the test machine. I did it so that I did not overload the machine running the tests.
Versions of the JPA implementations tested:
  • Hibernate EntityManager and Annotations 3.4.0
  • Toplink Essentials version 2 build 41
  • Openjpa 1.2.0
  • Eclipselink 1.0.2
Description of the code
The code developed for the tests is available to download here . All you have to do is import the zip file in Eclipse . You will need at least one of the JPA implementation libraries. You can download them from the urls in the references section below.
The code is made up of two type of threads, one for inserting and one for querying.
Inserting thread gets an arbitrary employee and makes a copy of him/her, letting MySQL generate a new emp_no. This was the only modification I did to the employees database: the emp_no is auto-generated.
Querying threads execute all these queries in sequence:
  • A query returning the number of female employees.
  • A query returning the number of male employees.
  • A query returning all employees hired since an arbitray date.
  • A query returning all employees born after an arbitrary date.
  • A query returning all women who have earned more than an arbitrary salary.
I have also created an independent class JPAManager, which is in charge of creating the static EntityManagerFactory and the EntityManager for each of the threads. You have the details of that class here .

This is the starting sequence:

  1. When the program starts, it waits 2 minutes for the monitoring infraestructure to be ready (connecting JConsole to the JVM, basically).
  2. It then starts 2 of the so-called inserting threads. I start the inserting threads before the querying threads trying that the queries do not always return the same (which will eventually happen, anyway).
  3. After starting the inserting threads, the program starts running 18 of the querying threads, inserting a pause of 10 seconds before starting next. This is so that they do not execute the same query at the same time.
  4. The program runs the threads for 30 minutes. After that time, it sends a stop signal to the threads, which will safely make them stop after the next inserting or querying round. The main program waits 15 minutes for the threads to stop and the jvm memory to stabilize.
  5. Before stopping, the threads provide information about the number of inserts/queries they have executed.
The only change from test to test was the JPA implementation library and the persistence.xml. It is important to notice that the persistence.xml was left by default for each of the implementations, omitting on purpose any kind optimization that the implementation could accept.

Results
These were the results of the tests per JPA implementation library. Notice that the time was fixed: 30 minutes running.
  Number of queries+inserts executed Number of queries executed Number of inserts executed Max mem occupied during the test(Mb) Mem occupied after the test(Mb)
OpenJPA 3928
3530 398 96
61
Hibernate 12687
3080 9607 130 79
Toplink Essentials
5720
3740 1980 55 25
Eclipselink
5874
3735 2139 57 25

The maximum memory occupied is the maximum amount that the JVM reserved during the test.
The memory occupied after the test is the amount of memory that remained reserved after finishing the test.
I have emphasized the highest and lowest values for each of the columns.
You can see this graphically in the following images showing the data monitored during the different tests.
 
  http://3.bp.blogspot.com/_VnVvmksSsVY/SXMNKekU_vI/AAAAAAAAAKU/A8pm9no5EwE/s1600-h/openjpa-complete.png
http://2.bp.blogspot.com/_VnVvmksSsVY/SXMNKB2YF4I/AAAAAAAAAKM/B13HTy_yq-Q/s1600-h/hibernate-complete.png
http://1.bp.blogspot.com/_VnVvmksSsVY/SXMNKrN1TuI/AAAAAAAAAKc/YGW3IPjy84U/s1600-h/toplink-complete.png
http://4.bp.blogspot.com/_VnVvmksSsVY/SXMNJg0AXSI/AAAAAAAAAKE/KJ2Ud70nyX8/s1600-h/eclipselink-complete.png
Conclusions
My intention is that anyone can draw their own conclusions looking at the results or using the code to do a test of their own.
Nevertheless, I consider that there are a number of conclusions that one can draw watching the monitored data:
  1. There is not an implementation that clearly has the best performance. Some had a very good CPU or memory performance and some did it very well when inserting or querying. But none of them was outstanding as a whole.
  2. The number of records inserted by Hibernate was extremely higher than it was for any other implementation (4 times more compared to Eclipselink and 24 times more compared to OpenJPA). However, Hibernate was also the JPA implementation that executed the lowest number of queries, although the differences in this value (3080 for Hibernate vs 3740 for Toplink Essentials) are not so extreme as for the number of inserts.
  3. Hibernate was also the implementation that consumed more memory. But having into account that it inserted many more records than the others, it sounds reasonable.
  4. OpenJPA had the lowest value of inserts+queries.
  5. The number of inserts executed by OpenJPA was extremely low, compared to the others.
  6. The usage of CPU in the case of Toplink Essentials and Eclipselink was extremely low.
Note for the JPA implementations responsible/developers : I am aware that some optimization can be obtained by changing the persistence.xml and/or changing the code somehow. If you give me some advice on how to improve the performance of any of the implementations, I will be glad to update this post with that information.

References
Ubuntu: http://www.ubuntu.com/
Employees database: http://dev.mysql.com/doc/employee/en/employee.html , https://launchpad.net/test-db/
Openjpa: http://openjpa.apache.org/
Toplink Essentials: http://www.oracle.com/technology/products/ias/toplink/jpa/download.html
Hibernate JPA: http://www.hibernate.org/397.html
Eclipselink: http://www.eclipse.org/eclipselink/
MySQL: http://www.mysql.com/
Eclipse: http://www.eclipse.org/
 
Journal is from http://terrazadearavaca.blogspot.com/2008/12/jpa-implementations-comparison.html
 
分享到:
评论

相关推荐

    JPA教程,包括TOPLink JPA,Hibernate JPA,Open Jpa,jpa批注

    TOPLink JPA的优势在于其高性能和对复杂数据模型的良好支持,同时也能够无缝集成到EclipseLink(Oracle的开源持久化框架)中,提供了广泛的持久化服务。 **2. Hibernate JPA** Hibernate是最早的ORM框架之一,后来...

    JPA-eclipselink-project:使用 EclipseLink 实现的 JPA 项目示例

    这个 API 有不同的实现:EclipseLik、Hibernate、TopLink、OpenJPA、...... API 提供类似于 SQL 的查询语言,但使用对象而不是数据库中的关系实体。 Java Persistence API 基于实体,这些实体是简单的带注释的 POJO...

    5.Hibernate 05 Hibernate结合JPA1

    JPA支持多种ORM实现,包括Hibernate、TopLink、OpenJPA等。 **2. JPA与Hibernate的关系** JPA是一个规范,而Hibernate是JPA的一个实现。这意味着你可以使用JPA的API来编写代码,而具体的数据访问逻辑则由Hibernate...

    EclipseLink JPA User Guide

    详细讲述了EclipseLink的使用方法。EclipseLink的前身是Oracle的TopLink.

    toplink-essentials.jar

    toplink-essentials.jar toplink-essentials.jar

    JPA和Hibernate的关系

    随着JPA标准的推广和被广泛采用,越来越多的厂商和框架开始支持JPA,其中包括Spring Framework、OpenJPA、EclipseLink(原TopLink)等。这种广泛的采纳使得JPA成为了一个重要的行业标准,为开发者提供了丰富的资源和...

    Toplink_JPA注解参考

    **Toplink JPA注解参考** Toplink JPA(Java Persistence API)是Oracle公司提供的一种对象关系映射(ORM)框架,它允许开发者使用Java对象来操作数据库,而无需直接编写SQL语句。JPA提供了丰富的注解,使得在Java...

    toplink-api.jar,toplink-essentials.jar

    此外,它还支持Java Persistence API (JPA)标准,使得TopLink能与其他遵循JPA规范的框架兼容,如Hibernate。 接着,我们来看`toplink-essentials.jar`。这个库文件包含了TopLink的实现部分,即实际执行ORM转换和...

    toplink-essentials-agent.jar

    toplink-essentials-agent.jar

    Oracle Toplink JPA

    Oracle Toplink JPA

    JPA操作手册,包括EJB3.0

    JPA的目标是提供一个简洁易用的接口,同时整合了多种流行的ORM技术的最佳实践,如Hibernate、TopLink等。 **EJB3.0**(Enterprise JavaBeans 3.0)是Java EE的一部分,它定义了一套用于构建企业级应用程序的标准...

    JPA、hibernate项目常用包

    现在引入了一组全新的 API:Java Persistence API JPA 以允许开发者管理 Java EE(甚至 SE)应用程序中的关系数据 另外 Sun 声称 Java Persistence API 表现了一些 Hibernate TopLink(二者都会在稍后讨论) JDO ...

    jpa-开发11

    除此之外,还有 OpenJPA,它是 Apache 软件基金会的一个开源项目,以及 TopLink,原本是商业产品,现在也已开源。 **2. JPA 的功能特点** - **ORM 映射元数据**:JPA 提供了注解和 XML 两种方式来定义对象与数据库...

    jpa toplink相关jar包,完整版。

    在Java EE环境中使用JPA TopLink,你需要包含相关的jar包以支持TopLink作为JPA的提供者。这些jar包通常包含了TopLink的实体管理器工厂、持久化单元配置、查询API以及其他必要的组件。"jpa_toplink"这个压缩包很可能...

Global site tag (gtag.js) - Google Analytics