附录:1-Grain生命周期-译注
Grain Lifecycle
Grains are logical entities that always exist, virtually, and have stable logical identities (keys). Application code never creates or destroys grains. Instead, it acts as if all possible grains are always in memory and available for processing requests.
注:
- Grain是一直存在的逻辑实体,有稳定的逻辑标识(键)。应用程序代码永远不会创建或销毁Grain。相反,它的作用就好像所有可能的谷物都在内存中,对于处理请求,一直处于可用状态。
- 永远假设Grain是活着的。
Grains get physically instantiated, activated, by the Orleans runtime automatically on an as-needed to process incoming requests. After a grain has been idle for a certain amount of time, the Orleans runtime automatically removes, deactivates, it from memory.
注:
- 当需要处理请求时,Orleans运行时会将Grain自动activate。
- 当Grain被闲置一段时间时,Orleans运行时会将Grain自动remove、deactivate。
A physical instance of a grain in memory is called a grain activation. Grain activations are invisible to application code as well as the process of activating and deactivating them. Only the grain itself can be aware of that - by overriding virtual methods OnActivateAsync and OnDeactivateAsync that get invoked upon activation and deactivation of the grain respectively.
注:
- 在内存中实例化Grain叫作Grain激活。
- 对应用程序而言,activate与deactivate是透明的。
- activate:override OnActivateAsync虚方法;deactivate: override OnDeactivateAsync 虚方法
Over the course of its eternal, virtual, life a grain goes through the cycles of activations and deactivations, staying always available for callers to invoke it, whether it is in memory at the time of the call or not.
注:
- 无论Grain在不在内存里,Grain对于调用者总是可用的。
When you get a grain reference in a client or in another grain by using GetGrain, you only get a proxy object, called a grain reference, with a logical address (identity) of the grain, but not its physical address. When you call a method using the grain reference, then the grain will get activated in a silo (if it is not already activated in the cluster). Your method calls on the grain reference are sent to the activation by the Orleans runtime.
注:
- 客户端使用Grain引用时,使用的是它的引用代理类,不是物理地址。
- Grain实例在云端的Silo里。
- 使用Grain引用时,如果Grain不存在,Orleans运行时会激活它。
A call to GetGrain is an inexpensive local operation of constructing a grain reference with an embedded identity of the target grain.
Virtual methods
A grain class can optionally override OnActivateAsync and OnDeactivateAsync virtual methods that get invoked by the Orleans runtime upon activation and deactivation of each grain of the class. This gives the grain code a chance to perform additional initialization and cleanup operations. An exception throw by OnActivateAsync fails the activation process. While OnActivateAsync, if overridden, is always called as part of the grain activation process, OnDeactivateAsync is not guaranteed to get called in all situations, for example, in case of a server failure or other abnormal events. Because of that, applications should not rely on OnDeactivateAsync for performing critical operations, such as persistence of state changes, and only use it for best effort operations.
注:
- 重写OnActivateAsync 自定义initialization操作
- 重写OnDeactivateAsync 自定义cleanup操作
- OnActivateAsync中报异常,将阻断实例化过程。
- 不建议重写OnDeactivateAsync。
Declarative persistence
If a grain class uses declarative persistence by inheriting from Grain, the Orleans runtime automatically loads state of grain of that class as part of the activation process by calling ReadStateAsync before invoking OnActivateAsync and processing a request to the grain. A failure to load grain’s state with ReadStateAsync fails the activation process. The Orleans runtime never automatically persists grain’s state, and leaves it up to the application code when to call WriteStateAsync’
Sequence of events in a grain’s life cycle
- 如果Grain继承了Grain,Orleans运行时会在执行OnActivateAsync之前,执行ReadStateAsync,自动加载state。
- 如果加载state失败,则激活过程失败。
- Orleans运行时从不会自动持久化grain的state。
The life cycle of a grain is like this
Another grain or a client calls a method of the grain
The grain gets activated (if it is not activated anywhere in the silo) and an instance of the grain class is created
Constructor of the grain is executed and DI will setup (If you have DI)
If declarative persistence is used, the grain state is read from storage
If overridden, OnActivateAsync is called
The grain processes incoming requests
The grain remains idle for some time
Runtime decides to deactivate the grain
Runtime calls OnDeactivateAsync
Runtime removes the grain from memory
Upon a graceful shutdown of a silo, all grain activations it holds get deactivated. Any requests waiting to be processed in grains’ queues get forwarded to other silos in the cluster, where new activations of deactivated grains get created on an as-needed basis. If a silo shuts down or dies ungracefully, other silos in the cluster detect the failure, and start creating new activations of grains lost on the failed silo, as new requests for those grains arrive. Note that detection of a silo failure takes some time (configurable), and hence the process of reactivating lost grains isn’t instantaneous
注:
- silo正常关闭,所有激活的grain将失活;等待处理的请求将由云中的其他silo处理,在silo里根据需求激活grain。
- silo非正常关闭,请求到达时,其他silo会检测到失败,会在失败的silo上创建grain;因为检测到silo故障需要一定的时间(可配置),丢失的grain不会被立即重新激活。
附录:1-Grain生命周期-译注的更多相关文章
- Angular2 组件生命周期
1. 说明 Angular每个组件都存在一个生命周期,从创建,变更到销毁.Angular提供组件生命周期钩子,把这些关键时刻暴露出来,赋予在这些关键结点和组件进行交互的能力. 2. 接口 按照生命周期 ...
- Android 生命周期 和 onWindowFocusChanged
转载 http://blog.csdn.net/pi9nc/article/details/9237031 onWindowFocusChanged重要作用 Activity生命周期中,onStart ...
- Mvc请求的生命周期
ASP.NET Core : Mvc请求的生命周期 translation from http://www.techbloginterview.com/asp-net-core-the-mvc-req ...
- java基础78 Servlet的生命周期
1.Servlet的生命周期 简单的解析就是: 创建servlet实例(调用构造器)---->调用init()方法---->调用service()方法----->调用destroy( ...
- onWindowFocusChanged重要作用 and Activity生命周期
onWindowFocusChanged重要作用 Activity生命周期中,onStart, onResume, onCreate都不是真正visible的时间点,真正的visible时间点是onW ...
- thinkphp5.0生命周期
本篇内容我们对ThinkPHP5.0的应用请求的生命周期做大致的介绍,以便于开发者了解整个执行流程. 1.入口文件 用户发起的请求都会经过应用的入口文件,通常是 public/index.php文件. ...
- 【译】深入理解Rust中的生命周期
原文标题:Understanding Rust Lifetimes 原文链接:https://medium.com/nearprotocol/understanding-rust-lifetimes- ...
- react组件的生命周期
写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...
- 浅谈 Fragment 生命周期
版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Fragment 文中如有纰漏,欢迎大家留言指出. Fragment 是在 Android 3.0 中 ...
随机推荐
- 深入理解Amazon Alexa Skill(四)
本节利用三星Smartthings Classic物联网平台的web service smartapp,实现了一个Alexa智能家居skill的例子,由此来了解Alexa是如何控制其他云的智能家居设备 ...
- Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效
原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...
- Win8Metro(C#)数字图像处理--2.19图像水平镜像
原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像 [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码] ...
- 分配粒度和内存页面大小(x86处理器平台的分配粒度是64K,内存页是4K,所以section都是0x1000对齐,硬盘扇区大小是512字节,所以PE文件默认文件对齐是0x200)
分配粒度和内存页面大小 x86处理器平台的分配粒度是64K,32位CPU的内存页面大小是4K,64位是8K,保留内存地址空间总是要和分配粒度对齐.一个分配粒度里包含16个内存页面. 这是个概念,具体不 ...
- jquery模拟按下回车实现代码
简单地记下jquery实现回车事件,代码如下: 全局: 代码如下: $(function(){ document.onkeydown = function(e){ var ev = document. ...
- Cocos2d-x 3.X Qt MinGW版本编译运行
自Cocos2d-x 3.X引入了C++ 11特性,在Windows平台上的支持就仅限VS 2012,其实还可以尝试MinGW版本,GitHub上有MinGW版本的Qt Creator工程. 地址:h ...
- Qt优雅地结束线程(两种方法都是用Mutex锁住bool变量进行修改,然后由bool变量控制耗时动作的退出,即正常退出)
如果一个线程运行完成,就会结束.可很多情况并非这么简单,由于某种特殊原因,当线程还未执行完时,我们就想中止它.不恰当的中止往往会引起一些未知错误.比如:当关闭主界面的时候,很有可能次线程正在运行,这时 ...
- 【MyEclipse常见错误】-java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory的解决
ApacheJavaTomcatMyeclipse 自己前一段时间出现了这个问题,通过在网上搜索,大概知道了原因,整理下一,以供大家参考. 将项目部署好后,启动tomcat后报错,java.lang ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发
进行本文之前需要在数据库用户表里面增加一条用户数据,直接手动添加即可,未安全考虑密码一定要使用Md5加密后的,这里提供666666的Md5密文为(c831b04de153469d),本文完成登录模块的 ...
- 626. Exchange Seats-(LeetCode之Database篇)
问题表述 数据库表如下: id student 1 Abbot 2 Doris 3 Emerson 4 Green 5 Jeames 现在要通过SQL语句将表变换成如下: id student 1 D ...