Performance 服务结构事务比另一台计算机中的SQL事务慢10倍

Performance 服务结构事务比另一台计算机中的SQL事务慢10倍,performance,azure,dictionary,transactions,azure-service-fabric,Performance,Azure,Dictionary,Transactions,Azure Service Fabric,我尝试过在进程中使用可靠的字典进行事务处理,它们的执行速度比进程外的SQL事务慢10倍。我们希望使用ServiceFabric,但如果它不能在正在处理的事务中执行简单的增量任务,我们又如何依赖它呢 在服务结构上 简单调用GetFromStateful方法5000次大约需要100秒才能完成 在RDBMS上 同样的操作需要10秒才能完成。(疯狂的是,即使这是进程外的操作,速度也要慢10倍) 我不明白的是 为什么这么慢 微软的推广速度如此之快 代码 using System.Collecti

我尝试过在进程中使用可靠的字典进行事务处理,它们的执行速度比进程外的SQL事务慢10倍。我们希望使用ServiceFabric,但如果它不能在正在处理的事务中执行简单的增量任务,我们又如何依赖它呢

在服务结构上

简单调用GetFromStateful方法5000次大约需要100秒才能完成

在RDBMS上

同样的操作需要10秒才能完成。(疯狂的是,即使这是进程外的操作,速度也要慢10倍)

我不明白的是

  • 为什么这么慢
  • 微软的推广速度如此之快
代码

   using System.Collections.Generic;
   using System.Fabric;
   using System.Threading.Tasks;
   using Microsoft.ServiceFabric.Data.Collections;
   using Microsoft.ServiceFabric.Services.Communication.Runtime;
   using Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime;
   using Microsoft.ServiceFabric.Services.Runtime;

   namespace Counting
    {
   internal sealed class Counting : StatefulService,
       ICount
   {
       private IReliableDictionary<string, int> _myDictionary = null;

       public Counting(StatefulServiceContext context)
           : base(context)
       {
       }

       protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
       {
           var settings = new FabricTransportRemotingListenerSettings
           {
               MaxConcurrentCalls = 32
           };

           yield return
               new ServiceReplicaListener(
                   context =>
                       new FabricTransportServiceRemotingListener(context, this, settings));
       }

       async Task<int> ICount.GetFromStateful()
       {
           if (_myDictionary == null)
           {
               _myDictionary = await StateManager.GetOrAddAsync<IReliableDictionary<string, int>>("myDictionary").ConfigureAwait(false);
           }

           using (var tx = StateManager.CreateTransaction())
           {
               var result = await _myDictionary.AddOrUpdateAsync(tx, "Counter", 0, (key, value) => ++value).ConfigureAwait(false);

               await tx.CommitAsync().ConfigureAwait(false);

               return result;
           }
       }
   }
  }
使用System.Collections.Generic;
使用系统、织物;
使用System.Threading.Tasks;
使用Microsoft.ServiceFabric.Data.Collections;
使用Microsoft.ServiceFabric.Services.Communication.Runtime;
使用Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime;
使用Microsoft.ServiceFabric.Services.Runtime;
名称空间计数
{
内部密封类计数:StatefulService,
I计数
{
私有IReliableDictionary _myDictionary=null;
公共计数(StatefulServiceContext上下文)
:基本(上下文)
{
}
受保护的重写IEnumerable CreateServiceReplicaListeners()
{
var设置=新的FabricTransportRemotingListenerSettings
{
MaxConcurrentCalls=32
};
生利
新ServiceReplicaListener(
上下文=>
新的FabricTransportServiceRemotingListener(上下文、此、设置));
}
异步任务ICount.GetFromStateful()
{
如果(_myDictionary==null)
{
_myDictionary=await StateManager.GetOrAddAsync(“myDictionary”).ConfigureAwait(false);
}
使用(var tx=StateManager.CreateTransaction())
{
var result=await\u myDictionary.AddOrUpdateAsync(tx,“Counter”,0,(键,值)=>++值)。ConfigureAwait(false);
wait tx.CommitAsync().configurewait(false);
返回结果;
}
}
}
}
Microsoft Service Fabric团队将此作为

来自注释

可靠字典定期从内存中删除最近使用最少的值。这是为了使

·大型可靠词典

·更高密度:每个副本的可靠收集密度更高,每个节点的副本密度更高。 取舍是,这可能会增加读取延迟:需要磁盘IO来检索未缓存在内存中的值。”


但在执行此操作时,我们看不到任何cpu/ram/disc IO。

您更新一条记录..SF将对其设置写锁

SF是为3个病例设计的IMHO

  • 1) 非常小的东西,如微服务和演员 管理许多SQL Server成本高昂
  • 2) 非常大规模-切分等
  • 3) 高可用性,SQL只具有fall over及其 那就很难了

记住,这是一个NoSQL,所以你需要考虑文档而不是表。

ConfigureAwait(false)语句是怎么回事?删除了所有语句,没有任何区别。在这一行中,我们正在减速。wait tx.CommitAsync().ConfigureAwait(false);这是否会影响[StatePersistence(StatePersistence.peristed)]内部类CountingActor:Actor,icountingactor从您发布的内容中,无法判断您做错了什么,但您做错了什么,因为其他人每秒可以收到1000个请求。也许您应该下载性能示例,看看正确编写的解决方案可以做什么,正如我在其他相关问题中所问的l、 张贴调用方的代码。