对象是否由Azure构造服务中的不同辅助角色共享? [英] Are objects shared by different worker roles in Azure fabric service?

查看:54
本文介绍了对象是否由Azure构造服务中的不同辅助角色共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure服务结构来开发Asp.Net核心.我们也提供无国籍服务.在Azure门户上,我们有5个节点,每个节点有2个实例.我已经实现了日志记录机制.我也在使用依赖注入.

I am working on Asp.Net core with Azure service fabric. We have stateless service too. On the Azure portal we have 5 nodes and for each node we have 2 instances. I have implemented logging mechanism. I am using Dependency injection too.

每当工作者角色从数据库中获取记录时,在处理记录之前几乎没有值,因为我需要在我的日志记录框架中记录这些值.我正在使用此值来跟踪所有系统上的遥测.

Whenever worker role pick up the record from database,there are few values till the time that record is processed because I need to log those values in my logging framework. I am using this value to track telemetry across all systems.

当前,我已经为这些值创建了一个对象,并且每当我拿起文档时就将该对象分配给日志记录类.

Currently I have created an object for such values and assigning this object to logging class whenever I picked up the document.

当我在本地环境中运行时,它工作正常,因为我有一个节点和一个实例.移至Azure后,它将开始覆盖值.

It's working fine when I run in local environment because I have one node and one instance. Once I moved to Azure, it starts overwriting values.

如何避免呢?我该如何确保该值在处理之前不改变?

How to avoid it? How can I make sure that value should not change till it gets processed?

对于Asp.Net,我们进行会话,是否有类似工作者角色的内容?

For the Asp.Net we have session, do we have anything such like for worker role?

感谢您的输入和指导.

推荐答案

我认为您的问题与服务结构具有两个模型,共享过程专有过程.

Service fabric has two models, Shared Process and Exclusive process.

共享模型是默认的,当您在创建服务时未指定托管模型时,该模型将使用单个进程来托管同一CodePackage(可执行文件)的多个副本.这意味着,当您在同一节点上启动多个副本时,它将创建一个进程并初始化该进程中的任何新副本.当您使用 static singleton 对象时,这是一个 大问题 ,因为所有副本都将看到同一对象,但是在您的代码逻辑上,对于每个服务实例,它应该是不同的.

The Shared Model is the default when you don't specify a hosting model when creating the service, this model will use a single process to host multiple replicas from same CodePackage(executable). That means, when you start multiple replicas on same node, it will create one process and initialise any new replica in this process. This is a big problem when you use static and singleton objects, because all replicas will see the same object, but on you code logic it supposed to be different for each instance of your service.

独占进程将在每次将新副本放置在同一节点上时创建一个新进程.因此,如果您使用的是 static singleton 对象,则应使用该模型.

The Exclusive Process will create a new process every time a new replica is placed on same node. So if you are using static or singleton objects, this should be the model to use.

这篇关于对象是否由Azure构造服务中的不同辅助角色共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆