【发布时间】:2018-06-23 21:35:55
【问题描述】:
我正在使用带有 Xamarin.Forms 的 Azure 移动应用程序来创建支持脱机的移动应用程序。
我的解决方案是基于https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/client/
这是我用于离线同步的代码:
public class AzureDataSource
{
private async Task InitializeAsync()
{
// Short circuit - local database is already initialized
if (client.SyncContext.IsInitialized)
{
return;
}
// Define the database schema
store.DefineTable<ArrayElement>();
store.DefineTable<InputAnswer>();
//Same thing with 16 others table
...
// Actually create the store and update the schema
await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
}
public async Task SyncOfflineCacheAsync()
{
await InitializeAsync();
//Check if authenticated
if (client.CurrentUser != null)
{
// Push the Operations Queue to the mobile backend
await client.SyncContext.PushAsync();
// Pull each sync table
var arrayTable = await GetTableAsync<ArrayElement>();
await arrayTable.PullAsync();
var inputAnswerInstanceTable = await GetTableAsync<InputAnswer>();
await inputAnswerInstanceTable.PullAsync();
//Same thing with 16 others table
...
}
}
public async Task<IGenericTable<T>> GetTableAsync<T>() where T : TableData
{
await InitializeAsync();
return new AzureCloudTable<T>(client);
}
}
public class AzureCloudTable<T>
{
public AzureCloudTable(MobileServiceClient client)
{
this.client = client;
this.table = client.GetSyncTable<T>();
}
public async Task PullAsync()
{
//Query name used for incremental pull
string queryName = $"incsync_{typeof(T).Name}";
await table.PullAsync(queryName, table.CreateQuery());
}
}
问题在于,即使没有任何东西可以拉取,同步也需要很长时间(Android 设备上需要 8-9 秒,拉取整个数据库需要 25 秒以上)。
我查看了Fiddler 以了解移动应用后端响应需要多长时间,每个请求大约需要 50 毫秒,所以问题似乎不是来自这里。
有人遇到同样的问题吗?是否有什么我做错了什么或提示可以提高我的同步性能?
【问题讨论】:
-
你解决了吗?我也看到了
-
这方面也有很多麻烦。我们有相当大的数据集(最高为 160 行)。尝试做一个 50 组的拉动大约需要 2 分半钟。更进一步的问题是,即使用户手机上已经存在数据,即使没有进行任何更改,加载仍需要大约 30-40 秒。如果设备离线,从手机上的 SQLiteDB 访问相同的数据,几乎是即时的。
-
经历同样的事情。对我来说,这看起来像是一个内存问题。表同步之间的同步暂停以允许 GC.Collect()。使用 Xamarin Profiler,同步结果在 400 - 600 Megs 之间 - 哎哟:(
-
@InquisitorJax 你能从你的发现中做出任何改进吗?
-
@Bejasc 很遗憾没有 - 我认为 MS 并没有对 Azure App Service atm 给予太多关注 :(
标签: xamarin.forms xamarin.android azure-mobile-services offline-caching