The basic principle of the concept of high-performance framework eventually consistent framework Ray Ray

A, Actor Introduction

Actor is a concurrency model is an alternative to shared memory concurrency model.

Shortcoming shared memory model:
  1. Shared memory model using a variety of locks to solve the state competition, poor performance and make coding is complicated and prone to error.

  2. Shared memory is limited to a single node server resource limitations.

Actor model advantages:
  1. To communicate messages between threads, message sequence single thread, there is no competition status.

  2. Way to communicate a message, you can easily set up a cluster.

  3. The State and Behavior bindings, better control of the state.

Glossary:

Mailbox: can be understood as first in first out queue, and the cache is responsible for receiving messages delivered.

State: state information, such as the user's account balance information.

Behavior: responsible for order processing Mailbox messages, such as debit messages, arrival messages, check your balance messages.

Two, Orleans Introduction

Actor .Net Orleans is a foundation to maintain cross-platform open-source framework, Virtual Actor original concept, support for distributed clusters.

Project Address: http://dotnet.github.io/orleans/

It has the following advantages:
  1. Access to objects Actor, consistent with object-oriented habits.

  2. Proposed the concept of the Virtual Actor, fine-grained access ID by Actor, Actor can carry tens of millions of objects.

  3. The Stateful support, buffer layer can replace more precise control of the memory state, reducing the pressure on the database.

  4. High-performance, single Actor can support 100,000 + in QPS.

  5. Activation transparent, Actor of visitors is permanent, but also provide complete life cycle control, easy to expand.

  6. Native support for clusters, but Actor location transparency, visitors do not need to concern Actor running load will be scheduled according to the node where the node cluster.

  7. Offers a variety of support cluster, the cluster is very easy to deploy, support AdoNet, Zookeeper, K8s, SF and so on.

  8. It provides a complete solution for unit testing, unit testing easy.

  9. It provides a perfect monitoring tool that detailed monitoring indicators.

  10. Based on .net core, supports a variety of platforms.

Glossary:

Silo: a node in the cluster, Grains responsible for maintaining the current node.

SiloGateway: Each node exists, is responsible for maintaining the cluster status and forwards the request.

Grain: equivalent Actor, identified by ID + Interface.

Client: Grain used to access the cluster of client tools.

Three, Ray introduced

Ray Actor model constructed based on event-based distributed ultimately traceable high performance consistency frame, the traditional split complicated distributed transaction processing flow by way of the linear event-driven, performance and higher throughput, more responsive.

Ray offers state maintenance, event publish / subscribe, such as power control, distributed transactions and other modules, and built a distributed ID, distributed lock, lock the weight distributed services.

Ray provide superior performance, can achieve a single Actor 20000 / s events.

Project Address: https://github.com/RayTale/Ray

Glossary:

  1. State (State): aggregate data memory.

  2. Event (Event): change of status information.

  3. EventBus: providing events and send event consumer subscriptions.

  4. Idempotence: to ensure event delivery times will not cause an abnormal state, such as transfer event A chart on multiple service B, but B will only increase once the balance.

Ray's final consistency principle transfer

A user calls A method of transferring accounts Actor of transfer funds, check balances carried Actor account A state based on memory, if the balance is insufficient, the direct cause of the failure is returned, if the check is to produce a successful transfer Event (recording target account Id, transfer amount , the remaining balance) and persisted, and then transmitted to modify memory state EventBus. EventBus a subscriber balance reading event information repository A modified account transfers and bill inserted into the bill a table, call another subscriber account Actor arrival method B according to event information based on, will produce a B account Actor arrival Event (arrival record amount, FromId, the remaining balance) and persisted, and then transmitted to modify memory state EventBus, EventBus arrival of a subscriber billing according to the balance of the read event information modification repository and inserted into the B accounts in a billing table .

A, Actor Introduction

Actor is a concurrency model is an alternative to shared memory concurrency model.

Shortcoming shared memory model:
  1. 共享内存模型使用各种各样的锁来解决状态竞争问题,性能低下且让编码变得复杂和容易出错。

  2. 共享内存受限于单节点的服务器资源限制。

Actor模型的优点:
  1. 线程之间以消息进行通信,消息按顺序单线程处理,不存在状态竞争。

  2. 以消息方式通信,可以方便的组建集群。

  3. 把State和Behavior绑定,能更好的控制状态。

名词解释:

Mailbox:可以理解为先入先出队列,负责接收和缓存送达的消息。

State:状态信息,比如用户的账户余额信息。

Behavior:负责按顺序处理Mailbox中的消息,比如扣款消息、到账消息,查询余额消息等。

二、Orleans介绍

Orleans是.Net基金会维护的一个Actor跨平台开源框架,独创Virtual Actor概念,支持分布式集群。

项目地址:http://dotnet.github.io/orleans/

有以下优点:
  1. 以对象方式访问Actor,符合面向对象的使用习惯。

  2. 提出Virtual Actor概念,可以通过ID访问细粒度的Actor,能承载数千万的Actor对象。

  3. 支持Stateful,能替代缓存层来对内存状态进行更精确的控制,减少数据库的压力。

  4. 高性能,单个Actor能支持10万+的QPS。

  5. 激活透明,Actor对访问者是永久存在的,但也提供完整的生命周期控制,拓展方便。

  6. 原生支持集群,但Actor位置透明,访问者不需要关注Actor运行在那个节点,集群会根据节点情况进行负载调度。

  7. 提供了多种集群支持,集群部署非常方便,支持AdoNet,Zookeeper,K8s,SF等。

  8. 提供了完整的单元测试解决方案,方便进行单元测试。

  9. 提供了完善的监控工具,能够详细的监测各种指标。

  10. 基于.net core,支持各种平台。

名词解释:

Silo:集群中的一个节点,负责维护当前节点的Grains。

SiloGateway:每个节点都存在,负责维护集群状态和转发请求。

Grain:相当于Actor,通过ID+Interface来识别。

Client:用来访问集群中的Grain的客户端工具。

三、Ray介绍

Ray是基于Actor模型构建的基于事件朔源的分布式最终一致性高性能框架,把传统的复杂的分布式事务拆分为由事件驱动的线性处理流程的一种方式,性能和吞吐更高,响应更快。

Ray提供了状态维护、事件发布/订阅、幂等性控制、分布式事务等模块,并内置了分布式ID、分布式锁、分布式权重锁等服务。

Ray提供卓越的性能,单个Actor能达到20000/s的事件。

项目地址:https://github.com/RayTale/Ray

名词解释:

  1. 状态(State):内存聚合数据。

  2. 事件(Event):状态变化的信息。

  3. EventBus:提供事件发送和事件消费订阅。

  4. 幂等性:保证事件送达多次不会导致状态异常,例如上图的A的转账事件多次送达B,但是B只会增加一次余额。

Ray的最终一致性转账原理

A用户调用A账户Actor的转账方法进行转账,A账户Actor根据内存状态进行余额校验,如果余额不足,则直接返回失败原因,如果校验成功则产生一个转账Event(记录目标账户Id、转账金额、剩余余额)并持久化,然后修改内存状态和发送到EventBus。EventBus一个订阅者根据事件信息修改读库中A账户的余额和往账单表中插入一条转账账单,另外一个订阅者根据事件信息调用B账户Actor的到账方法,B账户Actor会产生一个到账Event(记录到账金额、FromId、剩余余额)并持久化,然后修改内存状态和发送到EventBus,EventBus的一个订阅者根据事件信息修改读库中B账户的余额和往账单表中插入一条到账账单。

Guess you like

Origin www.cnblogs.com/Leo_wl/p/11883787.html