【问题标题】:Loading million rows into partitioned Stateful service将百万行加载到分区状态服务中
【发布时间】:2018-07-24 21:50:25
【问题描述】:

我正在尝试将 2000 万行加载到分区状态服务 ReliableDictionary。我将有状态服务划分为 10 个分区。根据 MSDN 文档,我了解到我需要使用一些散列算法来找到正确的分区并将数据发送到它以加载到 IReliabledictionary。所以我使用Hydra根据值获取分区号。我所存储的只是IReliableDictionary 中的List<long>

所以我创建了一个无状态服务作为包装器,

  1. 将从 SQL Server 获取行(2000 万),
  2. 使用Hydra 获取每一行的分区号,
  3. 按分区号分组
  4. 使用 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


【解决方案1】:

您可以通过并行上传到所有分区来节省一些时间。 因此,创建 10 个服务代理(每个分区一个)并同时使用它们。

【讨论】:

  • 我在 itemsShards.count > 1m 条件下尝试了并行调用。但这最终导致超时错误。我将在分区级别尝试并行调用并通知您。
  • 添加并行调用后,现在减少到 30 分钟。 SF Reliabledictionary 上传数据的时间是平时吗?
猜你喜欢
  • 1970-01-01
  • 2011-04-19
  • 2021-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多