Hibernate Batch Operation performance

I have around 5000 records to update. I am trying to measure performance of the operation. It starts with around 100 ms but after every thousand updates operation time increases around 80 ms. Why is it slowing down? JVM?

StatelessSession session = dao.getStatelessSession();
Transaction transaction = session.beginTransaction();
try {
    List<Entity> list = dao.findAll();
    int counter = 0;
    for (Entity each : list) {
        final Date startTime = Clock.getTime();
        webService.execute(each);
        session.update(each);
        counter += 1;
        final Date endTime = Clock.getTime();
        LOGGER.info("***** " + getMilliSecondsDifference(startTime, endTime) + " for count: " + counter + "*****");
    }
} catch (Exception e) {
    LOGGER.info("***** Exception occured : ", e);
} finally {
    transaction.commit();
    session.close();
}

Upvotes: 2

Views: 274

Answers (2)

Afsin Buyuksarac
Afsin Buyuksarac

Reputation: 298

Hüseyin,

It doesnt have to be hibernate problem at all if we look at your code. I suggest you to comment out your line related with webservice call.

Then please try again batch hql running.

Maybe networking could be getting slower.

Upvotes: 1

jMounir
jMounir

Reputation: 495

You have one transaction and dealing with a large number of objects. here you will probabely have a memory leak and performance issue too. The objects references will stay in memory untill a session flush is executed (commit). so you will have a big number of object in memory in addition of the big number of informations about the object changes that will be also kept in the hibernate session and that can alter the performance too (i'am not an hibernate expert but you should consider this point) I think that you may think about using a lot of transactions

See theses interesting links:

Transaction Management for bulk operations

Hibernate session and Transaction Management Guidelines

Good luck

Upvotes: 0

Related Questions