Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsutherla2013-03-07 14:38:27 -0500
committerjsutherla2013-03-07 14:38:27 -0500
commit7fb2f29e049d8781e79c067faba2b9124d580376 (patch)
treecfc08df48ca9b8c60822d1b3e56edefc01247167
parent4d2839e1ebb9b1d9aef95684219cc5eff0404215 (diff)
downloadperformance-7fb2f29e049d8781e79c067faba2b9124d580376.tar.gz
performance-7fb2f29e049d8781e79c067faba2b9124d580376.tar.xz
performance-7fb2f29e049d8781e79c067faba2b9124d580376.zip
Adds a cache index test to the benchmark
-rw-r--r--cache/benchmark.zipbin14045 -> 16641 bytes
-rw-r--r--cache/src/META-INF/persistence.xml63
-rw-r--r--cache/src/META-INF/query-cache.xml1
-rw-r--r--cache/src/example/Test.java65
-rw-r--r--cache/src/model/Customer.java2
-rw-r--r--cache/src/model/Order.java5
6 files changed, 108 insertions, 28 deletions
diff --git a/cache/benchmark.zip b/cache/benchmark.zip
index 1e21071..2be6daa 100644
--- a/cache/benchmark.zip
+++ b/cache/benchmark.zip
Binary files differ
diff --git a/cache/src/META-INF/persistence.xml b/cache/src/META-INF/persistence.xml
index fceaccd..88efe1b 100644
--- a/cache/src/META-INF/persistence.xml
+++ b/cache/src/META-INF/persistence.xml
@@ -7,7 +7,7 @@
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>model.Order</class>
<class>model.OrderLine</class>
- <class>model.Customer</class>
+ <class>model.Customer</class>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<!-- Change this to access your own database. -->
@@ -19,8 +19,9 @@
<property name="javax.persistence.jdbc.url" value="jdbc:derby:test;create=true" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" /-->
- <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.jdbc.cache-statements" value="true" />
+ <property name="eclipselink.jdbc.batch-writing" value="jdbc" />
<property name="eclipselink.logging.level" value="off" />
<property name="eclipselink.orm.validate.schema" value="true"/>
</properties>
@@ -157,4 +158,62 @@
<!--property name="eclipselink.logging.level" value="FINE" /-->
</properties>
</persistence-unit>
+ <persistence-unit name="db-query-cache" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>model.Order</class>
+ <class>model.OrderLine</class>
+ <class>model.Customer</class>
+ <shared-cache-mode>NONE</shared-cache-mode>
+ <mapping-file>META-INF/db-query-cache.xml</mapping-file>
+ <properties>
+ <!-- Change this to access your own database. -->
+ <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:oracle:oci:@localhost:1521:orcl" />
+ <property name="javax.persistence.jdbc.user" value="scott" />
+ <property name="javax.persistence.jdbc.password" value="tiger" />
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.jdbc.cache-statements" value="true" />
+ <property name="eclipselink.logging.level" value="off" />
+ <property name="eclipselink.orm.validate.schema" value="true"/>
+ <!--property name="eclipselink.logging.level" value="FINE" /-->
+ </properties>
+ </persistence-unit>
+ <persistence-unit name="database-index" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>model.Order</class>
+ <class>model.OrderLine</class>
+ <class>model.Customer</class>
+ <mapping-file>META-INF/database-index.xml</mapping-file>
+ <properties>
+ <!-- Change this to access your own database. -->
+ <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
+ <property name="javax.persistence.jdbc.user" value="scott" />
+ <property name="javax.persistence.jdbc.password" value="tiger" />
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
+ <property name="eclipselink.jdbc.cache-statements" value="true" />
+ <property name="eclipselink.logging.level" value="off" />
+ <property name="eclipselink.orm.validate.schema" value="true"/>
+ <!--property name="eclipselink.logging.level" value="FINE" /-->
+ </properties>
+ </persistence-unit>
+ <persistence-unit name="cache-index" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>model.Order</class>
+ <class>model.OrderLine</class>
+ <class>model.Customer</class>
+ <mapping-file>META-INF/cache-index.xml</mapping-file>
+ <properties>
+ <!-- Change this to access your own database. -->
+ <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:oracle:oci:@localhost:1521:orcl" />
+ <property name="javax.persistence.jdbc.user" value="scott" />
+ <property name="javax.persistence.jdbc.password" value="tiger" />
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.jdbc.cache-statements" value="true" />
+ <property name="eclipselink.logging.level" value="off" />
+ <property name="eclipselink.orm.validate.schema" value="true"/>
+ <!--property name="eclipselink.logging.level" value="FINE" /-->
+ </properties>
+ </persistence-unit>
</persistence>
diff --git a/cache/src/META-INF/query-cache.xml b/cache/src/META-INF/query-cache.xml
index a876a8f..bc944f0 100644
--- a/cache/src/META-INF/query-cache.xml
+++ b/cache/src/META-INF/query-cache.xml
@@ -6,6 +6,7 @@
<named-query name="findOrdersByCustomer">
<query>Select o from Order o where o.customer.id = :customerId</query>
<hint name="eclipselink.query-results-cache" value="true"/>
+ <hint name="eclipselink.query-results-cache.size" value="100000"/>
</named-query>
</entity-mappings>
diff --git a/cache/src/example/Test.java b/cache/src/example/Test.java
index 6208983..093a86e 100644
--- a/cache/src/example/Test.java
+++ b/cache/src/example/Test.java
@@ -31,7 +31,7 @@ import model.OrderLine;
* @author James Sutherland
*/
public abstract class Test extends PerformanceTest {
- public static int SIZE = 1000;
+ public static int SIZE = 10000;
long[] orderIds = new long[SIZE];
long[] customerIds = new long[SIZE/10];
@@ -43,30 +43,12 @@ public abstract class Test extends PerformanceTest {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("database");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
- Order order = null;
em.createQuery("Delete from OrderLine").executeUpdate();
em.createQuery("Delete from Order").executeUpdate();
em.createQuery("Delete from Customer").executeUpdate();
- int index = 0;
- for (int customerIndex = 0; customerIndex < (SIZE /10); customerIndex++) {
- Customer customer = new Customer();
- customer.setName("Customer-" + index);
- em.persist(customer);
- this.customerIds[customerIndex] = customer.getId();
- for (int orderIndex = 0; orderIndex < 10; orderIndex++) {
- order = new Order();
- order.setDescription("Order-" + index);
- order.setCustomer(customer);
- order.addOrderLine(new OrderLine("line1", new BigDecimal(10)));
- order.addOrderLine(new OrderLine("line2", new BigDecimal(5)));
- order.addOrderLine(new OrderLine("line3", new BigDecimal(99)));
- em.persist(order);
- this.orderIds[index] = order.getId();
- index++;
- }
- }
em.getTransaction().commit();
em.close();
+ populate(factory);
this.factories.put("database", factory);
factory = Persistence.createEntityManagerFactory("cache");
@@ -93,24 +75,61 @@ public abstract class Test extends PerformanceTest {
factory.createEntityManager().close();;
this.factories.put("query-cache", factory);
+ factory = Persistence.createEntityManagerFactory("db-query-cache");
+ factory.createEntityManager().close();;
+ this.factories.put("db-query-cache", factory);
+
factory = Persistence.createEntityManagerFactory("in-memory");
- em = factory.createEntityManager();
+ // ** comment this persistence unit out for very large database sizes (can't load all into memory).
+ /*em = factory.createEntityManager();
List<Order> results = em.createQuery("Select o from Order o").getResultList();
for (Order result : results) {
result.getCustomer().toString();
result.getOrderLines().size();
}
- em.close();
+ em.close();*/
this.factories.put("in-memory", factory);
}
+
+ public void populate(EntityManagerFactory factory) {
+ EntityManager em = factory.createEntityManager();
+ int index = 0;
+ for (int customerIndex = 0; customerIndex < (SIZE /10); customerIndex++) {
+ em.getTransaction().begin();
+ Customer customer = new Customer();
+ customer.setName("Customer-" + customerIndex);
+ em.persist(customer);
+ this.customerIds[customerIndex] = customer.getId();
+ for (int orderIndex = 0; orderIndex < 10; orderIndex++) {
+ Order order = new Order();
+ order.setDescription("Order-" + index);
+ order.setCustomer(customer);
+ order.addOrderLine(new OrderLine("line1", new BigDecimal(10)));
+ order.addOrderLine(new OrderLine("line2", new BigDecimal(5)));
+ order.addOrderLine(new OrderLine("line3", new BigDecimal(99)));
+ em.persist(order);
+ this.orderIds[index] = order.getId();
+ index++;
+ }
+ em.getTransaction().commit();
+ em.clear();
+ System.out.println("Insert batch - " + customerIndex);
+ }
+ em.close();
+ }
public void test() {
- System.out.println("Begin benchmark");
this.executeRun("Database", new Runnable() {
public void run() {
runTest(factories.get("database"));
}
});
+ System.out.println("Begin benchmark");
+ this.executeRun("DBQueryCache", new Runnable() {
+ public void run() {
+ runTest(factories.get("db-query-cache"));
+ }
+ });
this.executeRun("Cache", new Runnable() {
public void run() {
runTest(factories.get("cache"));
diff --git a/cache/src/model/Customer.java b/cache/src/model/Customer.java
index c1c0e90..679ef6f 100644
--- a/cache/src/model/Customer.java
+++ b/cache/src/model/Customer.java
@@ -22,6 +22,8 @@ import javax.persistence.*;
*/
@Entity
@Table(name="PERF_CUSTOMER")
+@NamedQuery(name="findCustomerByName",
+ query="Select c from Customer c where c.name = :name")
public class Customer implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
diff --git a/cache/src/model/Order.java b/cache/src/model/Order.java
index e880d47..1abbbd5 100644
--- a/cache/src/model/Order.java
+++ b/cache/src/model/Order.java
@@ -25,10 +25,9 @@ import javax.persistence.*;
*/
@Entity(name="Order")
@Table(name="PERF_ORDER")
-@NamedQueries({
- @NamedQuery(name="findOrdersByCustomer",
+@NamedQuery(name="findOrdersByCustomer",
query="Select o from Order o where o.customer.id = :customerId")
-})
+@org.eclipse.persistence.annotations.Index(columnNames="CUSTOMER_ID")
public class Order implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)

Back to the top