你需要知道的那些 Abilities
Tags: availability, reliability, stability
Published: 2017-10-10 06:01:47

---
title: ä½ éœ€è¦çŸ¥é“çš„é‚£äº› Abilities
published: true
description: å¯ç”¨æ€§ï¼Œå¯é æ€§ï¼Œç¨³å®šæ€§
tags: availability, reliability, stability
---

å¼•è‡ªï¼šhttp://xianjing.github.io/2017/08/11/abilities/

å¦‚æžœä½ åŽ»ä¹°ä¸€éƒ¨æ‰‹æœºï¼Œä½ ä¼šè€ƒè™‘ä»€ä¹ˆå› ç´ å‘¢ï¼Ÿä¸€èˆ¬æˆ‘ä»¬éƒ½ä¼šé¦–å…ˆè€ƒè™‘æ™ºèƒ½æ‰‹æœºã€ç…§ç›¸åŠŸèƒ½ã€å¤šå¤§å®¹é‡ç­‰ã€‚è€Œé™¤äº†è¿™äº›ï¼Œæˆ‘ä»¬é€šå¸¸è¿˜ä¼šè€ƒè™‘å“ç‰Œã€é¢œè‰²ã€å¤–åž‹å¥½ä¸å¥½çœ‹ã€æ—¶å°šä¸Žå¦ã€‚ä½œä¸ºä¸€ä¸ªè½¯ä»¶äº§å“ä¹Ÿä¸ä¾‹å¤–ï¼Œç”¨æˆ·é¦–å…ˆä¼šæœŸæœ›ç³»ç»Ÿè¦æ»¡è¶³æ­£å¸¸çš„åŠŸèƒ½éœ€æ±‚ï¼ŒåŒæ—¶ç³»ç»Ÿè¿˜è¦æ»¡è¶³å¥½ç”¨ã€æ€§èƒ½å¥½ã€ç¨³å®šå¯é ç­‰å…¶ä»–ç‰¹æ€§ã€‚ä¸€èˆ¬æˆ‘ä»¬ä¼šæŠŠè¿™äº›ç§°ä¸ºéžåŠŸèƒ½æ€§éœ€æ±‚æˆ–è€…è·¨åŠŸèƒ½æ€§éœ€æ±‚ã€‚ç³»ç»Ÿçš„æ¯ä¸€æ¬¡æ•…éšœå’Œå®•æœºå¯¹ç”¨æˆ·éƒ½æ˜¯ä¸å¯å¿½è§†çš„æŸå¤±ï¼Œæ‰€ä»¥è¿™äº›éžåŠŸèƒ½æ€§éœ€æ±‚ä¹Ÿæ˜¯è½¯ä»¶è´¨é‡éžå¸¸é‡è¦çš„å±žæ€§ï¼Œæ˜¯è½¯ä»¶æž¶æž„è®¾è®¡éœ€è¦æ»¡è¶³çš„ç›®æ ‡ã€‚

åœ¨è¿è¡Œæ—¶çš„éžåŠŸèƒ½éœ€æ±‚ä¸­ï¼Œæˆ‘ä»¬å¸¸å¸¸ä¼šæåˆ°å‡ ä¸ªè¯æœ‰ Availabilityã€Stability å’Œ Reliabilityï¼Œå³ç³»ç»Ÿè¦é«˜å¯ç”¨ã€é«˜å¯é å’Œç¨³å®šã€‚é‚£ä¹ˆå¯ç”¨ã€å¯é è¿˜æœ‰ç¨³å®šæ˜¯ä»€ä¹ˆæ„æ€å‘¢ï¼Ÿå¦‚ä½•è¡¡é‡ï¼Ÿå®ƒä»¬ä¹‹é—´åˆæœ‰ä»€ä¹ˆåŒºåˆ«ï¼Ÿæˆ‘ç»å¸¸åœ¨ä¸åŒåœºæ™¯ä¸‹å¬åˆ°è¿™å‡ ä¸ªè¯çš„æ··ç”¨ã€‚ä»Šå¤©å°±å…ˆæ¥è°ˆä¸€è°ˆè¿™å‡ ä¸ª abilityã€‚

###1. Availability å¯ç”¨æ€§
> Availability defines the proportion of time that the system is functional and working. It can be measured as a percentage of the total system downtime over a predefined period. Availability will be affected by system errors, infrastructure problems, malicious attacks, and system load. - Microsoft Application Architecture Guide

å¯ç”¨æ€§æŒ‡ç³»ç»Ÿåœ¨ç»™å®šæ—¶é—´å†…å¯ä»¥æ­£å¸¸å·¥ä½œçš„æ¦‚çŽ‡ï¼Œé€šå¸¸ç”¨ SLA æŒ‡æ ‡æ¥è¡¨ç¤ºï¼Œå¦‚ä¸‹å›¾æ‰€ç¤ºã€‚
SLAæŒ‡æ ‡
![SLA](https://thepracticaldev.s3.amazonaws.com/i/4rga1ynsofu6l7p30hd0.png)
å¢¨è²å®šå¾‹è¯´ â€œä¼šå‡ºé”™çš„äº‹æ€»ä¼šå‡ºé”™â€ï¼Œå¯ç”¨æ€§åšåˆ° 100 æ˜¯å¯æœ›è€Œä¸å¯åŠçš„ã€‚å¯¹äºŽ SLA æŒ‡æ ‡æ¥è¯´ï¼Œ9 çš„æ•°å­—è¶Šå¤šå¯ç”¨æ€§è¶Šé«˜ï¼Œå®•æœºæ—¶é—´è¶Šå°‘ï¼Œç³»ç»Ÿå°±å¯ä»¥åœ¨ç»™å®šçš„æ—¶åˆ»å†…é«˜æ¯”ä¾‹åœ°æ­£å¸¸å·¥ä½œã€‚ç„¶è€Œå¯¹ç³»ç»Ÿçš„æŒ‘æˆ˜å°±è¶Šå¤§ï¼ŒæŠ•å…¥çš„æˆæœ¬ä¹Ÿä¼šè¶Šé«˜ã€‚ æ¯”å¦‚ 5 ä¸ª 9 è¦æ±‚ç³»ç»Ÿæ¯å¹´åªå®•æœº 5 åˆ†é’Ÿå·¦å³ï¼Œè€Œ 4 ä¸ª 9 è¦æ±‚æ¯å¹´å®•æœºæ—¶é—´ä¸è¶…è¿‡ä¸€ä¸ªå°æ—¶ã€‚è¿™å°±ä½¿å¾—ç³»ç»Ÿéœ€è¦åœ¨è®¾è®¡ã€åŸºç¡€è®¾æ–½ã€æ•°æ®å¤‡ä»½ç­‰ä¸åŒå±‚é¢é‡‡å–å¤šç§æ–¹å¼ï¼Œç”šè‡³å¢žåŠ åŸºç¡€è®¾æ–½æŠ•èµ„æ¥ä¿è¯å¯ç”¨æ€§ã€‚

> â€œå½“ä½ çš„è®¾å¤‡å¤„ç†äººå‘½å…³å¤©çš„äº‹æƒ…ï¼Œæˆ–ä¸šåŠ¡ä¸­æ–­ä¸€åˆ†é’Ÿå°±ä¼šæŸå¤±ç™¾ä¸‡ç¾Žåˆ€ï¼Œé‚£ä¹ˆä½ å¯ä»¥è€ƒè™‘ 99.99% çš„å¯é æ€§ã€‚â€ Robertsonï¼ˆLinux é«˜å¯ç”¨é¡¹ç›®å¼€å‘è€…ï¼‰

ä¸åŒç³»ç»Ÿçš„å¯ç”¨æ€§è¦æ±‚ä¹Ÿæ˜¯ä¸åŒçš„ï¼Œæ¯”å¦‚ï¼šæ·˜å®ã€äº¬ä¸œç­‰è¿™äº›ç”µå•†ç³»ç»Ÿç”¨æˆ·é‡å¾ˆå¤šï¼Œä¸åŒåŒºä¸åŒæ—¶åˆ»éƒ½æœ‰å¤§é‡çš„ç”¨æˆ·åœ¨ä½¿ç”¨ç³»ç»Ÿï¼Œè¿™å¿…ç„¶å¯¹ç³»ç»Ÿçš„å¯ç”¨æ€§è¦æ±‚å¾ˆé«˜ã€‚æ®ä»¥å¾€è¿™äº›ç³»ç»Ÿçš„æ•…éšœç»Ÿè®¡å’Œä¸å‡†ç¡®åœ°æµ‹è¯•æ•°æ®æŽ¨æµ‹ï¼Œå®ƒä»¬ç›®å‰çš„å¯ç”¨æ€§æ˜¯åœ¨ 3 ä¸ª 9 åˆ° 4 ä¸ª 9 å·¦å³ã€‚ç›¸å¯¹è€Œè¨€ï¼Œä¼ä¸šç±»çš„å·¥ä½œè½¯ä»¶å› ä¸ºé€šå¸¸åªåœ¨å·¥ä½œæ—¶é—´è¢«ä½¿ç”¨ï¼Œæˆ–åªåœ¨æŸäº›ç‰¹å®šçš„åœ°åŒºä½¿ç”¨ï¼Œæˆ–åªç»™æŸéƒ¨åˆ†äººæŸä¸€ç‰¹å®šæ—¶é—´ä½¿ç”¨ï¼Œå¯ç”¨æ€§çš„éœ€æ±‚å°±ä¼šä½Žä¸€äº›ã€‚å…¸åž‹çš„ç³»ç»Ÿå°±æ•° salesforce äº†ï¼Œç»å¸¸ä¼šçœ‹åˆ° â€œå‘¨æœ«åˆè¦å‡çº§äº†â€ çš„æç¤ºã€‚

å½±å“å¯ç”¨æ€§çš„å› ç´ æœ‰å¾ˆå¤šï¼ŒåŒ…æ‹¬ç³»ç»Ÿæ•…éšœã€åŸºç¡€è®¾æ–½æ•…éšœã€æ•°æ®æ•…éšœã€å®‰å…¨æ”»å‡»ã€ç³»ç»ŸåŽ‹åŠ›ç­‰ç­‰ã€‚

###2. Reliability å¯é æ€§
> Reliability is a measure of the probability that an item will perform its intended function for a specified interval under stated conditions.

å¯é æ€§æ˜¯åœ¨ç»™å®šçš„æ—¶é—´é—´éš”å’Œç»™å®šæ¡ä»¶ä¸‹ï¼Œç³»ç»Ÿå¯ä»¥æ— æ•…éšœæŒç»­è¿è¡Œçš„æ¦‚çŽ‡ã€‚é‚£ä¹ˆå¯é æ€§å’Œå¯ç”¨æ€§æœ‰ä»€ä¹ˆåŒºåˆ«å‘¢ï¼Ÿåœ¨ã€Šåˆ†å¸ƒå¼ç³»ç»ŸåŽŸç†ä¸ŽèŒƒåž‹ã€‹ä¸­æåˆ°çš„ä¸‹é¢ä¾‹å­ä¸­æ¯”è¾ƒå‡†ç¡®çš„è§£é‡Šäº†ä¸¤è€…çš„åŒºåˆ«ï¼š
> å¦‚æžœç³»ç»Ÿåœ¨æ¯å°æ—¶å´©æºƒ 1msï¼Œé‚£ä¹ˆå®ƒçš„å¯ç”¨æ€§å°±è¶…è¿‡ 99.9999%ï¼Œä½†æ˜¯å®ƒè¿˜æ˜¯é«˜åº¦ä¸å¯é ã€‚ä¸Žä¹‹ç±»ä¼¼ï¼Œå¦‚æžœä¸€ä¸ªç³»ç»Ÿä»Žæ¥ä¸å´©æºƒï¼Œä½†æ˜¯æ¯å¹´è¦åœæœºä¸¤æ˜ŸæœŸï¼Œé‚£ä¹ˆå®ƒæ˜¯é«˜åº¦å¯é çš„ï¼Œä½†æ˜¯å¯ç”¨æ€§åªæœ‰ 96%ã€‚

ç®€è€Œè¨€ä¹‹ï¼Œå¯ç”¨æ€§å…³æ³¨çš„æ˜¯ç³»ç»Ÿä»»ä½•æ—¶åˆ»å¯ä»¥æŒç»­æ­£å¸¸å·¥ä½œçš„èƒ½åŠ›ï¼Œå…³æ³¨çš„æ˜¯æœåŠ¡æ€»ä½“çš„æŒç»­æ—¶é—´ã€‚ç³»ç»Ÿåœ¨ç»™å®šæ—¶é—´å†…æ€»ä½“çš„è¿è¡Œæ—¶é—´è¶Šé•¿ï¼Œå¯ç”¨æ€§è¶Šé«˜ã€‚è€Œå¯é æ€§æ›´å…³æ³¨ç³»ç»Ÿå¯ä»¥æ— æ•…éšœåœ°æŒç»­è¿è¡Œçš„æ¦‚çŽ‡ï¼Œå…³æ³¨çš„æ˜¯æ•…éšœçŽ‡ã€‚æ•…éšœçš„é¢‘çŽ‡è¶Šé«˜ï¼Œå¯é æ€§è¶Šä½Žã€‚å¯é æ€§å·®ä¸€å®šç¨‹åº¦ä¸Šæ˜¯ä¼šå½±å“å¯ç”¨æ€§çš„ï¼Œä½†åè¿‡æ¥ä¸ä¸€å®šæˆç«‹ã€‚

è¿™é‡Œé¢è¿˜æœ‰ä¸€äº›å¸¸ç”¨çš„æŒ‡æ ‡æ¥è¡¡é‡å¯ç”¨æ€§å’Œå¯é æ€§ï¼š
* MTBFï¼ˆMean Time Between Failureï¼‰
å³å¹³å‡æ— æ•…éšœæ—¶é—´ï¼Œæ˜¯æŒ‡ä»Žæ–°çš„äº§å“åœ¨è§„å®šçš„å·¥ä½œçŽ¯å¢ƒæ¡ä»¶ä¸‹å¼€å§‹å·¥ä½œåˆ°å‡ºçŽ°ç¬¬ä¸€ä¸ªæ•…éšœçš„æ—¶é—´çš„å¹³å‡å€¼ã€‚MTBF è¶Šé•¿è¡¨ç¤ºå¯é æ€§è¶Šé«˜ï¼Œæ­£ç¡®å·¥ä½œèƒ½åŠ›è¶Šå¼º ã€‚
* MTTRï¼ˆMean Time To Repairï¼‰
å³å¹³å‡ä¿®å¤æ—¶é—´ã€‚æ˜¯æŒ‡å¯ä¿®å¤äº§å“çš„å¹³å‡ä¿®å¤æ—¶é—´ï¼Œå°±æ˜¯ä»Žå‡ºçŽ°æ•…éšœåˆ°ä¿®å¤ä¸­é—´çš„è¿™æ®µæ—¶é—´ã€‚MTTR è¶ŠçŸ­è¡¨ç¤ºæ˜“æ¢å¤æ€§è¶Šå¥½ã€‚
* MTTFï¼ˆMean Time To Failureï¼‰
å³å¹³å‡å¤±æ•ˆæ—¶é—´ã€‚ç³»ç»Ÿå¹³å‡èƒ½å¤Ÿæ­£å¸¸è¿è¡Œå¤šé•¿æ—¶é—´ï¼Œæ‰å‘ç”Ÿä¸€æ¬¡æ•…éšœã€‚ç³»ç»Ÿçš„å¯é æ€§è¶Šé«˜ï¼Œå¹³å‡æ— æ•…éšœæ—¶é—´è¶Šé•¿ã€‚

åŸºäºŽä»¥ä¸ŠæŒ‡æ ‡ï¼Œå¯ç”¨æ€§å¯ä»¥å¦‚æ­¤è®¡ç®—ï¼š
> Availability = UpTime/(UpTime+DownTime) = MTBF / (MTBF + MTTR)

ä½œä¸ºç³»ç»Ÿçš„å“åº”ï¼Œé¦–è¦ç›®æ ‡æ˜¯å…ˆé™ä½Žæ•…éšœçš„æ¬¡æ•°ï¼Œé¢‘çŽ‡è¦ä½Žï¼Œä»Žè€Œæé«˜å¯é æ€§ï¼›åŒæ—¶åœ¨æ•…éšœå‡ºçŽ°åŽï¼Œè¦æé«˜æ•…éšœçš„æ¢å¤æ—¶é—´ï¼Œé€Ÿåº¦è¦å¿«ï¼Œä»Žè€Œæé«˜ä¸šåŠ¡çš„å¯ç”¨æ€§ã€‚

å½±å“å¯é æ€§çš„å› ç´ å°±æ˜¯èƒ½å¤Ÿå¼•èµ·æ•…éšœçš„æ‰€æœ‰å› ç´ ï¼ŒåŒ…æ‹¬è½¯ä»¶è®¾è®¡é”™è¯¯ï¼Œç¼–ç é”™è¯¯ï¼Œç¡¬ä»¶æ•…éšœç­‰ç­‰ã€‚

###3. Stability ç¨³å®šæ€§
> Stability is about how many failures an application exhibits; whether that is manifested as unexpected or unintended behaviour, users receiving errors, or a catastrophic failure that brings a system down. The fewer failures that are observed the more stable an application is.

è½¯ä»¶çš„ç¨³å®šæ€§ï¼ŒæŒ‡è½¯ä»¶åœ¨ä¸€ä¸ªè¿è¡Œå‘¨æœŸå†…ã€åœ¨ä¸€å®šçš„åŽ‹åŠ›æ¡ä»¶ä¸‹ï¼Œåœ¨æŒç»­æ“ä½œæ—¶é—´å†…å‡ºé”™çš„æ¦‚çŽ‡ï¼Œæ€§èƒ½åŠ£åŒ–è¶‹åŠ¿ç­‰ç­‰ã€‚å¦‚æžœä¸€ä¸ªç³»ç»Ÿçš„æ•…éšœçŽ‡å¾ˆé«˜ï¼Œå®ƒä¸€å®šæ˜¯é«˜åº¦ä¸å¯é çš„ï¼Œä¹Ÿä¸€å®šæ˜¯ä¸ç¨³å®šçš„ã€‚é‚£ä¹ˆå¦‚ä½•åŒºåˆ†ç¨³å®šæ€§å’Œå¯é æ€§å‘¢ï¼Ÿ

> å¯¹äºŽç”µåŠ›ç³»ç»Ÿè€Œè¨€ï¼Œç¨³å®šæ€§å°±æ˜¯ â€œäººæ°‘ç”¨ç”µä¸è¦å¿½æ˜Žå¿½æš—å¿½å¿«å¿½æ…¢â€ï¼Œå¯é æ€§å°±æ˜¯â€ ä¸è¦ç”¨ç€ç”¨ç€çªç„¶æ²¡æœ‰å•¦ â€œã€‚- çŸ¥ä¹Žç››å¤ç™½æ—¥æ¢¦

å¦‚æžœä¸€ä¸ªç³»ç»Ÿçš„æ€§èƒ½æ—¶å¥½æ—¶åï¼Œå®ƒä¸€å®šæ˜¯ä¸ç¨³å®šçš„ï¼Œè€Œä¸ä¸€å®šæ˜¯ä¸å¯é çš„ã€‚ç¨³å®šæ€§æ›´å…³æ³¨ç³»ç»Ÿåœ¨ç»™å®šæ¡ä»¶ä¸‹çš„å“åº”æ˜¯å¦ä¸€è‡´ï¼Œè¡Œä¸ºæ˜¯å¦ç¨³å®šã€‚å¯é æ˜¯å¯ç”¨çš„å‰æï¼Œç¨³å®šæ˜¯å¯é çš„è¿›ä¸€æ­¥æå‡ã€‚

ä»Šå¤©åœ¨ Stackoverflow çœ‹åˆ°è¿™æ ·ä¸€æ®µä»£ç æ¥è¡¨ç¤ºè¿™ä¸¤ä¸ªçš„åŒºåˆ«ï¼Œç”šä¸ºæœ‰è¶£ï¼š
```
Reliable but unstable:
  add(a,b):
    if randomInt mod 5 == 0: 
      throw exception
    else
      print a+b        
Stable but unreliable:
  add(a,b):
    if randomInt mod 5 == 0: 
      print a+a
    else
      print a+b
```
ä¸çŸ¥é“å†™åˆ°è¿™é‡Œï¼Œä½ æ˜¯å¦å¯¹å¯ç”¨æ€§ã€å¯é æ€§å’Œç¨³å®šæ€§æœ‰äº†æ›´æ¸…æ™°çš„äº†è§£äº†å‘¢ï¼Ÿæœ‰äº†è¿™äº›æŒ‡æ ‡å¯ä»¥å¸®åŠ©æˆ‘ä»¬åŽ»åˆ†æžç³»ç»Ÿå­˜åœ¨çš„é—®é¢˜ï¼Œæ¯”å¦‚è¯´æ•…éšœé¢‘çŽ‡è¾ƒé«˜ï¼Œæ•…éšœæ¢å¤æ—¶é—´è¾ƒé•¿ï¼Œé‚£ä¹ˆç³»ç»Ÿçš„å¯é æ€§å¯ç”¨æ€§ä¸€å®šå¾ˆä½Žï¼Œå¯¹ç”¨æˆ·çš„å½±å“ä¸€å®šå¾ˆé«˜ï¼Œå°±å¯ä»¥ä¿ƒä½¿æˆ‘ä»¬åŽ»ä»Žå„ä¸ªè§’åº¦åŽ»æ”¹è¿›å’Œæé«˜ï¼ŒåŽ»æ‰¾æž¶æž„è®¾è®¡çš„é—®é¢˜ï¼ŒåŽ»æ‰¾ç³»ç»Ÿå®žçŽ°çš„ç¼ºé™·ï¼ŒåŽ»æ‰¾ä¾èµ–çš„åŸºç¡€è®¾æ–½é—®é¢˜ç­‰ç­‰ï¼Œä»Žè€Œæ”¹å–„æˆ‘ä»¬çš„ç³»ç»Ÿã€‚å°¤å…¶æ˜¯åœ¨å½“ä¸‹å¤æ‚çš„åˆ†å¸ƒå¼ç³»ç»Ÿä¸‹ï¼Œè¿™äº›æ˜¾å¾—å°¤ä¸ºé‡è¦ã€‚

é‚£ä¹ˆï¼Œæœ€åŽè¯·é—®æˆ‘ä»¬å¸¸è§çš„å®¹é”™å¤„ç†ã€è“ç»¿éƒ¨ç½²ã€å›žæ»šã€clusterã€ç¾å¤‡ä¼šæœ‰åŠ©äºŽæé«˜ä»¥ä¸Šå“ªä¸ª ability å‘¢ï¼Ÿ