openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kuuldor <kuul...@gmail.com>
Subject Weird Performance Problem
Date Mon, 21 Jan 2008 14:27:16 GMT
Hi everybody,
I'm trying to use OpenJPA in my new project, but when I do some
experiments I encounter a very low performance in inserting records
into database.

My situation is like this:
Database is derby 10.2
A very simple table 'account' having a auto-increment ID, and a 'name'
field of varchar(16), and an 'fullname' field of varchar(32) and
'descript' of varchar(255).
Here is the create table SQL:
create table account (id integer not null generated always as
identity, name varchar(16) not null unique, fullname varchar(32),
descript varchar(255), constraint Account_Primary_ID primary key
(id));
My persistence.xml is like this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
 version="1.0">
 <persistence-unit name="Test" transaction-type="RESOURCE_LOCAL">
  <provider>
   org.apache.openjpa.persistence.PersistenceProviderImpl
  </provider>
  <class>test.Account</class>
  <properties>
    <property name="openjpa.ConnectionDriverName"
    value="org.apache.derby.jdbc.ClientDriver" />
   <property name="openjpa.ConnectionURL"
    value="jdbc:derby://localhost:1527/tsam2" />
   <property name="openjpa.ConnectionUserName" value="app" />
   <property name="openjpa.ConnectionPassword" value="app" />
   <property name="openjpa.Log" value="none" />
   <property name="openjpa.DataCache" value="true" />
   <property name="openjpa.RemoteCommitProvider" value="sjvm" />
  </properties>
 </persistence-unit>
</persistence>

And the Entity Class is:
package test;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.*;

@Entity()
@Table(name="ACCOUNT")
public class Account  implements Serializable {
 //default serial version id, required for serializable classes.
 private static final long serialVersionUID = 1L;
 private Integer id;
 private String descript;
 private String fullname;
 private String name;

    public Account() {
    }

 @Id()
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 @Column(name="ID", unique=true, nullable=false, precision=10)
 public Integer getId() {
  return this.id;
 }
 public void setId(Integer id) {
  this.id = id;
 }

 @Basic()
 @Column(name="DESCRIPT", length=255)
 public String getDescript() {
  return this.descript;
 }
 public void setDescript(String descript) {
  this.descript = descript;
 }

 @Basic()
 @Column(name="FULLNAME", length=32)
 public String getFullname() {
  return this.fullname;
 }
 public void setFullname(String fullname) {
  this.fullname = fullname;
 }

 @Basic()
 @Column(name="NAME", unique=true, nullable=false, length=16)
 public String getName() {
  return this.name;
 }
 public void setName(String name) {
  this.name = name;
 }

 public boolean equals(Object other) {
  if (this == other) {
   return true;
  }
  if (!(other instanceof Account)) {
   return false;
  }
  Account castOther = (Account)other;
  return new EqualsBuilder()
   .append(this.getId(), castOther.getId())
   .isEquals();
    }

 public int hashCode() {
  return new HashCodeBuilder()
   .append(getId())
   .toHashCode();
    }

 public String toString() {
  return new ToStringBuilder(this)
   .append("id", getId())
   .toString();
 }
}

My test is to insert 1000 records into the table. The test code is like this:
 private static void insertJPA() throws DAOException, SQLException {
  DAOFactory daoF = new DAOFactory();
  AccountDao accountDao = daoF.getAccountDao();
  System.out.println(new java.util.Date().toString());

  for (int i = 0; i<1000; i++)
  {

   TransactionProxy tran = accountDao.beginTransaction();
   Account newuser = new Account();
   newuser.setName("user" + i);
   //newuser.setFullname("User No. " + i);
   //newuser.setDescript("Common user");
   accountDao.insert(newuser);
   accountDao.commitTransaction(tran);
  }
 }


This test can only finish in about 1min 30sec, equals to 11rec/sec. If
I get rid of the fullname and descript fields from the table. The time
can be shorten to 32sec. But it still be quite slow. I've done the
test with BEA Kodo which is based on OpenJPA. Kodo can insert the 1000
record in 9sec, about 10 times faster than OpenJPA. And I did not do
any optimization for Kodo.

So anybody knows why the performance of OpenJPA is so slow? Or how to
optimize OpenJPA to achieve the performance near Kodo?

Thanks a lot.

Mime
View raw message