Understanding Hibernate Session batching is often the key to improve a bulk import.
He improves the performance by focusing on table indexes, GORM cleanup and choosing the appropriate MYSQL Database engine.
I've created a repository with the code sample.
In the previous linked we learned that indexes can improve heavily our database performance. Learn how to create a composite index with GORM.
Akshay Chavan and Prakash Bhavnath compare different approaches for bulk inserts with GORM and Grails.
- Traditional Save
- Cleanup GORM
- Batch processing
- Hibernate Stateless Session
Note: in the blog post they call everytime save(flush: true) instead of save(). Flushing makes inserts much slower. Bear that in mind, set it to true only if you need to.
I have created a repository with sample code. From what I am seeing
Hibernate StatelessSession approach is the fastest.
If you are doing Grails 2 development, you will need to call too:
DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP.get().clear() when processing your batches. Detailed explanation by @burtbeckwith.