ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Parkinson" <pa...@avaning.com>
Subject Performance question
Date Wed, 09 Jan 2008 22:16:34 GMT
Hello:

 

I am using iBATIS, and it's working out well for me, but have run into a
performance issue, and wondering if anyone can help.

 

The object I am trying to persist is pretty complicated - it's an object
which contains a bunch of child objects, which contain children, etc.
The save method in the DAO (I am using the Spring DAO base class) is
pretty long and complicated, as it has to save each child object (or
list of child objects) separately. Example code is at the bottom of this
email.

 

I have put the whole thing into a transaction as well as doing the whole
thing in a batch, which I expect should have some performance
improvements.

 

When I run a performance test, I am finding that the insert (doSave) is
extremely slow - averaging about 100 ms (this after "priming" the test
with 1000 transactions, and running the test over an additional 1000).

 

So, my question is - can anyone make any suggestions on how to speed
this up - clearly 100ms is too long a time to persist this data.

 

Any help would be greatly appreciated.


Regards,

 

parki...

 

 

      private void doSave(Thermostat thermostat) throws Exception

      {

            try

            {           

                  getSqlMapClient().startTransaction();

                  getSqlMapClient().startBatch();

                  

                  int thermostatId = (Integer)
getSqlMapClientTemplate().insert("Thermostat.insert", thermostat);

                  

                  Location location = thermostat.getLocation();

                  location.setThermostatId(thermostatId);

                  getSqlMapClientTemplate().insert("Location.insert",
location);

 

                  Setting setting = thermostat.getSetting();

                  setting.setThermostatId(thermostatId);

                  getSqlMapClientTemplate().insert("Setting.insert",
setting);

                  

                  ContractorInfo contractorInfo =
thermostat.getContractorInfo();

                  contractorInfo.setThermostatId(thermostatId);

 
getSqlMapClientTemplate().insert("ContractorInfo.insert",
contractorInfo);

 

                  List<EquipmentInfo> equipmentInfos =
thermostat.getEquipmentInfos();

                  for(EquipmentInfo equipmentInfo : equipmentInfos)

                  {

                        equipmentInfo.setThermostatId(thermostatId);

 
getSqlMapClientTemplate().insert("EquipmentInfo.insert", equipmentInfo);

                  }

                  

                  InternetConfig internetConfig =
thermostat.getInternetConfig();

                  internetConfig.setThermostatId(thermostatId);

 
getSqlMapClientTemplate().insert("InternetConfig.insert",
internetConfig);

 

                  WifiConfig wifiConfig = thermostat.getWifiConfig();

                  wifiConfig.setThermostatId(thermostatId);

                  getSqlMapClientTemplate().insert("WifiConfig.insert",
wifiConfig);

                  

                  List<Zone> zones = thermostat.getZones();

                  for(Zone zone : zones)

                  {

                        zone.setThermostatId(thermostatId);

                        getSqlMapClientTemplate().insert("Zone.insert",
zone);

                  }

                  

                  Program program = thermostat.getProgram();

                  program.setThermostatId(thermostatId);

                  

                  int programId = (Integer)
getSqlMapClientTemplate().insert("Program.insert", program);

                  

                  List<CalendarEvent> calendarEvents =
program.getCalendarEvents();

                  for(CalendarEvent calendarEvent : calendarEvents)

                  {

                        calendarEvent.setProgramId(programId);

 
getSqlMapClientTemplate().insert("CalendarEvent.insert", calendarEvent);

                  }

                  

                  List<Climate> climates = program.getClimates();

                  for(Climate climate : climates)

                  {

                        climate.setProgramId(programId);

                        int climateId = (Integer)
getSqlMapClientTemplate().insert("Climate.insert", climate);

                        

                        List<ClimateZone> climateZones =
climate.getClimateZones();

                        for(ClimateZone climateZone : climateZones)

                        {

                              climateZone.setClimateId(climateId);

                              climateZone.setProgramId(programId);

 
getSqlMapClientTemplate().insert("ClimateZone.insert", climateZone);

                        }

                  }

                  

                  List<Period> periods = program.getPeriods();

                  for(Period period : periods)

                  {

                        period.setProgramId(programId);

 
getSqlMapClientTemplate().insert("Period.insert", period);

                  }

                  

                  getSqlMapClient().executeBatch();

                  getSqlMapClient().commitTransaction();

            }

            finally

            {

                  getSqlMapClient().endTransaction();

            }

      }

      

 

 

 


Mime
View raw message