1

I have a spring batch application that uses Azure SQL server as a backend, I am using Hibernate to update the database.

I am reading the data from CSV file using FlatfileReader & writing into Azure SQL Server using ItemWriter as mentioned below

public class StoreWriter implements ItemWriter<List<Store>> {

   Logger logger = Logger.getLogger(StoreWriter.class);

   private HibernateItemWriter<Store> hibernateItemWriter;

   public StoreWriter(HibernateItemWriter<Store> hibernateItemWriter) {
      this.hibernateItemWriter = hibernateItemWriter;
   }

   @Override
   public void write(List<? extends List<Store>> items) throws Exception {
      for (List<Store> Store : items) {
        hibernateItemWriter.write(Store);
      }
      logger.info(String.format("Store Processing Completed %s", new LocalDateTime()));
   }
}

Below is my Hibernate configuration

<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" lazy-init="true">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
        </props>
    </property>
</bean>

<bean class="org.springframework.batch.core.scope.StepScope" />

<!-- DATA SOURCE -->
<bean id="demoDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    <property name="url" value="jdbc:sqlserver://demo.database.windows.net:1433;database=sqldb;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;" />
    <property name="username" value="user1" />
    <property name="password" value="p@ssword1" />
</bean>

What I observe is that it is processing only 360 records per minute, is there a way to increase the performance?

Here is the Hibernate stats:

For 1 record

enter image description here

For 3 records

enter image description here

One Developer
  • 99
  • 5
  • 43
  • 103
  • How about buying a faster machine? Not sure how your connection pooling is configured, but a connection acquisition time of almost 0,5 seconds looks fishy to me. I don't know if these numbers are for an empty connection pool, but maybe your network is crappy? – Christian Beikov Sep 30 '21 at 10:36

0 Answers0