Service Fabric基本概念:Partition/Replicas示例

做者:張鼎鬆 (Dingsong Zhang) @ Microsoft設計

 

在上一節的結尾簡單介紹了Service Fabric中分區Partitions和複製replicas的概念,本節主要以示例的形式來具體說明這個抽象概念在Service Fabric中的工做方式。blog

 

1. 分區Partitions和複製replicas部署

一個service能夠包含多個分區Partition,Service Fabric經過使用分區做爲擴展的機制來將工做分佈到不一樣的service實例上。get

一個分區Partition能夠包含一個或者多個複製replicas。Service Fabric經過使用複製來實現可用性。一個分區能夠有一個主複製和多個從複製,多個複製之間的狀態能夠自動同步。當主複製出現錯誤時,其中一個從複製被自動提高爲主複製,以保證系統的可用性。而後將從複製的個數恢復到正常水平,保證足夠的從複製冗餘。同步

 

(Note: 下文中出現的全部Instance 跟Replica是同一個意思)it

以下圖示例,咱們假設一個有一個Cluster中有5個Node, 如今咱們要在Cluster上部署一個Application, 這個Application包含兩個Service。 Application Type爲「A」,Service Type爲「S」。io

首先咱們要建立一個Named Application, 按照上一節提到的Application的命名規範,咱們將這個Named Application叫作「faric:/A1」。依次再建立兩個「S」 type的Named Service,並將它們命名爲「fabric:/A1/S1」和「fabric:/A1/S2」。擴展

 

image

 

2. 建立Named Application高可用

對於建立的這個Named Application 「faric:/A1」, Service Fabric提供三種方式對其進行管理:service

  • REST API: 可使用REST API 經過HTTP 協議和 port 19080進行管理
  • PowerShell commands: PS Cmdlet 使用的是 TCP 協議和 port 19000進行管理
  • Fabric Client: 還可使用 C#/VB的.Net 類庫Fabric Client, 其實內部使用的仍然是 TCP on port 19000的方式

3. 建立Named Service

咱們但願S1有一個分區,三個Instance. S2有2個分區,2個Instance.

image

 

咱們看到Named Service fabric:/A1/S1,按照要求咱們但願設置 Partition count爲 1, Instances count 爲 3。 1個Partition乘以3個 Instances等於3。 (1x3=3). 因此Service Fabric會選擇Cluster中的3個Node來存放這個Named Service. 咱們不須要去控制這個過程,Service Fabric會幫咱們完成這個操做。

如今,S1在Cluster中的分佈以下圖:

Service fabric選擇了 Node #1 #2 和 #3 給

Partition 1, Instance 1: fabric:/A1/S1, P1, I1

Partition 1, Instance 2: fabric:/A1/S1, P1, I2

Partition 1, Instance 3: fabric:/A1/S1, P1, I3

同一Partition的不一樣instance要分佈在不一樣的Node上。

就是說Instance1 和Instance2永遠不可能在同一個Node上,這樣設計的緣由是高可用性:當任何一個Node忽然出現故障不能工做時,其餘Node可以正常提供服務。 可是若是兩個或兩個以上的Instance在同一個Node上時,這個Node出現故障,您將會失去這個Node上的全部數據。

Service Fabric 被設計成能夠將 instance分散發布在不一樣的Nodes上,以保證能夠給用戶高可用性的體驗。

 

image

咱們繼續建立另外一個Named Service: 「fabric:/A1/S2」, Partitions count爲2, Instances/Replicas count爲2。  (2x2=4)

Partition 1, Instance 1: fabric:/A1/S2, P1, I1

Partition 1, Instance 2: fabric:/A1/S2, P1, I2

Partition 2, Instance 1: fabric:/A1/S2, P2, I1

Partition 2, Instance 2: fabric:/A1/S2, P2, I2

Service Fabric 會首先將Partition1 Instance1部署在 Node3上, 而後再將 Partition1 Instance2 放置在Node4上。

(Service Fabric 能夠確保不一樣的 instances/replicas被放置部署在不一樣的 Nodes上)

 

image

 

而後繼續將 Partition2 Instance2 放置在Node5, Partition2 Instance1 放置在 Node4.

你會注意到 Partition1 Instance2 和 Partition2 Instance1 都在同一個 Node4上。這樣是沒有問題的,由於當 Node4出現故障時, 咱們在Cluster中仍然擁有 Partition1 的一個Instance1和 Partition2的 Instance2。

Node4 is a single point of failure but for two instances of different Partitions, 咱們永遠不會讓一個Partition的兩個Instance出如今同一個Node上。

 

image

 

到此爲止,Service Fabric就完成了S1 和S2的部署。

相關文章
相關標籤/搜索