You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by idan <id...@gmail.com> on 2010/07/11 09:17:51 UTC

OpenJPA MySQL performance overhead

Hi,

I'm using OpenJPA with MySQL.

I tested OpenJPA against basic JDBC calls and found that OpenJPA is 5 times
slower on basic INSERT queries, 2 times slower on basic SELECT queries (when
data is fetched from MySQL), UPDATE & DELETE queries.


Are these results reasonable?
 
Thanks,
Idan

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5279410.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
Thank you very much for the help and information.
>From what i understand, openjpa.ConnectionRetainMode="always" made a big
difference.

I understand any ORM has an overhead.. i just wanted to know if my initial
results were reasonable which appeared not to be and now look much better
:-)

I'm using DBCP's statements pooling so i guess its the same as creating one
statement in JDBC.


Thanks,
Idan





-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5293141.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by Rick Curtis <cu...@gmail.com>.
The openjpa.Multithreaded property is only for having multiple threads
sharing the same EntityManager. Per the spec EMs aren't supposed to be
shared across threads, but some applications do(rightly or wrongly). If
you're building from the ground up, I'd suggest against it (Perhaps others
on the list have an opinion). Also, there is a performance hit for setting
this property to true. A properly designed application shouldn't need to set
this prop.

Now on the the JDBC benchmark... shouldn't you be creating your prepared
statement within the for loop? The way you have it coded currently, you're
caching your prepared statement, but OpenJPA is creating a new prepared
statement each time (I think?).

Thanks,
Rick

Re: OpenJPA MySQL performance overhead

Posted by Michael Dick <mi...@gmail.com>.
Hi

In your JPA test you start a transaction for each find - if you aren't going
to modify the entities there's no real need for a transaction - does
removing the tran help?

We're never going to quite equal JDBC, since OpenJPA will be creating a new
PreparedStatement each time - the prepared statement pool you have on dbcp
should help a lot though.

Also in the JPA case the application is creating 20,000 instances of your
entities - whereas with JDBC you just check the results count (I'm guessing
a bit here). So there's a GC impact with JPA (and there would be with any
ORM). If you were to do more with the data in the JDBC case you should see
the numbers get closer.

Regarding openjpa.Multithreaded, this is useful if you plan to use a single
EntityManager on multiple threads at the same time. This pattern can be
tricky to get right - I'd strongly recommend removing the property and
getting a new EntityManager for each thread (you can use a single
EntityManagerFactory for all threads though).

-mike

On Wed, Jul 14, 2010 at 9:41 AM, idan <id...@gmail.com> wrote:

>
> That's my JDBC test: http://pastebin.com/ame6k1CG
>
> Regarding the openjpa.Multithread property.. my final application will be
> used in a multi-threaded
> environment.. so i guess i will have to set this property to true.. Am i
> correct?
>
> I ran the test again with the changes you suggested and i'm getting 1.5x
> than plain JDBC.
> I ran the test a few times and it got consistent after the 3rd time i ran
> the test.
>
> Any more suggestions? :-)
>
> Thanks,
> Idan
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5292879.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
That's my JDBC test: http://pastebin.com/ame6k1CG

Regarding the openjpa.Multithread property.. my final application will be
used in a multi-threaded
environment.. so i guess i will have to set this property to true.. Am i
correct?

I ran the test again with the changes you suggested and i'm getting 1.5x
than plain JDBC.
I ran the test a few times and it got consistent after the 3rd time i ran
the test.

Any more suggestions? :-)

Thanks,
Idan



-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5292879.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by Rick Curtis <cu...@gmail.com>.
Can you also post the JDBC code you're comparing against?

Also, try setting the following properties:

<property name="openjpa.ConnectionRetainMode" value="always" />
<property name="openjpa.Multithreaded" value="false" />

The openjpa.ConnectionRetainMode[1] is something that we wouldn't suggest
when running in an EE environment, but it will be interesting to see how/if
that helps your numbers.

Thanks,
Rick

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_retain

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
Here's the method i'm using:
http://pastebin.com/eYicwgvR

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5292754.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by Rick Curtis <cu...@gmail.com>.
Can you post a zip of the code that you are running?

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
Hey,
After learning some ANT basics i have managed to enhance my classes using
the ant script :-)

In each of my tests i have 10,000 iterations and at the end i calculate the
average execution time.

Insert/Update & Delete results are reasonable.. about 1.5x than plain JDBC.

But, Select (EntityManager.find()) performs pretty slow 2x and more than
plain JDBC.

Some details about my environment:

Client and Server are on different machines on my local network.

The properties i have in my persistence.xml file are:

	<property name="ConnectionProperties" 
                  value="DriverClassName=com.mysql.jdbc.Driver,
                  Url=jdbc:mysql://......., 
                  MaxActive=100, 
                  MaxWait=10000,
                  Username=...,
                  Password=..., 
                  TestOnBorrow=false,
                  poolPreparedStatements=true" /> 
	<property name="jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
         <property name="ConnectionDriverName" 
                value="org.apache.commons.dbcp.BasicDataSource"/>			

	<property name="openjpa.Multithreaded" value="true" />                  
	<property name="jdbc.DBDictionary" value="batchLimit=1000"/>


-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5292574.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
Thank you very much for the information!
I will test again according to the info you gave me.


Idan

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5288087.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by Michael Dick <mi...@gmail.com>.
Also good advice. Here's the link to the ant script (I think this is the
right one) :
http://openjpa.208410.n2.nabble.com/Ant-based-enhancement-td5065091.html#a5065949
.

-mike

On Tue, Jul 13, 2010 at 3:52 AM, Jean-Baptiste BRIAUD -- Novlog <
j-b.briaud@novlog.com> wrote:

> Enhance at build-time, not at run-time.
> Search the archive, I gave an ant script to do it.
>
> I'm not sure what "out of the box" really mean.
> I suggest you use high volume data and then an average time so you'll have
> the cruise speed only.
> I would also ensure any cache is disabled.
>
> On 13 juil. 2010, at 09:26, idan wrote:
> >
> >
> > Thanks for your reply guys.
> >
> > I'm using an out of the box configuration + DBCP for
> connection/statements
> > pooling.
> > I'm only measuring the persist/find/remove methods (transaction commit).
> >
> > The only thing i can think of is that i'm currently using a java agent
> for
> > enhancing my classes.
> >
> > Is there a known overhead over plain JDBC for the operations i have
> > mentioned?
> >
> >
> > Thanks,
> > Idan
> >
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5286305.html
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: OpenJPA MySQL performance overhead

Posted by Jean-Baptiste BRIAUD -- Novlog <j-...@novlog.com>.
Enhance at build-time, not at run-time.
Search the archive, I gave an ant script to do it.

I'm not sure what "out of the box" really mean.
I suggest you use high volume data and then an average time so you'll have the cruise speed only.
I would also ensure any cache is disabled.

On 13 juil. 2010, at 09:26, idan wrote:
> 
> 
> Thanks for your reply guys.
> 
> I'm using an out of the box configuration + DBCP for connection/statements
> pooling.
> I'm only measuring the persist/find/remove methods (transaction commit).
> 
> The only thing i can think of is that i'm currently using a java agent for
> enhancing my classes.
> 
> Is there a known overhead over plain JDBC for the operations i have
> mentioned?
> 
> 
> Thanks,
> Idan
> 
> 
> 
> 
> 
> 
> -- 
> View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5286305.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: OpenJPA MySQL performance overhead

Posted by Michael Dick <mi...@gmail.com>.
Hi Idan,

I wrote a simple test just for inserts : http://pastebin.com/bbW3RMnp

Results from my laptop :
DBC insert took: 23042
200  idan  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.0.0
649  idan  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.MySQLDictionary" (MySQL 5.1.37-1ubuntu5.4
,MySQL-AB JDBC Driver mysql-connector-java-5.1.5 ( Revision: ${svn.Revision}
)).
JPA insert took: 36036

So roughly 1.5x for JPA. It's a single connection for JDBC, but I'm using
dbcp with OpenJPA (MaxActive=100,MaxIdle=0,MaxWait=10000) and a javaagent to
enhance the entities.

Again this is very simple, but I'm not seeing the 5x degradation you
reported.

If you can post your testcase - maybe focus just on INSERTs that might help.

-mike

On Tue, Jul 13, 2010 at 2:26 AM, idan <id...@gmail.com> wrote:

>
> Thanks for your reply guys.
>
> I'm using an out of the box configuration + DBCP for connection/statements
> pooling.
> I'm only measuring the persist/find/remove methods (transaction commit).
>
> The only thing i can think of is that i'm currently using a java agent for
> enhancing my classes.
>
> Is there a known overhead over plain JDBC for the operations i have
> mentioned?
>
>
> Thanks,
> Idan
>
>
>
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5286305.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: OpenJPA MySQL performance overhead

Posted by idan <id...@gmail.com>.
Thanks for your reply guys.

I'm using an out of the box configuration + DBCP for connection/statements
pooling.
I'm only measuring the persist/find/remove methods (transaction commit).

The only thing i can think of is that i'm currently using a java agent for
enhancing my classes.

Is there a known overhead over plain JDBC for the operations i have
mentioned?


Thanks,
Idan






-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-performance-overhead-tp5279410p5286305.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: OpenJPA MySQL performance overhead

Posted by Michael Dick <mi...@gmail.com>.
To add to what Rick said it really depends on what you're timing.

Any ORM framework is going to be slower than JDBC - the framework is doing
some extra work for you. If you count the time taken to initialize the
framework e.g. something that should be done infrequently (creating a new
EntityManagerFactory) that can affect the performance results dramatically.

Considering the insert scenario. If you just compare the time it takes to
perform an EntityTransaction (begin, create entity, commit) to the time to
execute a prepared statement and commit a connection I suspect the numbers
are a bit closer.

-mike

On Mon, Jul 12, 2010 at 10:23 AM, Rick Curtis <cu...@gmail.com> wrote:

> I have a couple questions about your configuration:
> 1.] JEE or JSE?
> 2.] Is this out of box testing, or are you doing some amount of tuning to
> OpenJPA?
> 3.] Do you have some sort of connection pooling configured?
>
> Thanks,
> Rick
>

Re: OpenJPA MySQL performance overhead

Posted by Rick Curtis <cu...@gmail.com>.
I have a couple questions about your configuration:
1.] JEE or JSE?
2.] Is this out of box testing, or are you doing some amount of tuning to
OpenJPA?
3.] Do you have some sort of connection pooling configured?

Thanks,
Rick