【发布时间】:2018-07-24 21:50:25
【问题描述】:
我正在尝试将 2000 万行加载到分区状态服务 ReliableDictionary。我将有状态服务划分为 10 个分区。根据 MSDN 文档,我了解到我需要使用一些散列算法来找到正确的分区并将数据发送到它以加载到 IReliabledictionary。所以我使用Hydra根据值获取分区号。我所存储的只是IReliableDictionary 中的List<long>。
所以我创建了一个无状态服务作为包装器,
- 将从 SQL Server 获取行(2000 万),
- 使用Hydra 获取每一行的分区号,
- 按分区号分组
- 使用 ServiceRemoting 为每个分区调用有状态服务。但是,如果我每个请求发送 100 万行数据,我会得到
fabric message too large异常,因此我将每个请求分成 100000 行。
这需要 74 分钟才能完成。这太长了。下面是上传代码-
请指教。
foreach (var itemKvp in ItemsDictionary)
{
var ulnv2Uri = new Uri("fabric:/TestApp/dataservice");
//Insert to the correct shard based on the hash algorithm
var dataService = _serviceProxyFactory.CreateServiceProxy<IDataService>(
dataStoreUri,
new ServicePartitionKey(itemKvp.Key), TargetReplicaSelector.PrimaryReplica, "dataServiceRemotingListener");
var itemsShard = itemKvp.Value;
//if the total records count is greater then 100000 then send it in chunks
if (itemsShard.Count > 1_000_000)
{
//var tasks = new List<Task>();
var totalCount = itemsShard.Count;
var pageSize = 100000;
var page = 1;
var skip = 0;
while (skip < totalCount)
{
await dataService.InsertData(itemsShard.Skip(skip).Take(pageSize).ToList());
page++;
skip = pageSize * (page - 1);
}
}
else
{
//otherwise send all together
await dataService.InsertData(itemsShard);
}
}
【问题讨论】:
-
您的 IReliableDictionary 是什么样的?当您说要在 IReliableDictionary 中存储 List
时,您的意思是它是 IReliableDictionary 还是按照 IReliableDictionary > 的方式存储某些内容?
标签: azure-service-fabric service-fabric-stateful