You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Kevin Sutter <kw...@gmail.com> on 2009/03/12 14:38:29 UTC

Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Hi Shubbis,
Thanks for asking before posting any results...  :-)  Much appreciated.

The first thing that comes to mind is whether you are "enhancing" your
Entities that are used with OpenJPA.  For optimal performance, OpenJPA uses
a byte-code weaving technique to enhance the Entity objects.  This
enhancement allows for more efficient interaction between the Entity objects
and the OpenJPA runtime.

This blog entry explains the various enhancement mechanisms available for an
OpenJPA environment (build vs runtime):
http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html

FYI, if you do not perform the byte-code enhancement either statically at
build time or dynamically at runtime, then OpenJPA falls back to a simpler
subclassing approach.  This subclassing approach is meant for simple
out-of-the-box examples, and not for production or performance comparisons.
This performance concern becomes especially noticeable with Eager type
relationship fetching like it looks your example is doing.

Let's start with this enhancement processing.  If you are doing enhancement
and you are still hitting this performance concern, then we need to dig
further because we definitely do not see this type of performance concern
when we do our comparisons...  :-)

Thanks,
Kevin

On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no> wrote:

>
> First post so bare with me, and I've search for quite a while and not found
> any answers.
>
> I'm working on a school project where we are testing performance with
> different ORM's compared to JDBC and I'm having a big issue with OpenJPA
> when using a ManyToMany relation.
>
> We're trying to do a simple select case where we run a for loop with 500
> iterations while calling a findById method that returns the instance.
>
> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
>
> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes 10+
> sec on OpenJPA.
> This only happens with ManyToMany! We have plenty of insert tests, select
> tests etc and all of them are much more similar, with openjpa winning and
> losing a few.
>
> Now, I'll gladly admit we dont have to much experience with this, but this
> strikes me as very odd. So, if anyone has any tips, comments or info I'll
> be
> glad to try it out.
>
> Thanks in advance!
>
> Marius
>
> Here are the two entities in question:
>
> package project.common.model;
>
> import java.util.*;
>
> import javax.persistence.*;
>
> @Entity
> public class Wearhouse {
>
>        @Id
>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>        private Integer wearhouseNr;
>        private String wearhouseName;
>
>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch = FetchType.EAGER)
>        @JoinTable(
>                        name="wearhouse_storagecategory",
>                        joinColumns=@JoinColumn(name="wearhouseNr"),
>
>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
>        )
>        private List<Storagecategory> storageCategories;
>
>        public Wearhouse() {
>        }
>
>        public Wearhouse(String wearhouseName) {
>                this.wearhouseName = wearhouseName;
>                storageCategories = new ArrayList<Storagecategory>();
>        }
>
>        public Integer getWearhouseNr() {
>                return this.wearhouseNr;
>        }
>
>        public void setWearhouseNr(Integer wearhouseNr) {
>                this.wearhouseNr = wearhouseNr;
>        }
>
>        public String getWearhouseName() {
>                return this.wearhouseName;
>        }
>
>        public void setWearhouseName(String wearhouseName) {
>                this.wearhouseName = wearhouseName;
>        }
>
>        public void setStorageCategories(List<Storagecategory>
> storageCategory){
>                this.storageCategories = storageCategory;
>        }
>
>        public List<Storagecategory> getStorageCategories(){
>                return storageCategories;
>        }
>
>        public void addStorageCategories(Storagecategory storagecategory) {
>                if(storageCategories == null)
>                        storageCategories = new
> ArrayList<Storagecategory>();
>                storageCategories.add(storagecategory);
>
>        }
>
> }
>
>
>
> package project.common.model;
>
> import java.util.*;
>
> import javax.persistence.*;
>
> @Entity
> public class Storagecategory {
>
>        @Id
>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>        private Integer storagecategoryNr;
>        private String storageCategoryName;
>
>        @ManyToMany(mappedBy="storageCategories",
> cascade={CascadeType.PERSIST})
>        private List<Wearhouse> wearhouses;
>
>        public Storagecategory() {
>        }
>
>        public Storagecategory(String storageCategoryName) {
>                this.storageCategoryName = storageCategoryName;
>        }
>
>        public Integer getStoragecategoryNr() {
>                return this.storagecategoryNr;
>        }
>
>        public void setStoragecategoryNr(Integer storagecategoryNr) {
>                this.storagecategoryNr = storagecategoryNr;
>        }
>
>        public String getStorageCategoryName() {
>                return this.storageCategoryName;
>        }
>
>        public void setStorageCategoryName(String storageCategoryName) {
>                this.storageCategoryName = storageCategoryName;
>        }
>
>        public List<Wearhouse> getWearhouses() {
>                return wearhouses;
>        }
>
>        public void setWearhouses(List<Wearhouse> wearhouses) {
>                this.wearhouses = wearhouses;
>
>                //Wearhouse owns the relation, therefor we have to tell
> these
>                //wearhouses this storargecategories is on of the
> wearhouse's
> storagecategories.
>                for (Wearhouse wearhouse : wearhouses)
>                        wearhouse.addStorageCategories(this);
>        }
> }
> --
> View this message in context:
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Jeremy Bauer <te...@gmail.com>.
Shubbis,

Thanks for your reply and for your willingness to give my suggestion a try.
My question was mainly to (indirectly) point out that emf & em creation is
costly (especially emf) and that it could skew results.  Since your
measurement procedure tosses out high & low values, even if you create the
em during the first exec in your test cycle the measurement procedure would
likely toss out that result.  That being the case, creating the em ahead of
time should not show any better results.  Unless your test suite executes
the ManyToMany tests first and reuses that em for all following tests,
which, from your description is not the case, other tests should have been
similarly affected.  But, it may still be worth verifying.

What issue did you have with the 1.2.x nightly build?  A vote is currently
underway to publish a new 1.2.x release soon so please post if you've found
a problem.

-Jeremy

On Thu, Mar 12, 2009 at 2:26 PM, Shubbis <ma...@broadpark.no> wrote:

>
> Hi Jeremy!
>
> Our tests get (or create) the em when we begin the measurement. This is
> done
> on all the frameworks and all the tests (selects, inserts, updates,
> deletes,
> etc.). We then remove the highest and lowest numbers from all the results
> and gather an average. Should this really be affected? I mean, wouldn't
> that
> be a problem on all the selects and not only the ManyToMany if that was the
> case?
>
> Don't get me wrong, I'm going to give it a go, but I just want to make sure
> our scenario is understood.
>
> Also we are using MySQL 5.1.
>
> I've also tried to run the test on my local mysql installation and the
> results are similar, actually a bit slower..
>
>
>
> Jeremy Bauer wrote:
> >
> > Hi Shubbis,
> >
> > Does your measurement include the time it takes to create the entity
> > manager
> > factory and/or entity manager or are they created before you execute the
> > find operations?  I'm guessing you create the em ahead of time, since the
> > ManyToMany result is atypical. But if so, could you try creating the em
> > before taking measurement?  That would factor out any em initialization
> > related issues. Also, which db platform are you using for the tests?
> >
> > -Jeremy
> >
> > On Thu, Mar 12, 2009 at 8:48 AM, Shubbis <ma...@broadpark.no>
> > wrote:
> >
> >>
> >> Hi Kevin,
> >>
> >> Thanks for the reply!
> >>
> >> We are enhancing the files. I have an Ant script enhancing the files
> >> before
> >> every run of OpenJPA, so that is not the problem.
> >> Although it did give me strange results the first time I tried openjpa
> >> and
> >> did not enhance ;)
> >>
> >> -Shubbis
> >>
> >>
> >> Kevin Sutter wrote:
> >> >
> >> > Hi Shubbis,
> >> > Thanks for asking before posting any results...  :-)  Much
> appreciated.
> >> >
> >> > The first thing that comes to mind is whether you are "enhancing" your
> >> > Entities that are used with OpenJPA.  For optimal performance, OpenJPA
> >> > uses
> >> > a byte-code weaving technique to enhance the Entity objects.  This
> >> > enhancement allows for more efficient interaction between the Entity
> >> > objects
> >> > and the OpenJPA runtime.
> >> >
> >> > This blog entry explains the various enhancement mechanisms available
> >> for
> >> > an
> >> > OpenJPA environment (build vs runtime):
> >> >
> >>
> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
> >> >
> >> > FYI, if you do not perform the byte-code enhancement either statically
> >> at
> >> > build time or dynamically at runtime, then OpenJPA falls back to a
> >> simpler
> >> > subclassing approach.  This subclassing approach is meant for simple
> >> > out-of-the-box examples, and not for production or performance
> >> > comparisons.
> >> > This performance concern becomes especially noticeable with Eager type
> >> > relationship fetching like it looks your example is doing.
> >> >
> >> > Let's start with this enhancement processing.  If you are doing
> >> > enhancement
> >> > and you are still hitting this performance concern, then we need to
> dig
> >> > further because we definitely do not see this type of performance
> >> concern
> >> > when we do our comparisons...  :-)
> >> >
> >> > Thanks,
> >> > Kevin
> >> >
> >> > On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
> >> > wrote:
> >> >
> >> >>
> >> >> First post so bare with me, and I've search for quite a while and not
> >> >> found
> >> >> any answers.
> >> >>
> >> >> I'm working on a school project where we are testing performance with
> >> >> different ORM's compared to JDBC and I'm having a big issue with
> >> OpenJPA
> >> >> when using a ManyToMany relation.
> >> >>
> >> >> We're trying to do a simple select case where we run a for loop with
> >> 500
> >> >> iterations while calling a findById method that returns the instance.
> >> >>
> >> >> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class,
> id);
> >> >>
> >> >> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes
> >> 10+
> >> >> sec on OpenJPA.
> >> >> This only happens with ManyToMany! We have plenty of insert tests,
> >> select
> >> >> tests etc and all of them are much more similar, with openjpa winning
> >> and
> >> >> losing a few.
> >> >>
> >> >> Now, I'll gladly admit we dont have to much experience with this, but
> >> >> this
> >> >> strikes me as very odd. So, if anyone has any tips, comments or info
> >> I'll
> >> >> be
> >> >> glad to try it out.
> >> >>
> >> >> Thanks in advance!
> >> >>
> >> >> Marius
> >> >>
> >> >> Here are the two entities in question:
> >> >>
> >> >> package project.common.model;
> >> >>
> >> >> import java.util.*;
> >> >>
> >> >> import javax.persistence.*;
> >> >>
> >> >> @Entity
> >> >> public class Wearhouse {
> >> >>
> >> >>        @Id
> >> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >> >>        private Integer wearhouseNr;
> >> >>        private String wearhouseName;
> >> >>
> >> >>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
> >> >> FetchType.EAGER)
> >> >>        @JoinTable(
> >> >>                        name="wearhouse_storagecategory",
> >> >>                        joinColumns=@JoinColumn(name="wearhouseNr"),
> >> >>
> >> >>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
> >> >>        )
> >> >>        private List<Storagecategory> storageCategories;
> >> >>
> >> >>        public Wearhouse() {
> >> >>        }
> >> >>
> >> >>        public Wearhouse(String wearhouseName) {
> >> >>                this.wearhouseName = wearhouseName;
> >> >>                storageCategories = new ArrayList<Storagecategory>();
> >> >>        }
> >> >>
> >> >>        public Integer getWearhouseNr() {
> >> >>                return this.wearhouseNr;
> >> >>        }
> >> >>
> >> >>        public void setWearhouseNr(Integer wearhouseNr) {
> >> >>                this.wearhouseNr = wearhouseNr;
> >> >>        }
> >> >>
> >> >>        public String getWearhouseName() {
> >> >>                return this.wearhouseName;
> >> >>        }
> >> >>
> >> >>        public void setWearhouseName(String wearhouseName) {
> >> >>                this.wearhouseName = wearhouseName;
> >> >>        }
> >> >>
> >> >>        public void setStorageCategories(List<Storagecategory>
> >> >> storageCategory){
> >> >>                this.storageCategories = storageCategory;
> >> >>        }
> >> >>
> >> >>        public List<Storagecategory> getStorageCategories(){
> >> >>                return storageCategories;
> >> >>        }
> >> >>
> >> >>        public void addStorageCategories(Storagecategory
> >> storagecategory)
> >> >> {
> >> >>                if(storageCategories == null)
> >> >>                        storageCategories = new
> >> >> ArrayList<Storagecategory>();
> >> >>                storageCategories.add(storagecategory);
> >> >>
> >> >>        }
> >> >>
> >> >> }
> >> >>
> >> >>
> >> >>
> >> >> package project.common.model;
> >> >>
> >> >> import java.util.*;
> >> >>
> >> >> import javax.persistence.*;
> >> >>
> >> >> @Entity
> >> >> public class Storagecategory {
> >> >>
> >> >>        @Id
> >> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >> >>        private Integer storagecategoryNr;
> >> >>        private String storageCategoryName;
> >> >>
> >> >>        @ManyToMany(mappedBy="storageCategories",
> >> >> cascade={CascadeType.PERSIST})
> >> >>        private List<Wearhouse> wearhouses;
> >> >>
> >> >>        public Storagecategory() {
> >> >>        }
> >> >>
> >> >>        public Storagecategory(String storageCategoryName) {
> >> >>                this.storageCategoryName = storageCategoryName;
> >> >>        }
> >> >>
> >> >>        public Integer getStoragecategoryNr() {
> >> >>                return this.storagecategoryNr;
> >> >>        }
> >> >>
> >> >>        public void setStoragecategoryNr(Integer storagecategoryNr) {
> >> >>                this.storagecategoryNr = storagecategoryNr;
> >> >>        }
> >> >>
> >> >>        public String getStorageCategoryName() {
> >> >>                return this.storageCategoryName;
> >> >>        }
> >> >>
> >> >>        public void setStorageCategoryName(String storageCategoryName)
> >> {
> >> >>                this.storageCategoryName = storageCategoryName;
> >> >>        }
> >> >>
> >> >>        public List<Wearhouse> getWearhouses() {
> >> >>                return wearhouses;
> >> >>        }
> >> >>
> >> >>        public void setWearhouses(List<Wearhouse> wearhouses) {
> >> >>                this.wearhouses = wearhouses;
> >> >>
> >> >>                //Wearhouse owns the relation, therefor we have to
> tell
> >> >> these
> >> >>                //wearhouses this storargecategories is on of the
> >> >> wearhouse's
> >> >> storagecategories.
> >> >>                for (Wearhouse wearhouse : wearhouses)
> >> >>                        wearhouse.addStorageCategories(this);
> >> >>        }
> >> >> }
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
> >> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2469498.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Shubbis <ma...@broadpark.no>.
Hi Jeremy!

Our tests get (or create) the em when we begin the measurement. This is done
on all the frameworks and all the tests (selects, inserts, updates, deletes,
etc.). We then remove the highest and lowest numbers from all the results
and gather an average. Should this really be affected? I mean, wouldn't that
be a problem on all the selects and not only the ManyToMany if that was the
case?

Don't get me wrong, I'm going to give it a go, but I just want to make sure
our scenario is understood.

Also we are using MySQL 5.1.

I've also tried to run the test on my local mysql installation and the
results are similar, actually a bit slower..



Jeremy Bauer wrote:
> 
> Hi Shubbis,
> 
> Does your measurement include the time it takes to create the entity
> manager
> factory and/or entity manager or are they created before you execute the
> find operations?  I'm guessing you create the em ahead of time, since the
> ManyToMany result is atypical. But if so, could you try creating the em
> before taking measurement?  That would factor out any em initialization
> related issues. Also, which db platform are you using for the tests?
> 
> -Jeremy
> 
> On Thu, Mar 12, 2009 at 8:48 AM, Shubbis <ma...@broadpark.no>
> wrote:
> 
>>
>> Hi Kevin,
>>
>> Thanks for the reply!
>>
>> We are enhancing the files. I have an Ant script enhancing the files
>> before
>> every run of OpenJPA, so that is not the problem.
>> Although it did give me strange results the first time I tried openjpa
>> and
>> did not enhance ;)
>>
>> -Shubbis
>>
>>
>> Kevin Sutter wrote:
>> >
>> > Hi Shubbis,
>> > Thanks for asking before posting any results...  :-)  Much appreciated.
>> >
>> > The first thing that comes to mind is whether you are "enhancing" your
>> > Entities that are used with OpenJPA.  For optimal performance, OpenJPA
>> > uses
>> > a byte-code weaving technique to enhance the Entity objects.  This
>> > enhancement allows for more efficient interaction between the Entity
>> > objects
>> > and the OpenJPA runtime.
>> >
>> > This blog entry explains the various enhancement mechanisms available
>> for
>> > an
>> > OpenJPA environment (build vs runtime):
>> >
>> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
>> >
>> > FYI, if you do not perform the byte-code enhancement either statically
>> at
>> > build time or dynamically at runtime, then OpenJPA falls back to a
>> simpler
>> > subclassing approach.  This subclassing approach is meant for simple
>> > out-of-the-box examples, and not for production or performance
>> > comparisons.
>> > This performance concern becomes especially noticeable with Eager type
>> > relationship fetching like it looks your example is doing.
>> >
>> > Let's start with this enhancement processing.  If you are doing
>> > enhancement
>> > and you are still hitting this performance concern, then we need to dig
>> > further because we definitely do not see this type of performance
>> concern
>> > when we do our comparisons...  :-)
>> >
>> > Thanks,
>> > Kevin
>> >
>> > On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
>> > wrote:
>> >
>> >>
>> >> First post so bare with me, and I've search for quite a while and not
>> >> found
>> >> any answers.
>> >>
>> >> I'm working on a school project where we are testing performance with
>> >> different ORM's compared to JDBC and I'm having a big issue with
>> OpenJPA
>> >> when using a ManyToMany relation.
>> >>
>> >> We're trying to do a simple select case where we run a for loop with
>> 500
>> >> iterations while calling a findById method that returns the instance.
>> >>
>> >> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
>> >>
>> >> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes
>> 10+
>> >> sec on OpenJPA.
>> >> This only happens with ManyToMany! We have plenty of insert tests,
>> select
>> >> tests etc and all of them are much more similar, with openjpa winning
>> and
>> >> losing a few.
>> >>
>> >> Now, I'll gladly admit we dont have to much experience with this, but
>> >> this
>> >> strikes me as very odd. So, if anyone has any tips, comments or info
>> I'll
>> >> be
>> >> glad to try it out.
>> >>
>> >> Thanks in advance!
>> >>
>> >> Marius
>> >>
>> >> Here are the two entities in question:
>> >>
>> >> package project.common.model;
>> >>
>> >> import java.util.*;
>> >>
>> >> import javax.persistence.*;
>> >>
>> >> @Entity
>> >> public class Wearhouse {
>> >>
>> >>        @Id
>> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>> >>        private Integer wearhouseNr;
>> >>        private String wearhouseName;
>> >>
>> >>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
>> >> FetchType.EAGER)
>> >>        @JoinTable(
>> >>                        name="wearhouse_storagecategory",
>> >>                        joinColumns=@JoinColumn(name="wearhouseNr"),
>> >>
>> >>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
>> >>        )
>> >>        private List<Storagecategory> storageCategories;
>> >>
>> >>        public Wearhouse() {
>> >>        }
>> >>
>> >>        public Wearhouse(String wearhouseName) {
>> >>                this.wearhouseName = wearhouseName;
>> >>                storageCategories = new ArrayList<Storagecategory>();
>> >>        }
>> >>
>> >>        public Integer getWearhouseNr() {
>> >>                return this.wearhouseNr;
>> >>        }
>> >>
>> >>        public void setWearhouseNr(Integer wearhouseNr) {
>> >>                this.wearhouseNr = wearhouseNr;
>> >>        }
>> >>
>> >>        public String getWearhouseName() {
>> >>                return this.wearhouseName;
>> >>        }
>> >>
>> >>        public void setWearhouseName(String wearhouseName) {
>> >>                this.wearhouseName = wearhouseName;
>> >>        }
>> >>
>> >>        public void setStorageCategories(List<Storagecategory>
>> >> storageCategory){
>> >>                this.storageCategories = storageCategory;
>> >>        }
>> >>
>> >>        public List<Storagecategory> getStorageCategories(){
>> >>                return storageCategories;
>> >>        }
>> >>
>> >>        public void addStorageCategories(Storagecategory
>> storagecategory)
>> >> {
>> >>                if(storageCategories == null)
>> >>                        storageCategories = new
>> >> ArrayList<Storagecategory>();
>> >>                storageCategories.add(storagecategory);
>> >>
>> >>        }
>> >>
>> >> }
>> >>
>> >>
>> >>
>> >> package project.common.model;
>> >>
>> >> import java.util.*;
>> >>
>> >> import javax.persistence.*;
>> >>
>> >> @Entity
>> >> public class Storagecategory {
>> >>
>> >>        @Id
>> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>> >>        private Integer storagecategoryNr;
>> >>        private String storageCategoryName;
>> >>
>> >>        @ManyToMany(mappedBy="storageCategories",
>> >> cascade={CascadeType.PERSIST})
>> >>        private List<Wearhouse> wearhouses;
>> >>
>> >>        public Storagecategory() {
>> >>        }
>> >>
>> >>        public Storagecategory(String storageCategoryName) {
>> >>                this.storageCategoryName = storageCategoryName;
>> >>        }
>> >>
>> >>        public Integer getStoragecategoryNr() {
>> >>                return this.storagecategoryNr;
>> >>        }
>> >>
>> >>        public void setStoragecategoryNr(Integer storagecategoryNr) {
>> >>                this.storagecategoryNr = storagecategoryNr;
>> >>        }
>> >>
>> >>        public String getStorageCategoryName() {
>> >>                return this.storageCategoryName;
>> >>        }
>> >>
>> >>        public void setStorageCategoryName(String storageCategoryName)
>> {
>> >>                this.storageCategoryName = storageCategoryName;
>> >>        }
>> >>
>> >>        public List<Wearhouse> getWearhouses() {
>> >>                return wearhouses;
>> >>        }
>> >>
>> >>        public void setWearhouses(List<Wearhouse> wearhouses) {
>> >>                this.wearhouses = wearhouses;
>> >>
>> >>                //Wearhouse owns the relation, therefor we have to tell
>> >> these
>> >>                //wearhouses this storargecategories is on of the
>> >> wearhouse's
>> >> storagecategories.
>> >>                for (Wearhouse wearhouse : wearhouses)
>> >>                        wearhouse.addStorageCategories(this);
>> >>        }
>> >> }
>> >> --
>> >> View this message in context:
>> >>
>> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
>> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2469498.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Jeremy Bauer <te...@gmail.com>.
Hi Shubbis,

Does your measurement include the time it takes to create the entity manager
factory and/or entity manager or are they created before you execute the
find operations?  I'm guessing you create the em ahead of time, since the
ManyToMany result is atypical. But if so, could you try creating the em
before taking measurement?  That would factor out any em initialization
related issues. Also, which db platform are you using for the tests?

-Jeremy

On Thu, Mar 12, 2009 at 8:48 AM, Shubbis <ma...@broadpark.no> wrote:

>
> Hi Kevin,
>
> Thanks for the reply!
>
> We are enhancing the files. I have an Ant script enhancing the files before
> every run of OpenJPA, so that is not the problem.
> Although it did give me strange results the first time I tried openjpa and
> did not enhance ;)
>
> -Shubbis
>
>
> Kevin Sutter wrote:
> >
> > Hi Shubbis,
> > Thanks for asking before posting any results...  :-)  Much appreciated.
> >
> > The first thing that comes to mind is whether you are "enhancing" your
> > Entities that are used with OpenJPA.  For optimal performance, OpenJPA
> > uses
> > a byte-code weaving technique to enhance the Entity objects.  This
> > enhancement allows for more efficient interaction between the Entity
> > objects
> > and the OpenJPA runtime.
> >
> > This blog entry explains the various enhancement mechanisms available for
> > an
> > OpenJPA environment (build vs runtime):
> >
> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
> >
> > FYI, if you do not perform the byte-code enhancement either statically at
> > build time or dynamically at runtime, then OpenJPA falls back to a
> simpler
> > subclassing approach.  This subclassing approach is meant for simple
> > out-of-the-box examples, and not for production or performance
> > comparisons.
> > This performance concern becomes especially noticeable with Eager type
> > relationship fetching like it looks your example is doing.
> >
> > Let's start with this enhancement processing.  If you are doing
> > enhancement
> > and you are still hitting this performance concern, then we need to dig
> > further because we definitely do not see this type of performance concern
> > when we do our comparisons...  :-)
> >
> > Thanks,
> > Kevin
> >
> > On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
> > wrote:
> >
> >>
> >> First post so bare with me, and I've search for quite a while and not
> >> found
> >> any answers.
> >>
> >> I'm working on a school project where we are testing performance with
> >> different ORM's compared to JDBC and I'm having a big issue with OpenJPA
> >> when using a ManyToMany relation.
> >>
> >> We're trying to do a simple select case where we run a for loop with 500
> >> iterations while calling a findById method that returns the instance.
> >>
> >> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
> >>
> >> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes
> 10+
> >> sec on OpenJPA.
> >> This only happens with ManyToMany! We have plenty of insert tests,
> select
> >> tests etc and all of them are much more similar, with openjpa winning
> and
> >> losing a few.
> >>
> >> Now, I'll gladly admit we dont have to much experience with this, but
> >> this
> >> strikes me as very odd. So, if anyone has any tips, comments or info
> I'll
> >> be
> >> glad to try it out.
> >>
> >> Thanks in advance!
> >>
> >> Marius
> >>
> >> Here are the two entities in question:
> >>
> >> package project.common.model;
> >>
> >> import java.util.*;
> >>
> >> import javax.persistence.*;
> >>
> >> @Entity
> >> public class Wearhouse {
> >>
> >>        @Id
> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >>        private Integer wearhouseNr;
> >>        private String wearhouseName;
> >>
> >>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
> >> FetchType.EAGER)
> >>        @JoinTable(
> >>                        name="wearhouse_storagecategory",
> >>                        joinColumns=@JoinColumn(name="wearhouseNr"),
> >>
> >>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
> >>        )
> >>        private List<Storagecategory> storageCategories;
> >>
> >>        public Wearhouse() {
> >>        }
> >>
> >>        public Wearhouse(String wearhouseName) {
> >>                this.wearhouseName = wearhouseName;
> >>                storageCategories = new ArrayList<Storagecategory>();
> >>        }
> >>
> >>        public Integer getWearhouseNr() {
> >>                return this.wearhouseNr;
> >>        }
> >>
> >>        public void setWearhouseNr(Integer wearhouseNr) {
> >>                this.wearhouseNr = wearhouseNr;
> >>        }
> >>
> >>        public String getWearhouseName() {
> >>                return this.wearhouseName;
> >>        }
> >>
> >>        public void setWearhouseName(String wearhouseName) {
> >>                this.wearhouseName = wearhouseName;
> >>        }
> >>
> >>        public void setStorageCategories(List<Storagecategory>
> >> storageCategory){
> >>                this.storageCategories = storageCategory;
> >>        }
> >>
> >>        public List<Storagecategory> getStorageCategories(){
> >>                return storageCategories;
> >>        }
> >>
> >>        public void addStorageCategories(Storagecategory storagecategory)
> >> {
> >>                if(storageCategories == null)
> >>                        storageCategories = new
> >> ArrayList<Storagecategory>();
> >>                storageCategories.add(storagecategory);
> >>
> >>        }
> >>
> >> }
> >>
> >>
> >>
> >> package project.common.model;
> >>
> >> import java.util.*;
> >>
> >> import javax.persistence.*;
> >>
> >> @Entity
> >> public class Storagecategory {
> >>
> >>        @Id
> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >>        private Integer storagecategoryNr;
> >>        private String storageCategoryName;
> >>
> >>        @ManyToMany(mappedBy="storageCategories",
> >> cascade={CascadeType.PERSIST})
> >>        private List<Wearhouse> wearhouses;
> >>
> >>        public Storagecategory() {
> >>        }
> >>
> >>        public Storagecategory(String storageCategoryName) {
> >>                this.storageCategoryName = storageCategoryName;
> >>        }
> >>
> >>        public Integer getStoragecategoryNr() {
> >>                return this.storagecategoryNr;
> >>        }
> >>
> >>        public void setStoragecategoryNr(Integer storagecategoryNr) {
> >>                this.storagecategoryNr = storagecategoryNr;
> >>        }
> >>
> >>        public String getStorageCategoryName() {
> >>                return this.storageCategoryName;
> >>        }
> >>
> >>        public void setStorageCategoryName(String storageCategoryName) {
> >>                this.storageCategoryName = storageCategoryName;
> >>        }
> >>
> >>        public List<Wearhouse> getWearhouses() {
> >>                return wearhouses;
> >>        }
> >>
> >>        public void setWearhouses(List<Wearhouse> wearhouses) {
> >>                this.wearhouses = wearhouses;
> >>
> >>                //Wearhouse owns the relation, therefor we have to tell
> >> these
> >>                //wearhouses this storargecategories is on of the
> >> wearhouse's
> >> storagecategories.
> >>                for (Wearhouse wearhouse : wearhouses)
> >>                        wearhouse.addStorageCategories(this);
> >>        }
> >> }
> >> --
> >> View this message in context:
> >>
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Shubbis <ma...@broadpark.no>.
I wish it were that easy aswell.. ;)

The database has, at the time of testing, 200 in wearhouse, 500 in
storagecategory and 10 storage categories in each wearhouse.  I'm running
1.2.x. I gave the latest nightly a go, but had some issues and went back to
1.2 because of the importance of having a working installation for the
project.

Caching is default, so disabled. If i enable caching the first go still
takes just as long, but the next iterations obviously take only a few ms.

Basically it's just plain vanilla, since we cannot be expected to know all
of the frameworks tweaks and possibilities we decided to leave them all
default so we could have an even comparison. Obviously with the exception of
enhancing files for OpenJPA.

We really appreciate the help btw! :)


Kevin Sutter wrote:
> 
> Shubbis,
> Darn, I thought it was going to be an easy "lack of enhancement"
> question...  Your results don't seem to mesh what we have been
> experiencing,
> but let me try to mimic your exact setup and see what I come up with.
> 
> I do see that you are using Eager FetchType.  Is your database fully
> populated?  That is, what number of Wearhouse and StorageContainers are
> you
> running with?  And, have you verified that the FetchType of Eager is
> working
> for all implementations?
> 
> And, what version of OpenJPA are you running with?  1.0.x, 1.2.x, 1.3.x,
> or
> trunk (2.0.x)?  And, any caching parameters at all?  Or, just plain
> vanilla
> out-of-the-box configuration?
> 
> Thanks,
> Kevin
> 
> On Thu, Mar 12, 2009 at 8:48 AM, Shubbis <ma...@broadpark.no>
> wrote:
> 
>>
>> Hi Kevin,
>>
>> Thanks for the reply!
>>
>> We are enhancing the files. I have an Ant script enhancing the files
>> before
>> every run of OpenJPA, so that is not the problem.
>> Although it did give me strange results the first time I tried openjpa
>> and
>> did not enhance ;)
>>
>> -Shubbis
>>
>>
>> Kevin Sutter wrote:
>> >
>> > Hi Shubbis,
>> > Thanks for asking before posting any results...  :-)  Much appreciated.
>> >
>> > The first thing that comes to mind is whether you are "enhancing" your
>> > Entities that are used with OpenJPA.  For optimal performance, OpenJPA
>> > uses
>> > a byte-code weaving technique to enhance the Entity objects.  This
>> > enhancement allows for more efficient interaction between the Entity
>> > objects
>> > and the OpenJPA runtime.
>> >
>> > This blog entry explains the various enhancement mechanisms available
>> for
>> > an
>> > OpenJPA environment (build vs runtime):
>> >
>> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
>> >
>> > FYI, if you do not perform the byte-code enhancement either statically
>> at
>> > build time or dynamically at runtime, then OpenJPA falls back to a
>> simpler
>> > subclassing approach.  This subclassing approach is meant for simple
>> > out-of-the-box examples, and not for production or performance
>> > comparisons.
>> > This performance concern becomes especially noticeable with Eager type
>> > relationship fetching like it looks your example is doing.
>> >
>> > Let's start with this enhancement processing.  If you are doing
>> > enhancement
>> > and you are still hitting this performance concern, then we need to dig
>> > further because we definitely do not see this type of performance
>> concern
>> > when we do our comparisons...  :-)
>> >
>> > Thanks,
>> > Kevin
>> >
>> > On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
>> > wrote:
>> >
>> >>
>> >> First post so bare with me, and I've search for quite a while and not
>> >> found
>> >> any answers.
>> >>
>> >> I'm working on a school project where we are testing performance with
>> >> different ORM's compared to JDBC and I'm having a big issue with
>> OpenJPA
>> >> when using a ManyToMany relation.
>> >>
>> >> We're trying to do a simple select case where we run a for loop with
>> 500
>> >> iterations while calling a findById method that returns the instance.
>> >>
>> >> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
>> >>
>> >> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes
>> 10+
>> >> sec on OpenJPA.
>> >> This only happens with ManyToMany! We have plenty of insert tests,
>> select
>> >> tests etc and all of them are much more similar, with openjpa winning
>> and
>> >> losing a few.
>> >>
>> >> Now, I'll gladly admit we dont have to much experience with this, but
>> >> this
>> >> strikes me as very odd. So, if anyone has any tips, comments or info
>> I'll
>> >> be
>> >> glad to try it out.
>> >>
>> >> Thanks in advance!
>> >>
>> >> Marius
>> >>
>> >> Here are the two entities in question:
>> >>
>> >> package project.common.model;
>> >>
>> >> import java.util.*;
>> >>
>> >> import javax.persistence.*;
>> >>
>> >> @Entity
>> >> public class Wearhouse {
>> >>
>> >>        @Id
>> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>> >>        private Integer wearhouseNr;
>> >>        private String wearhouseName;
>> >>
>> >>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
>> >> FetchType.EAGER)
>> >>        @JoinTable(
>> >>                        name="wearhouse_storagecategory",
>> >>                        joinColumns=@JoinColumn(name="wearhouseNr"),
>> >>
>> >>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
>> >>        )
>> >>        private List<Storagecategory> storageCategories;
>> >>
>> >>        public Wearhouse() {
>> >>        }
>> >>
>> >>        public Wearhouse(String wearhouseName) {
>> >>                this.wearhouseName = wearhouseName;
>> >>                storageCategories = new ArrayList<Storagecategory>();
>> >>        }
>> >>
>> >>        public Integer getWearhouseNr() {
>> >>                return this.wearhouseNr;
>> >>        }
>> >>
>> >>        public void setWearhouseNr(Integer wearhouseNr) {
>> >>                this.wearhouseNr = wearhouseNr;
>> >>        }
>> >>
>> >>        public String getWearhouseName() {
>> >>                return this.wearhouseName;
>> >>        }
>> >>
>> >>        public void setWearhouseName(String wearhouseName) {
>> >>                this.wearhouseName = wearhouseName;
>> >>        }
>> >>
>> >>        public void setStorageCategories(List<Storagecategory>
>> >> storageCategory){
>> >>                this.storageCategories = storageCategory;
>> >>        }
>> >>
>> >>        public List<Storagecategory> getStorageCategories(){
>> >>                return storageCategories;
>> >>        }
>> >>
>> >>        public void addStorageCategories(Storagecategory
>> storagecategory)
>> >> {
>> >>                if(storageCategories == null)
>> >>                        storageCategories = new
>> >> ArrayList<Storagecategory>();
>> >>                storageCategories.add(storagecategory);
>> >>
>> >>        }
>> >>
>> >> }
>> >>
>> >>
>> >>
>> >> package project.common.model;
>> >>
>> >> import java.util.*;
>> >>
>> >> import javax.persistence.*;
>> >>
>> >> @Entity
>> >> public class Storagecategory {
>> >>
>> >>        @Id
>> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>> >>        private Integer storagecategoryNr;
>> >>        private String storageCategoryName;
>> >>
>> >>        @ManyToMany(mappedBy="storageCategories",
>> >> cascade={CascadeType.PERSIST})
>> >>        private List<Wearhouse> wearhouses;
>> >>
>> >>        public Storagecategory() {
>> >>        }
>> >>
>> >>        public Storagecategory(String storageCategoryName) {
>> >>                this.storageCategoryName = storageCategoryName;
>> >>        }
>> >>
>> >>        public Integer getStoragecategoryNr() {
>> >>                return this.storagecategoryNr;
>> >>        }
>> >>
>> >>        public void setStoragecategoryNr(Integer storagecategoryNr) {
>> >>                this.storagecategoryNr = storagecategoryNr;
>> >>        }
>> >>
>> >>        public String getStorageCategoryName() {
>> >>                return this.storageCategoryName;
>> >>        }
>> >>
>> >>        public void setStorageCategoryName(String storageCategoryName)
>> {
>> >>                this.storageCategoryName = storageCategoryName;
>> >>        }
>> >>
>> >>        public List<Wearhouse> getWearhouses() {
>> >>                return wearhouses;
>> >>        }
>> >>
>> >>        public void setWearhouses(List<Wearhouse> wearhouses) {
>> >>                this.wearhouses = wearhouses;
>> >>
>> >>                //Wearhouse owns the relation, therefor we have to tell
>> >> these
>> >>                //wearhouses this storargecategories is on of the
>> >> wearhouse's
>> >> storagecategories.
>> >>                for (Wearhouse wearhouse : wearhouses)
>> >>                        wearhouse.addStorageCategories(this);
>> >>        }
>> >> }
>> >> --
>> >> View this message in context:
>> >>
>> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
>> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2469415.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Kevin Sutter <kw...@gmail.com>.
Shubbis,
Darn, I thought it was going to be an easy "lack of enhancement"
question...  Your results don't seem to mesh what we have been experiencing,
but let me try to mimic your exact setup and see what I come up with.

I do see that you are using Eager FetchType.  Is your database fully
populated?  That is, what number of Wearhouse and StorageContainers are you
running with?  And, have you verified that the FetchType of Eager is working
for all implementations?

And, what version of OpenJPA are you running with?  1.0.x, 1.2.x, 1.3.x, or
trunk (2.0.x)?  And, any caching parameters at all?  Or, just plain vanilla
out-of-the-box configuration?

Thanks,
Kevin

On Thu, Mar 12, 2009 at 8:48 AM, Shubbis <ma...@broadpark.no> wrote:

>
> Hi Kevin,
>
> Thanks for the reply!
>
> We are enhancing the files. I have an Ant script enhancing the files before
> every run of OpenJPA, so that is not the problem.
> Although it did give me strange results the first time I tried openjpa and
> did not enhance ;)
>
> -Shubbis
>
>
> Kevin Sutter wrote:
> >
> > Hi Shubbis,
> > Thanks for asking before posting any results...  :-)  Much appreciated.
> >
> > The first thing that comes to mind is whether you are "enhancing" your
> > Entities that are used with OpenJPA.  For optimal performance, OpenJPA
> > uses
> > a byte-code weaving technique to enhance the Entity objects.  This
> > enhancement allows for more efficient interaction between the Entity
> > objects
> > and the OpenJPA runtime.
> >
> > This blog entry explains the various enhancement mechanisms available for
> > an
> > OpenJPA environment (build vs runtime):
> >
> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
> >
> > FYI, if you do not perform the byte-code enhancement either statically at
> > build time or dynamically at runtime, then OpenJPA falls back to a
> simpler
> > subclassing approach.  This subclassing approach is meant for simple
> > out-of-the-box examples, and not for production or performance
> > comparisons.
> > This performance concern becomes especially noticeable with Eager type
> > relationship fetching like it looks your example is doing.
> >
> > Let's start with this enhancement processing.  If you are doing
> > enhancement
> > and you are still hitting this performance concern, then we need to dig
> > further because we definitely do not see this type of performance concern
> > when we do our comparisons...  :-)
> >
> > Thanks,
> > Kevin
> >
> > On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
> > wrote:
> >
> >>
> >> First post so bare with me, and I've search for quite a while and not
> >> found
> >> any answers.
> >>
> >> I'm working on a school project where we are testing performance with
> >> different ORM's compared to JDBC and I'm having a big issue with OpenJPA
> >> when using a ManyToMany relation.
> >>
> >> We're trying to do a simple select case where we run a for loop with 500
> >> iterations while calling a findById method that returns the instance.
> >>
> >> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
> >>
> >> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes
> 10+
> >> sec on OpenJPA.
> >> This only happens with ManyToMany! We have plenty of insert tests,
> select
> >> tests etc and all of them are much more similar, with openjpa winning
> and
> >> losing a few.
> >>
> >> Now, I'll gladly admit we dont have to much experience with this, but
> >> this
> >> strikes me as very odd. So, if anyone has any tips, comments or info
> I'll
> >> be
> >> glad to try it out.
> >>
> >> Thanks in advance!
> >>
> >> Marius
> >>
> >> Here are the two entities in question:
> >>
> >> package project.common.model;
> >>
> >> import java.util.*;
> >>
> >> import javax.persistence.*;
> >>
> >> @Entity
> >> public class Wearhouse {
> >>
> >>        @Id
> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >>        private Integer wearhouseNr;
> >>        private String wearhouseName;
> >>
> >>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
> >> FetchType.EAGER)
> >>        @JoinTable(
> >>                        name="wearhouse_storagecategory",
> >>                        joinColumns=@JoinColumn(name="wearhouseNr"),
> >>
> >>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
> >>        )
> >>        private List<Storagecategory> storageCategories;
> >>
> >>        public Wearhouse() {
> >>        }
> >>
> >>        public Wearhouse(String wearhouseName) {
> >>                this.wearhouseName = wearhouseName;
> >>                storageCategories = new ArrayList<Storagecategory>();
> >>        }
> >>
> >>        public Integer getWearhouseNr() {
> >>                return this.wearhouseNr;
> >>        }
> >>
> >>        public void setWearhouseNr(Integer wearhouseNr) {
> >>                this.wearhouseNr = wearhouseNr;
> >>        }
> >>
> >>        public String getWearhouseName() {
> >>                return this.wearhouseName;
> >>        }
> >>
> >>        public void setWearhouseName(String wearhouseName) {
> >>                this.wearhouseName = wearhouseName;
> >>        }
> >>
> >>        public void setStorageCategories(List<Storagecategory>
> >> storageCategory){
> >>                this.storageCategories = storageCategory;
> >>        }
> >>
> >>        public List<Storagecategory> getStorageCategories(){
> >>                return storageCategories;
> >>        }
> >>
> >>        public void addStorageCategories(Storagecategory storagecategory)
> >> {
> >>                if(storageCategories == null)
> >>                        storageCategories = new
> >> ArrayList<Storagecategory>();
> >>                storageCategories.add(storagecategory);
> >>
> >>        }
> >>
> >> }
> >>
> >>
> >>
> >> package project.common.model;
> >>
> >> import java.util.*;
> >>
> >> import javax.persistence.*;
> >>
> >> @Entity
> >> public class Storagecategory {
> >>
> >>        @Id
> >>        @GeneratedValue(strategy = GenerationType.IDENTITY)
> >>        private Integer storagecategoryNr;
> >>        private String storageCategoryName;
> >>
> >>        @ManyToMany(mappedBy="storageCategories",
> >> cascade={CascadeType.PERSIST})
> >>        private List<Wearhouse> wearhouses;
> >>
> >>        public Storagecategory() {
> >>        }
> >>
> >>        public Storagecategory(String storageCategoryName) {
> >>                this.storageCategoryName = storageCategoryName;
> >>        }
> >>
> >>        public Integer getStoragecategoryNr() {
> >>                return this.storagecategoryNr;
> >>        }
> >>
> >>        public void setStoragecategoryNr(Integer storagecategoryNr) {
> >>                this.storagecategoryNr = storagecategoryNr;
> >>        }
> >>
> >>        public String getStorageCategoryName() {
> >>                return this.storageCategoryName;
> >>        }
> >>
> >>        public void setStorageCategoryName(String storageCategoryName) {
> >>                this.storageCategoryName = storageCategoryName;
> >>        }
> >>
> >>        public List<Wearhouse> getWearhouses() {
> >>                return wearhouses;
> >>        }
> >>
> >>        public void setWearhouses(List<Wearhouse> wearhouses) {
> >>                this.wearhouses = wearhouses;
> >>
> >>                //Wearhouse owns the relation, therefor we have to tell
> >> these
> >>                //wearhouses this storargecategories is on of the
> >> wearhouse's
> >> storagecategories.
> >>                for (Wearhouse wearhouse : wearhouses)
> >>                        wearhouse.addStorageCategories(this);
> >>        }
> >> }
> >> --
> >> View this message in context:
> >>
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: Slow performance with OpenJPA when selecting from a ManyToMany relation.

Posted by Shubbis <ma...@broadpark.no>.
Hi Kevin,

Thanks for the reply!

We are enhancing the files. I have an Ant script enhancing the files before
every run of OpenJPA, so that is not the problem. 
Although it did give me strange results the first time I tried openjpa and
did not enhance ;)

-Shubbis


Kevin Sutter wrote:
> 
> Hi Shubbis,
> Thanks for asking before posting any results...  :-)  Much appreciated.
> 
> The first thing that comes to mind is whether you are "enhancing" your
> Entities that are used with OpenJPA.  For optimal performance, OpenJPA
> uses
> a byte-code weaving technique to enhance the Entity objects.  This
> enhancement allows for more efficient interaction between the Entity
> objects
> and the OpenJPA runtime.
> 
> This blog entry explains the various enhancement mechanisms available for
> an
> OpenJPA environment (build vs runtime):
> http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
> 
> FYI, if you do not perform the byte-code enhancement either statically at
> build time or dynamically at runtime, then OpenJPA falls back to a simpler
> subclassing approach.  This subclassing approach is meant for simple
> out-of-the-box examples, and not for production or performance
> comparisons.
> This performance concern becomes especially noticeable with Eager type
> relationship fetching like it looks your example is doing.
> 
> Let's start with this enhancement processing.  If you are doing
> enhancement
> and you are still hitting this performance concern, then we need to dig
> further because we definitely do not see this type of performance concern
> when we do our comparisons...  :-)
> 
> Thanks,
> Kevin
> 
> On Thu, Mar 12, 2009 at 7:22 AM, Shubbis <ma...@broadpark.no>
> wrote:
> 
>>
>> First post so bare with me, and I've search for quite a while and not
>> found
>> any answers.
>>
>> I'm working on a school project where we are testing performance with
>> different ORM's compared to JDBC and I'm having a big issue with OpenJPA
>> when using a ManyToMany relation.
>>
>> We're trying to do a simple select case where we run a for loop with 500
>> iterations while calling a findById method that returns the instance.
>>
>> Wearhouse instance = getOJPAEntityManager().find(Wearhouse.class, id);
>>
>> This takes roughly 1~ sec on JDBC and 1.2~ EclipseLink while it takes 10+
>> sec on OpenJPA.
>> This only happens with ManyToMany! We have plenty of insert tests, select
>> tests etc and all of them are much more similar, with openjpa winning and
>> losing a few.
>>
>> Now, I'll gladly admit we dont have to much experience with this, but
>> this
>> strikes me as very odd. So, if anyone has any tips, comments or info I'll
>> be
>> glad to try it out.
>>
>> Thanks in advance!
>>
>> Marius
>>
>> Here are the two entities in question:
>>
>> package project.common.model;
>>
>> import java.util.*;
>>
>> import javax.persistence.*;
>>
>> @Entity
>> public class Wearhouse {
>>
>>        @Id
>>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>>        private Integer wearhouseNr;
>>        private String wearhouseName;
>>
>>        @ManyToMany(cascade={CascadeType.PERSIST}, fetch =
>> FetchType.EAGER)
>>        @JoinTable(
>>                        name="wearhouse_storagecategory",
>>                        joinColumns=@JoinColumn(name="wearhouseNr"),
>>
>>  inverseJoinColumns=@JoinColumn(name="storagecategoryNr")
>>        )
>>        private List<Storagecategory> storageCategories;
>>
>>        public Wearhouse() {
>>        }
>>
>>        public Wearhouse(String wearhouseName) {
>>                this.wearhouseName = wearhouseName;
>>                storageCategories = new ArrayList<Storagecategory>();
>>        }
>>
>>        public Integer getWearhouseNr() {
>>                return this.wearhouseNr;
>>        }
>>
>>        public void setWearhouseNr(Integer wearhouseNr) {
>>                this.wearhouseNr = wearhouseNr;
>>        }
>>
>>        public String getWearhouseName() {
>>                return this.wearhouseName;
>>        }
>>
>>        public void setWearhouseName(String wearhouseName) {
>>                this.wearhouseName = wearhouseName;
>>        }
>>
>>        public void setStorageCategories(List<Storagecategory>
>> storageCategory){
>>                this.storageCategories = storageCategory;
>>        }
>>
>>        public List<Storagecategory> getStorageCategories(){
>>                return storageCategories;
>>        }
>>
>>        public void addStorageCategories(Storagecategory storagecategory)
>> {
>>                if(storageCategories == null)
>>                        storageCategories = new
>> ArrayList<Storagecategory>();
>>                storageCategories.add(storagecategory);
>>
>>        }
>>
>> }
>>
>>
>>
>> package project.common.model;
>>
>> import java.util.*;
>>
>> import javax.persistence.*;
>>
>> @Entity
>> public class Storagecategory {
>>
>>        @Id
>>        @GeneratedValue(strategy = GenerationType.IDENTITY)
>>        private Integer storagecategoryNr;
>>        private String storageCategoryName;
>>
>>        @ManyToMany(mappedBy="storageCategories",
>> cascade={CascadeType.PERSIST})
>>        private List<Wearhouse> wearhouses;
>>
>>        public Storagecategory() {
>>        }
>>
>>        public Storagecategory(String storageCategoryName) {
>>                this.storageCategoryName = storageCategoryName;
>>        }
>>
>>        public Integer getStoragecategoryNr() {
>>                return this.storagecategoryNr;
>>        }
>>
>>        public void setStoragecategoryNr(Integer storagecategoryNr) {
>>                this.storagecategoryNr = storagecategoryNr;
>>        }
>>
>>        public String getStorageCategoryName() {
>>                return this.storageCategoryName;
>>        }
>>
>>        public void setStorageCategoryName(String storageCategoryName) {
>>                this.storageCategoryName = storageCategoryName;
>>        }
>>
>>        public List<Wearhouse> getWearhouses() {
>>                return wearhouses;
>>        }
>>
>>        public void setWearhouses(List<Wearhouse> wearhouses) {
>>                this.wearhouses = wearhouses;
>>
>>                //Wearhouse owns the relation, therefor we have to tell
>> these
>>                //wearhouses this storargecategories is on of the
>> wearhouse's
>> storagecategories.
>>                for (Wearhouse wearhouse : wearhouses)
>>                        wearhouse.addStorageCategories(this);
>>        }
>> }
>> --
>> View this message in context:
>> http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2466994.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/Slow-performance-with-OpenJPA-when-selecting-from-a-ManyToMany-relation.-tp2466994p2467417.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.