Given: Method in a @Stateless
EJB, JTA Mysql data source and a list of about 5000 entities which I'm trying to persist in a cycle :
List<MyObj> objList = entityManager.createNamedQuery("Q1", MyObj.class).getResultList();
for(MyObj obj : objList) {
long start_time = Calendar.getInstance().getTimeInMillis();
entityManager.persist(obj);
long end_time = Calendar.getInstance().getTimeInMillis();
logger.info("Object saved in " + (end_time - start_time) + "ms");
}
entityManager.close();
Log shows gradually decreasing performance from 15ms
up to 180ms
save time per entity. I believe Mysql sever settings are far beyond the needs of this task - it shows insignificant increase in CPU and I/O operations. Flushing EntityManager
after each update has no effect.
What could be the reason for such performance decrease? Please point me in the right direction.