-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
 Post subject: is there a faster way?
PostPosted: Mon Jan 26, 2004 10:21 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
/**
* add a List dataBO object in the database
* @param data
*/
public void addAll(List data) {

try {

for (int i = 0; i < data.size(); i++) {
this.session.save((MsconsDataBO)data.get(i));
}

} catch (Exception e) {

Import.errorExceptionExit("[couldn't add MsconsDataBO]", e);

}
}

Hi all,

i use this to add a List with objects to the database.
For 8640 objects this function takes 5860 ms. So i wonder if there another way to put more then one object in a time in the Hibernate session? Or a faster way to do this ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 6:21 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
It is about 90 objects per second, which is not bad.
How does your objet look like? On which HW are you running?
Look in the sql log if you see unnecessary rows, just to begin.
/rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 4:44 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
It's true it's not really bad, but the program have to import information of about 15.000.000 in totaal, so if there is a way to get it faster it would be apprceciated.

Well the object look like this:

public class MsconsDataBO {

// variables
private long id;
private double amount;
private String dateTime;
private EannumberBO eannumberBO;

// methods

And then the getters and setters.

HW:

CPU : P4 2,4GHz
MEM : 512MB ram
OS : Win XP Pro

Well if this is a reasonable performance i'm going to take the rest of my application under the loop to see if there are other things that are time expensive.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 4:52 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Uhm, probabily you should be able to get better performance on that hw.
Still I don't know what is a EannumberBO.
Please send your xml mapping.
What database are you using?
Can you send a sql log?
/rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 4:55 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Uhm, probabily you should be able to get better performance on that hw.
Still I don't know what is a EannumberBO.
Please send your xml mapping.
What database are you using?
Can you send a sql log?
/rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 5:30 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
public class EannumberBO implements Serializable {

// variables
private long id;
private String number;

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="nl.company.energyalert.mscons.businessobjects.database.MsconsDataBO" table="consumption_mscons">

<id name="id" column="id" unsaved-value="0">
<generator class="native">
</generator>
</id>

<property name="amount" column="amount" />
<property name="dateTime" column="date_time" />

<many-to-one name="eannumberBO" class="nl.company.energyalert.mscons.businessobjects.database.EannumberBO" column="fk_eannumber" />

</class>

</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="nl.company.energyalert.mscons.businessobjects.database.EannumberBO" table="eannumber">

<id name="id" column="id" unsaved-value="0">
<generator class="native">
</generator>
</id>

<property name="number" column="number"/>

</class>

</hibernate-mapping>

I'm using Mysql 3.23.55-max-nt

I'm currently not running a log file for that database.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 5:42 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Yes, I think you should get better performance.
Before trying to debug the application try to isolate the transaction and test the real speed.
Write a small application like:

Code:
long times = 1000;
Vector v = new Vector(times)
for(i=0; i<times; i++) {
  MsconsDataBO data = new MsconsDataBo();
  data.fillwiththeneededstuff();
  v.add(data);
}

long start = System.getCurrentMillis();
addAll(v);
long end = System.getCurrentMillis();


and see if you get the real numbers.
If you get them, the problem is somwhere else
/robcos


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:17 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
3 Query insert into consumption_mscons (amount, date_time, fk_eannumber) values (15.0, '20031201000000', 34)
3 Query SELECT LAST_INSERT_ID()

this if from my mysql log file... i think "SELECT LAST_INSERT_ID()" is not nessecary after every insert. Is that true? For the rest my stripped app is giving me the same times, so still a little slow.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes it is necessary, because hibernate needs to set the id property of your object after you have saved it. You can try to circumvent this using another generator or assigned identifiers.

PS: Remember bulk operations are not the job hibernate is designed for.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:23 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
Well i did a little test before this and Hibernate was faster then the code i made by hand, so why not choose Hibernate then?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:27 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
No, it is not necessary if you don't need the saved object anymore. Anyway I don't know if it is possible to avoid it (Hibernate gurus?) and it should not inpact on your performance very much.
I still think the problem is somwhere else.
Did you create the table with the export tool or you had it already? Do you have any constrains in the table?


Top
 Profile  
 
 Post subject: Performance example
PostPosted: Tue Jan 27, 2004 6:36 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Inserting a two column row in a table, I get more than 300 records per second.


Quote:
239 Query insert into categoryrecipient (categoryid, recipientid) values (165, 3155)
239 Query SELECT LAST_INSERT_ID()


Using :
Redhat 8
Mysql 4
Hibernate 2.
P3 800 mhz

You make the conclusion...
/roberto


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
robcos wrote:
Anyway I don't know if it is possible to avoid it (Hibernate gurus?)


As I said, use another generator.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:46 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
of course...
/ro


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:49 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
I do use InnoDB on all my tables, that should be a little performance isue as well. But i changed id generator to "increment" instead of "native", now i don't have the "SELECT LAST INSERTED ID()" query, this saves a pretty amount of time already.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.