How can I improve pull async performance in the Azure mobile services offline sync implementation?

rafael.colonrafael.colon PRMember ✭✭
edited August 2017 in Xamarin.Forms

Hello, I implemented azure offline sync in my Xamarin.Forms app but I am having performance issues when downloading data. I checked the azure api and everything is responding well. I am downloading approx 5,000 records from various tables. the way I am calling the pullasync is in the following way. The process is taking north of 5 minutes to finish. Is there anything I can do to know what exactly is the problem or is there any way to optimize these calls?

    `public async Task SyncAllData(decimal carrierId)
    {
        //TODO 3: Add connectivity check. 
        var connected = false;
        //Different calls for each platform because isReachable doesnt work with android
        if (Device.RuntimePlatform == "Android")
        {
            connected = CrossConnectivity.Current.IsConnected;
        }
        else
        {
            connected = await CrossConnectivity.Current.IsReachable(Helpers.Keys.AzureServiceUrl);
        }


        if (connected == false)
            return;


        try
        {
            //TODO 4: Push and Pull our data
            await MobileService.SyncContext.PushAsync();

        }
        catch (MobileServicePushFailedException ex)
        {
            //await ResolveConflictsAsync(ex.PushResult.Errors);
            Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            throw new Exception("An error occured in data sync");
        }


        PullOptions pullOptions = new PullOptions
        {
            MaxPageSize = 3000    
        };


        //Sync Draw
        try
        {
            //TODO 4: Push and Pull our data
            //await MobileService.SyncContext.PushAsync();
            await sCSDrawTable.PullAsync("mySCSDraws" + carrierId, sCSDrawTable.Where(u => u.CarrierID == carrierId),pullOptions);
            //MessagingCenter.Send<AzureService>(this, "UpdateSyncDate");

        }
        catch (MobileServicePushFailedException ex)
        {
            //await ResolveConflictsAsync(ex.PushResult.Errors);
            Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            throw new Exception("An error occured in data sync");  
        }

        //Sync Payments
        try
        {
            //TODO 4: Push and Pull our data
            //await MobileService.SyncContext.PushAsync();
            await paymentTable.PullAsync("allPayments" + carrierId, paymentTable.Where(x => x.CarrierID == carrierId),pullOptions);
            //MessagingCenter.Send<AzureService>(this, "UpdateSyncDate");
        }
        catch (MobileServicePushFailedException ex)
        {
            //await ResolveConflictsAsync(ex.PushResult.Errors);
            Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            throw new Exception("An error occured in data sync");  
        }


        //Sync Recurring Transactions
        try
        {
            //TODO 4: Push and Pull our data
            //await MobileService.SyncContext.PushAsync();
            await recurringTrxnTable.PullAsync("allRecurringTrxn" + carrierId, recurringTrxnTable.Where(x => x.CarrierID == carrierId),pullOptions);
            //MessagingCenter.Send<AzureService>(this, "UpdateSyncDate");
        }
        catch (MobileServicePushFailedException ex)
        {
            //await ResolveConflictsAsync(ex.PushResult.Errors);
            Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            throw new Exception("An error occured in data sync");  
        }

        //Sync Tax
        try
        {
            //TODO 4: Push and Pull our data

            //await MobileService.SyncContext.PushAsync();
            await taxTable.PullAsync("allTaxRecords" + carrierId, taxTable.Where(u => u.CarrierID == carrierId),pullOptions);


            //MessagingCenter.Send<AzureService>(this, "UpdateSyncDate");

        }
        catch (MobileServicePushFailedException ex)
        {
            //await ResolveConflictsAsync(ex.PushResult.Errors);
            Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            throw new Exception("An error occured in data sync");               
        }

        MessagingCenter.Send<AzureService>(this, "UpdateSyncDate");
    }`

Answers

  • JeffGonzalesJeffGonzales USMember ✭✭

    Have you tried just using PullAsync() and not calling PushAsync() beforehand? PullAsync() will do an implicit PushAsync() if data needs to be updated. It may speed things up for you.

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭
    edited June 2018

    What you need is probably Incremental Sync.

    Edit: you are already doing it. Well basically what you need is only sync the necessary data (by filtering). That's the reason I'm not a fan of Mobile Apps Offline Sync, I prefer to do this manually, and have control on things I need.

Sign In or Register to comment.