Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30959 > unrolled thread

hibernate insert is keep slowing down

Started bymcheung63@gmail.com
First post2015-01-31 00:11 -0800
Last post2015-01-31 19:42 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  hibernate insert is keep slowing down mcheung63@gmail.com - 2015-01-31 00:11 -0800
    Re: hibernate insert is keep slowing down Arne Vajhøj <arne@vajhoej.dk> - 2015-01-31 19:42 -0500

#30959 — hibernate insert is keep slowing down

Frommcheung63@gmail.com
Date2015-01-31 00:11 -0800
Subjecthibernate insert is keep slowing down
Message-ID<757c3aa6-6883-4311-bdcd-3c0ee173650e@googlegroups.com>
Hi All
   I am keep calling the below function to insert 100,000 rows to database. For the first ten 100,000 rows, it takes around 3 seconds. But it keep slowing down, up to 25 sec per 100,100 rows. May I know why hibernate will slow down?



	private void testH2_hibernate() {
		Session session = HibernateUtil.openSession();
		Transaction tx = session.beginTransaction();
		DeleteDbFiles.execute(new File(".").getAbsolutePath(), "jmpDB", true);
		Date start = new Date();
		for (int x = 0; x < 100000; x++) {
			JmpData jmpData = new JmpData(0, new Date(), 12345, "cheung", 12345, "peter", JmpType.CALL, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345,
					12345, 12345, 12345, 12345, 12345, 12345, 12345);
			session.save(jmpData);

		}
		tx.commit();
		session.close();
		Date end = new Date();
		System.out.println("hibernate =" + ((double) end.getTime() - start.getTime()) / 1000 + " sec");
	}

thanks
from Peter (cmk128@hotmail.com)

[toc] | [next] | [standalone]


#30975

FromArne Vajhøj <arne@vajhoej.dk>
Date2015-01-31 19:42 -0500
Message-ID<54cd767f$0$286$14726298@news.sunsite.dk>
In reply to#30959
On 1/31/2015 3:11 AM, mcheung63@gmail.com wrote:
> Hi All
>     I am keep calling the below function to insert 100,000 rows to database. For the first ten 100,000 rows, it takes around 3 seconds. But it keep slowing down, up to 25 sec per 100,100 rows. May I know why hibernate will slow down?
>
>
>
> 	private void testH2_hibernate() {
> 		Session session = HibernateUtil.openSession();
> 		Transaction tx = session.beginTransaction();
> 		DeleteDbFiles.execute(new File(".").getAbsolutePath(), "jmpDB", true);
> 		Date start = new Date();
> 		for (int x = 0; x < 100000; x++) {
> 			JmpData jmpData = new JmpData(0, new Date(), 12345, "cheung", 12345, "peter", JmpType.CALL, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345, 12345,
> 					12345, 12345, 12345, 12345, 12345, 12345, 12345);
> 			session.save(jmpData);
>
> 		}
> 		tx.commit();
> 		session.close();
> 		Date end = new Date();
> 		System.out.println("hibernate =" + ((double) end.getTime() - start.getTime()) / 1000 + " sec");
> 	}

A couple of thougths.

First 4000 inserts per second is actually not bad!

Maybe the first inserts are not really written to disk but only to
memory and then it starts writing to disk later.

That could explain the observed. You would need to check the databases
documentation dn configuration to verify whether this could be
the issue or not.

Second bundling 100000 inserts in a single transaction may be
stressing the database a lot.

If your business logic allows it then I think committing every 1000
inserts could be worth trying and see if it makes performance more
predictable.

Third no matter what then I think the probability of Hibernate causing
the problem is very low.

Arne


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web