views:

52

answers:

1

I have an iPhone app syncing with a website using a webservice. The sync procedure I'm using is the following:

  1. Send items that need to sync from iPhone to website
  2. Add items to website MySql database
  3. Send back items that need to sync from website to iPhone
  4. Add items on iPhone Sqlite database

All this is done using one request to the server. Often the user just have a few items (<20) to sync but sometimes a user might have 2000 items to sync. Adding 2000 items to a MySql database can take some time. I'm using transactions and commit on the website when adding the items, something like this:

mysqlTransaction.BeginTransaction();
foreach item sent from iPhone
{
    mysql.CommandText = //Sql query
    mysql.ExecuteNonQuery();
}
mysqlTransaction.Commit();

Sometimes when a user have a lot of items to add, this can take a veeery long time. My idea is therefore to change the sync procedure a little bit and instead of using one large request I divide the request into chunks, maybe sending and recieiving 50 items at a time. This will cause more but faster requests. What are your ideas on this? How would you solve it? Is it the right thing to use transactions and commit on the server?

+1  A: 

I would try to make the update from "iphone to server" and "server to iphone" concurrent and asynchronous if possible. That way the sync will be faster and the iphone app won't block waiting for the whole process to be done.

As well dividing the update into frames if the update is bigger than a given size is a good idea.

Fgblanch