i am rowking on a play framework project and a part of my project requies to insert large amounts of data in given time intervals.
I have 2 problems in here:
1- I need to finish bulk inserting sa fast as i can
2- When bulk insert jobs are running, it heavily affects my server response times. I dont know its a problem in play-framework or mine.
heres my current bulk-insert code:
org.hibernate.Session session =
(org.hibernate.Session)SomeEntityModel.em().getDelegate();
Transaction tx = session.beginTransaction();
int i = 0;
for(Inventory o:inventories)
{
returnList.add(SomeEntityModel.getInstance(o));
i++;
if(i%100==0)
{
tx.commit();
session.flush();
session.clear();
tx=session.beginTransaction();
}
}
the getInstance model converts the “o” object to an entity model .
the “o” Objects are coming from a webservice in bulk, and i convert them to “SomeEntityModel” then save it in getInstance method.
I need to know if there is a better and faster way to accomplish bulk insert methods and if there is a better way to use or optimize server response times when jobs are running.
Thanks for helping.
Have you had a look at Akka? It has strong support in Play 2.0 (and module support in Play 1.x if that is what you are using). Akka is designed as high performance concurrency package which one of the use cases is Batch/Bulk.