# 第ä¸ç« ï¼å¯é æ§ãå¯ä¼¸ç¸®æ§åå¯ç¶è·æ§ ![](../img/ch1.png) > 網é網路åå¾å¤ªæ£äºï¼ä»¥è³æ¼å¤§å¤æ¸äººå°å®çä½å太平æ´é樣çèªç¶è³æºï¼èä¸æ¯ä»éº¼äººå·¥ç¢ç©ãä¸ä¸æ¬¡åºç¾é種大è¦æ¨¡ä¸ç¡å·®é¯çæè¡ï¼ä½ éè¨å¾æ¯ä»éº¼æååï¼ > > ââ [è¾å«ã»å±](http://www.drdobbs.com/architecture-and-design/interview-with-alan-kay/240003442) å¨æ¥å Dobb å士éèªæ¡è¨ªæ說ï¼2012 å¹´ï¼ ----------------------- [TOC] ç¾ä»å¾å¤æç¨ç¨å¼é½æ¯ **è³æå¯éåï¼data-intensiveï¼** çï¼èé **è¨ç®å¯éåï¼compute-intensiveï¼** çãå æ¤ CPU å¾å°æçºéé¡æç¨çç¶é ¸ï¼æ´å¤§çåé¡é常ä¾èªè³æéãè³æè¤éæ§ã以åè³æçè®æ´é度ã è³æå¯éåæç¨é常ç±æ¨æºçµä»¶æ§å»ºèæï¼æ¨æºçµä»¶æä¾äºå¾å¤éç¨çåè½ï¼ä¾å¦ï¼è¨±å¤æç¨ç¨å¼é½éè¦ï¼ - å²åè³æï¼ä»¥ä¾¿èªå·±æå ¶ä»æç¨ç¨å¼ä¹å¾è½å次æ¾å° ï¼*è³æ庫ï¼å³ databases*ï¼ - è¨ä½éé·æè²´æä½ççµæï¼å å¿«è®åé度ï¼*å¿«åï¼å³ caches*ï¼ - å 許使ç¨è æééµåæå°è³æï¼æ以å種æ¹å¼å°è³æé²è¡é濾ï¼*æå°ç´¢å¼ï¼å³ search indexes*ï¼ - åå ¶ä»ç¨åºå³éè¨æ¯ï¼é²è¡éåæ¥èçï¼*æµèçï¼å³ stream processing*ï¼ - å®æèçç´¯ç©ç大æ¹æ¬¡è³æï¼*æ¹èçï¼å³ batch processing*ï¼ å¦æéäºåè½è½ä¸å»å¹³æ·¡ç¡å¥ï¼é£æ¯å çºéäº **è³æ系統ï¼data systemï¼** æ¯é常æåçæ½è±¡ï¼æåä¸ç´ä¸åæç´¢å°ä½¿ç¨å®å並ç¿ä»¥çºå¸¸ãçµå¤§å¤æ¸å·¥ç¨å¸«ä¸æå¹»æ³å¾é¶éå§ç·¨å¯«å²åå¼æï¼å çºå¨éç¼æç¨æï¼è³æ庫已ç¶æ¯è¶³å¤ å®ç¾çå·¥å ·äºã ä½ç¾å¯¦æ²æé麼簡å®ãä¸åçæç¨æèä¸åçéæ±ï¼å èè³æ庫系統ä¹æ¯ç¾è±é½æ¾ï¼æèåå¼å樣çç¹æ§ã實ç¾å¿«åæå¾å¤ç¨®æ段ï¼å»ºç«æå°ç´¢å¼ä¹æ好幾種æ¹æ³ï¼è«¸å¦æ¤é¡ãå æ¤å¨éç¼æç¨åï¼æåä¾ç¶æå¿ è¦å å¼æ¸ æ¥æé©åæé å·¥ä½çå·¥å ·åæ¹æ³ãèä¸ç¶å®åå·¥å ·è§£æ±ºä¸äºä½ çåé¡æï¼çµå使ç¨éäºå·¥å ·å¯è½éæ¯æäºé£åº¦çã æ¬æ¸å°æ¯ä¸è¶éæ¼è³æ系統åçã實è¸èæç¨çæ ç¨ï¼ä¸¦è¬è¿°äºè¨è¨è³æå¯éåæç¨çæ¹æ³ãæåå°æ¢ç´¢ä¸åå·¥å ·ä¹éçå ±æ§èç¹æ§ï¼ä»¥ååèªç實ç¾åçã æ¬ç« å°å¾æåæè¦å¯¦ç¾çåºç¤ç®æ¨éå§ï¼å¯é ãå¯ä¼¸ç¸®ãå¯ç¶è·çè³æ系統ãæåå°æ¾æ¸ éäºè©èªçå«ç¾©ï¼æ¦è¿°èééäºç®æ¨çæ¹æ³ã並å顧ä¸äºå¾çºç« ç¯æéçåºç¤ç¥èãå¨æ¥ä¸ä¾çç« ç¯ä¸æåå°æ½çµ²åç¹ï¼ç 究è¨è¨è³æå¯éåæç¨æå¯è½éå°çè¨è¨æ±ºçã ## éæ¼è³æ系統çæè æåé常èªçºï¼è³æ庫ãè¨æ¯ä½åãå¿«åçå·¥å ·å屬æ¼å¹¾åå·®ç°é¡¯èçé¡å¥ãéç¶è³æ庫åè¨æ¯éå表é¢ä¸æä¸äºç¸ä¼¼æ§ ââ å®åé½æå²åä¸æ®µæéçè³æ ââ ä½å®åæè¿¥ç¶ä¸åç訪å模å¼ï¼éæå³èè¿¥ç°çæè½ç¹å¾µå實ç¾æ段ã é£æåçºä»éº¼è¦æéäºæ±è¥¿æ¾å¨ **è³æ系統ï¼data systemï¼** ç總稱ä¹ä¸æ··çºä¸è«å¢ï¼ è¿äºå¹´ä¾ï¼åºç¾äºè¨±å¤æ°çè³æå²åå·¥å ·èè³æèçå·¥å ·ãå®åéå°ä¸åæç¨å ´æ¯é²è¡æä½³åï¼å æ¤ä¸åé©åç硬å°æ¸å ¥å³çµ±é¡å¥ã1ããé¡å¥ä¹éççéè®å¾è¶ä¾è¶æ¨¡ç³ï¼ä¾å¦ï¼è³æå²åå¯ä»¥è¢«ç¶æè¨æ¯ä½åç¨ï¼Redisï¼ï¼è¨æ¯ä½åå帶æé¡ä¼¼è³æ庫çæä¹ ä¿èï¼Apache Kafkaï¼ã å ¶æ¬¡ï¼è¶ä¾è¶å¤çæç¨ç¨å¼æèå種å´æ ¼è廣æ³çè¦æ±ï¼å®åå·¥å ·ä¸è¶³ä»¥æ»¿è¶³ææçè³æèçåå²åéæ±ãåè代ä¹çæ¯ï¼ç¸½é«å·¥ä½è¢«æåæä¸ç³»åè½è¢«å®åå·¥å ·é«æå®æçä»»åï¼ä¸¦ééæç¨ç¨å¼ç¢¼å°å®å縫åèµ·ä¾ã ä¾å¦ï¼å¦æå°å¿«åï¼æç¨ç®¡ççå¿«å層ï¼Memcached æåé¡ç¢åï¼åå ¨ææå°ï¼å ¨ææå°ä¼ºæå¨ï¼ä¾å¦ Elasticsearch æ Solrï¼åè½å¾ä¸»è³æ庫åé¢åºä¾ï¼é£éº¼ä½¿å¿«å / ç´¢å¼è主è³æ庫ä¿æåæ¥é常æ¯æç¨ç¨å¼ç¢¼ç責任ã[å 1-1](../img/fig1-1.png) 給åºäºé種æ¶æ§å¯è½ç樣åï¼ç´°ç¯å°å¨å¾é¢çç« ç¯ä¸è©³ç´°ä»ç´¹ï¼ã ![](../img/fig1-1.png) **å 1-1 ä¸åå¯è½ççµå使ç¨å¤åå 件çè³æ系統æ¶æ§** ç¶ä½ å°å¤åå·¥å ·çµåå¨ä¸èµ·æä¾æåæï¼æåçä»é¢æ **æç¨ç¨å¼ç¨å¼è¨è¨ä»é¢ï¼API, Application Programming Interfaceï¼** é常å客æ¶ç«¯é±èéäºå¯¦ç¾ç´°ç¯ãç¾å¨ï¼ä½ åºæ¬ä¸å·²ç¶ä½¿ç¨è¼å°çéç¨å 件建ç«äºä¸åå ¨æ°çãå°ç¨çè³æ系統ãéåæ°çè¤åè³æ系統å¯è½ææä¾ç¹å®çä¿èï¼ä¾å¦ï¼å¿«åå¨å¯«å ¥ææä½å»¢ææ´æ°ï¼ä»¥ä¾¿å¤é¨å®¢æ¶ç«¯ç²åä¸è´ççµæãç¾å¨ä½ ä¸å æ¯æç¨ç¨å¼éç¼äººå¡ï¼éæ¯è³æ系統è¨è¨äººå¡äºã è¨è¨è³æ系統ææåæå¯è½æéå°å¾å¤æ£æçåé¡ï¼ä¾å¦ï¼ç¶ç³»çµ±åºåé¡æï¼å¦ä½ç¢ºä¿è³æçæ£ç¢ºæ§åå®æ´æ§ï¼ç¶é¨å系統éåéç´æï¼å¦ä½çºå®¢æ¶æä¾å§çµå¦ä¸çè¯å¥½æè½ï¼ç¶è² è¼å¢å æï¼å¦ä½æ´å®¹æå°ï¼ä»éº¼æ¨£ç API ææ¯å¥½ç APIï¼ å½±é¿è³æ系統è¨è¨çå ç´ å¾å¤ï¼å æ¬åè人å¡çæè½åç¶é©ãæ·å²éºçåé¡ã系統路å¾ä¾è³´ã交ä»æéãå ¬å¸ç風éªå®¹å¿åº¦ãç£ç®¡ç´æçï¼éäºå ç´ é½éè¦å ·é«åé¡å ·é«åæã æ¬æ¸èéè¨è«ä¸åå¨å¤§å¤æ¸è»é«ç³»çµ±ä¸é½å¾éè¦çåé¡ï¼ * å¯é æ§ï¼Reliabilityï¼ ç³»çµ±å¨ **å°å¢**ï¼adversityï¼æ¯å¦ç¡¬é«æ éãè»é«æ éã人çºé¯èª¤ï¼ä¸ä»å¯æ£å¸¸å·¥ä½ï¼æ£ç¢ºå®æåè½ï¼ä¸¦è½éå°ææçæè½æ°´æºï¼ãè«åé± â[å¯é æ§](#å¯é æ§)âã * å¯ä¼¸ç¸®æ§ï¼Scalabilityï¼ æåçç辦æ³æå°ç³»çµ±çå¢é·ï¼è³æéãæµéãè¤éæ§ï¼ãè«åé± â[å¯ä¼¸ç¸®æ§](#å¯ä¼¸ç¸®æ§)âã * å¯ç¶è·æ§ï¼Maintainabilityï¼ è¨±å¤ä¸åç人ï¼å·¥ç¨å¸«ãéç¶ï¼å¨ä¸åççå½é±æï¼é½è½é«æå°å¨ç³»çµ±ä¸å·¥ä½ï¼ä½¿ç³»çµ±ä¿æç¾æè¡çºï¼ä¸¦é©ææ°çæç¨å ´æ¯ï¼ãè«åé± â[å¯ç¶è·æ§](#å¯ç¶è·æ§)âã 人åç¶å¸¸è¿½æ±éäºè©å½ï¼å»æ²ææ¸ æ¥ç解å®åå°åºæå³èä»éº¼ãçºäºå·¥ç¨çå´è¬¹æ§ï¼æ¬ç« çå©é¤é¨åå°æ¢è¨å¯é æ§ãå¯ä¼¸ç¸®æ§åå¯ç¶è·æ§çå«ç¾©ãçºå¯¦ç¾éäºç®æ¨è使ç¨çå種æè¡ï¼æ¶æ§åæ¼ç®æ³å°å¨å¾çºçç« ç¯ä¸ç 究ã ## å¯é æ§ äººåå°æ¼ä¸åæ±è¥¿æ¯å¦å¯é ï¼é½æä¸åç´è§çæ³æ³ã人åå°å¯é è»é«çå ¸åææå æ¬ï¼ * æç¨ç¨å¼è¡¨ç¾åºä½¿ç¨è æææçåè½ã * å 許使ç¨è ç¯é¯ï¼å 許使ç¨è 以åºä¹ææçæ¹å¼ä½¿ç¨è»é«ã * å¨é æçè² è¼åè³æéä¸ï¼æè½æ»¿è¶³è¦æ±ã * 系統è½é²æ¢æªç¶ææ¬ç訪ååæ¿«ç¨ã å¦æææéäºå¨ä¸èµ·æå³è âæ£ç¢ºå·¥ä½âï¼é£éº¼å¯ä»¥æå¯é æ§ç²ç¥çè§£çº âå³ä½¿åºç¾åé¡ï¼ä¹è½ç¹¼çºæ£ç¢ºå·¥ä½âã é æé¯èª¤çåå å«å **æ éï¼faultï¼**ï¼è½é æ並æå°æ éç系統ç¹æ§å¯ç¨±çº **容é¯ï¼fault-tolerantï¼** æ **åå½æ§ï¼resilientï¼**ãâ**容é¯**â ä¸è©å¯è½æç¢ç誤å°ï¼å çºå®æ示è系統å¯ä»¥å®¹å¿ææå¯è½çé¯èª¤ï¼ä½å¨å¯¦éä¸éæ¯ä¸å¯è½çãæ¯æ¹èªªï¼å¦ææ´åå°çï¼åå ¶ä¸çææ伺æå¨ï¼é½è¢«é»æ´åå¬äºï¼æ³è¦å®¹å¿é種é¯èª¤ï¼éè¦æ網路è¨ç®¡å°å¤ªç©ºä¸ ââ é種é ç®è½ä¸è½æ¹åå°±ç¥ä½ 好éäºãæ以å¨è¨è«å®¹é¯æï¼åªæè«è«ç¹å®åå¥çé¯èª¤æææ義ã 注æ **æ éï¼faultï¼** ä¸åæ¼ **失æï¼failureï¼**ã2ãã**æ é** é常å®ç¾©çºç³»çµ±çä¸é¨åçæ åé¢å ¶æ¨æºï¼è **失æ** åæ¯ç³»çµ±ä½çºä¸åæ´é«åæ¢åç¨æ¶æä¾æåãæ éçæ©çä¸å¯è½éå°é¶ï¼å æ¤æ好è¨è¨å®¹é¯æ©å¶ä»¥é²å **æ é** èå°è´ **失æ**ãæ¬æ¸ä¸æåå°ä»ç´¹å¹¾ç¨®ç¨ä¸å¯é çé¨ä»¶æ§å»ºå¯é 系統çæè¡ã åç´è¦ºçæ¯ï¼å¨éé¡å®¹é¯ç³»çµ±ä¸ï¼ééæ æ觸ç¼ä¾ **æé«** æ éçæ¯ææ義çï¼ä¾å¦ï¼å¨æ²æè¦åçæ æ³ä¸é¨æ©å°æ®ºæ»å®åç¨åºã許å¤é«å±æ¼æ´å¯¦éä¸æ¯ç±ç³ç³çé¯èª¤èçå°è´çã3ãï¼å æ¤æåå¯ä»¥ééæ æå¼ç¼æ éä¾ç¢ºä¿å®¹é¯æ©å¶ä¸æ·å·è¡ä¸¦æ¥åèé©ï¼å¾èæé«æ éèªç¶ç¼çæ系統è½æ£ç¢ºèççä¿¡å¿ãNetflix å ¬å¸ç *Chaos Monkey*ã4ãå°±æ¯é種æ¹æ³çä¸åä¾åã å管æ¯èµ· **é»æ¢é¯èª¤ï¼prevent errorï¼**ï¼æåé常æ´å¾åæ¼ **容å¿é¯èª¤**ãä½ä¹æ **é é²åæ¼æ²»ç** çæ æ³ï¼æ¯å¦ä¸åå¨æ²»çæ¹æ³æï¼ãå®å ¨åé¡å°±å±¬æ¼é種æ æ³ãä¾å¦ï¼å¦ææ»æè ç ´å£äºç³»çµ±ï¼ä¸¦ç²åäºææè³æï¼é種äºæ¯æ¤é·ä¸äºçãä½æ¬æ¸ä¸»è¦è¨è«çæ¯å¯ä»¥æ¢å¾©çæ é種é¡ï¼æ£å¦ä¸é¢å¹¾ç¯æè¿°ã ### 硬é«æ é ç¶æ³å°ç³»çµ±å¤±æçåå æï¼**硬é«æ éï¼hardware faultsï¼** 總æ第ä¸åé²å ¥è ¦æµ·ã硬ç¢å´©æ½°ãè¨æ¶é«åºé¯ãæ©æ¿æ·é»ãæ人æé¯ç¶²ç·â¦â¦ ä»»ä½è大åè³æä¸å¿æé交éç人é½æåè¨´ä½ ï¼ä¸æ¦ä½ ææå¾å¤æ©å¨ï¼éäºäºæ **總** æç¼çï¼ æå ±é稱ï¼ç¡¬ç¢ç **å¹³åç¡æ éæéï¼MTTF, mean time to failureï¼** ç´çº 10 å° 50 å¹´ã5ãã6ããå æ¤å¾æ¸å¸ææä¸è¬ï¼å¨ææ 10000 åç£ç¢çå²åå¢éä¸ï¼å¹³åæ¯å¤©ææ 1 åç£ç¢åºæ éã çºäºæ¸å°ç³»çµ±çæ éçï¼ç¬¬ä¸åæé常é½æ¯å¢å å®å硬é«çåé¤åº¦ï¼ä¾å¦ï¼ç£ç¢å¯ä»¥çµå»º RAIDï¼ä¼ºæå¨å¯è½æéè·¯é»æºåç±ææ CPUï¼è³æä¸å¿å¯è½æé»æ± åæ´æ²¹ç¼é»æ©ä½çºå¾åé»æºï¼æåå 件æææåé¤å 件å¯ä»¥ç«å»æ¥ç®¡ãé種æ¹æ³éç¶ä¸è½å®å ¨é²æ¢ç±ç¡¬é«åé¡å°è´ç系統失æï¼ä½å®ç°¡å®ææï¼é常ä¹è¶³ä»¥è®æ©å¨ä¸éæ·å·è¡å¾å¤å¹´ã ç´å°æè¿ï¼ç¡¬é«åé¤å°æ¼å¤§å¤æ¸æç¨ä¾èªªå·²ç¶è¶³å¤ äºï¼å®ä½¿å®èºæ©å¨å®å ¨å¤±æè®å¾ç¸ç¶ç½è¦ãåªè¦ä½ è½å¿«éå°æå份æ¢å¾©å°æ°æ©å¨ä¸ï¼æ éåæ©æéå°å¤§å¤æ¸æç¨èè¨é½ç®ä¸ä¸ç½é£æ§çãåªæå°éé«å¯ç¨æ§è³ééè¦çæç¨ææè¦æ±æå¤å¥ç¡¬é«åé¤ã ä½æ¯é¨èè³æéåæç¨è¨ç®éæ±çå¢å ï¼è¶ä¾è¶å¤çæç¨éå§å¤§é使ç¨æ©å¨ï¼éæç¸æå°å¢å 硬é«æ éçãæ¤å¤ï¼å¨é¡ä¼¼äºé¦¬é AWSï¼Amazon Web Servicesï¼çä¸äºé²æåå¹³èºä¸ï¼èæ¬æ©å¨ä¾é ä¸å¯ç¨å»æ²æä»»ä½è¦åä¹æ¯å¾å¸¸è¦çã7ãï¼å çºé²å¹³èºçè¨è¨å°±æ¯åªå èæ ® **éæ´»æ§ï¼flexibilityï¼** å **å½æ§ï¼elasticityï¼**[^i]ï¼èä¸æ¯å®æ©å¯é æ§ã å¦æå¨ç¡¬é«åé¤çåºç¤ä¸é²ä¸æ¥å¼å ¥è»é«å®¹é¯æ©å¶ï¼é£éº¼ç³»çµ±å¨å®¹å¿æ´åï¼å®èºï¼æ©å¨æ éçéè·¯ä¸å°±æ´é²ä¸æ¥äºãé樣ç系統ä¹æéç¶ä¸ç便å©ï¼ä¾å¦ï¼å¦æéè¦éåæ©å¨ï¼ä¾å¦æç¨ä½æ¥ç³»çµ±å®å ¨è£ä¸ï¼ï¼å®ä¼ºæå¨ç³»çµ±å°±éè¦è¨ååæ©ãèå 許æ©å¨å¤±æç系統åå¯ä»¥ä¸æ¬¡ä¿®å¾©ä¸åç¯é»ï¼ç¡éæ´å系統åæ©ã [^i]: å¨ [æå°è² è¼çæ¹æ³](#æå°è² è¼çæ¹æ³) ä¸ç¯å®ç¾© ### è»é«é¯èª¤ æåé常èªçºç¡¬é«æ éæ¯é¨æ©çãç¸äºç¨ç«çï¼ä¸èºæ©å¨çç£ç¢å¤±æ並ä¸æå³èå¦ä¸èºæ©å¨çç£ç¢ä¹æ失æãéç¶å¤§é硬é«å 件ä¹éå¯è½åå¨å¾®å¼±çç¸éæ§ï¼ä¾å¦ä¼ºæå¨æ©æ¶ç溫度çå ±åçåå ï¼ï¼ä½åæç¼çæ éä¹æ¯æ¥µçºç½è¦çã å¦ä¸é¡é¯èª¤æ¯å §é¨ç **系統æ§é¯èª¤ï¼systematic errorï¼**ã8ããéé¡é¯èª¤é£ä»¥é æï¼èä¸å çºæ¯è·¨ç¯é»ç¸éçï¼æ以æ¯èµ·ä¸ç¸éç硬é«æ éå¾å¾å¯è½é ææ´å¤ç **系統失æ**ã5ããä¾åå æ¬ï¼ * æ¥åç¹å®çé¯èª¤è¼¸å ¥ï¼ä¾¿å°è´æææç¨ä¼ºæå¨ä¾é å´©æ½°ç BUGãä¾å¦ 2012 å¹´ 6 æ 30 æ¥çéç§ï¼ç±æ¼ Linux æ ¸å¿ä¸çä¸åé¯èª¤ã9ãï¼è¨±å¤æç¨åæææäºã * 失æ§ç¨åºæç¨ç¡ä¸äºå ±äº«è³æºï¼å æ¬ CPU æéãè¨æ¶é«ãç£ç¢ç©ºéæç¶²è·¯é »å¯¬ã * 系統ä¾è³´çæåè®æ ¢ï¼æ²æé¿æï¼æè éå§è¿åé¯èª¤çé¿æã * ç´è¯æ éï¼ä¸åå 件ä¸çå°æ é觸ç¼å¦ä¸åå 件ä¸çæ éï¼é²è觸ç¼æ´å¤çæ éã10ãã å°è´éé¡è»é«æ éç BUG é常ææ½ä¼å¾é·æéï¼ç´å°è¢«ç°å¸¸æ æ³è§¸ç¼çºæ¢ãé種æ æ³æå³èè»é«å°å ¶ç°å¢ååºäºæ種åè¨ ââ éç¶é種åè¨é常ä¾èªªæ¯æ£ç¢ºçï¼ä½ç±æ¼æ種åå æå¾ä¸åæç«äºã11ãã éç¶è»é«ä¸ç系統æ§æ éæ²æéæè¥ï¼ä½æåéæ¯æå¾å¤å°è¾¦æ³ï¼ä¾å¦ï¼ä»ç´°èæ ®ç³»çµ±ä¸çåè¨åäºåï¼å¾¹åºç測試ï¼ç¨åºéé¢ï¼å 許ç¨åºå´©æ½°ä¸¦éåï¼æ¸¬éãç£æ§ä¸¦åæçç¢ç°å¢ä¸ç系統è¡çºãå¦æ系統è½å¤ æä¾ä¸äºä¿èï¼ä¾å¦å¨ä¸åè¨æ¯ä½åä¸ï¼é²å ¥èç¼åºçè¨æ¯æ¸éç¸çï¼ï¼é£éº¼ç³»çµ±å°±å¯ä»¥å¨å·è¡æä¸æ·èªæª¢ï¼ä¸¦å¨åºç¾ **å·®ç°ï¼discrepancyï¼** æå ±è¦ã12ãã ### 人çºé¯èª¤ è¨è¨ä¸¦æ§å»ºäºè»é«ç³»çµ±çå·¥ç¨å¸«æ¯äººé¡ï¼ç¶æ系統å·è¡çéç¶ä¹æ¯äººé¡ãå³ä½¿ä»åæ·ææ大çåæï¼äººé¡ä¹æ¯ä¸å¯é çãèåä¾åï¼ä¸é éæ¼å¤§å網é網路æåçç 究ç¼ç¾ï¼éç¶é ç½®é¯èª¤æ¯å°è´æåä¸æ·çé¦è¦åå ï¼è硬é«æ éï¼ä¼ºæå¨æ網路ï¼å å°è´äº 10-25% çæåä¸æ·ã13ãã å管人é¡ä¸å¯é ï¼ä½æ麼åæè½è®ç³»çµ±è®å¾å¯é ï¼æ好ç系統æçµå使ç¨ä»¥ä¸å¹¾ç¨®è¾¦æ³ï¼ * 以æå°åç¯é¯æ©æçæ¹å¼è¨è¨ç³»çµ±ãä¾å¦ï¼ç²¾å¿è¨è¨çæ½è±¡ãAPI å管çå¾èºä½¿åå°äºæ æ´å®¹æï¼æç ¸äºæ æ´å°é£ãä½å¦æä»é¢éå¶å¤ªå¤ï¼äººåå°±æ忽ç¥å®åç好èèæ³è¾¦æ³ç¹éãå¾é£æ£ç¢ºææ¡é種微å¦ç平衡ã * å°äººåæ容æç¯é¯çå°æ¹èå¯è½å°è´å¤±æçå°æ¹ **解è¦ï¼decoupleï¼**ãç¹å¥æ¯æä¾ä¸ååè½é½å ¨çéçç¢ç°å¢ **æ²ç®±ï¼sandboxï¼**ï¼ä½¿äººåå¯ä»¥å¨ä¸å½±é¿ç實使ç¨è çæ æ³ä¸ï¼ä½¿ç¨ç實è³æå®å ¨å°æ¢ç´¢å實é©ã * å¨åå層次é²è¡å¾¹åºç測試ã3ãï¼å¾å®å 測試ãå ¨ç³»çµ±æ´å測試å°æå測試ãèªåå測試ææ¼ç解ï¼å·²ç¶è¢«å»£æ³ä½¿ç¨ï¼ç¹å¥é©åç¨ä¾è¦èæ£å¸¸æ æ³ä¸å°è¦ç **éç·£å ´æ¯ï¼corner caseï¼**ã * å 許å¾äººçºé¯èª¤ä¸ç°¡å®å¿«éå°æ¢å¾©ï¼ä»¥æ大é度å°æ¸å°å¤±ææ æ³å¸¶ä¾çå½±é¿ãä¾å¦ï¼å¿«éå滾é ç½®è®æ´ï¼åæ¹ç¼å¸æ°ç¨å¼ç¢¼ï¼ä»¥ä¾¿ä»»ä½æå¤é¯èª¤é»å½±é¿ä¸å°é¨å使ç¨è ï¼ï¼ä¸¦æä¾è³æéç®å·¥å ·ï¼ä»¥åèçè¨ç®åºé¯ï¼ã * é 置詳細åæ確çç£æ§ï¼æ¯å¦æè½ææ¨åé¯èª¤çãå¨å ¶ä»å·¥ç¨å¸ç§ä¸éæçæ¯ **é測ï¼telemetryï¼**ï¼ä¸æ¦ç«ç®é¢éäºå°é¢ï¼é測æè¡å°æ¼è·è¹¤ç¼ççäºæ åç解失ææ¯è³ééè¦çï¼ãç£æ§å¯ä»¥åæåç¼åºé è¦è¨èï¼ä¸¦å 許æå檢æ¥æ¯å¦æä»»ä½å°æ¹éåäºåè¨åç´æãç¶åºç¾åé¡æï¼ææ¨è³æå°æ¼åé¡è¨ºæ·æ¯é常寶貴çã * è¯å¥½ç管ç實è¸èå åçå¹è¨ ââ ä¸åè¤éèéè¦çæ¹é¢ï¼ä½è¶ åºäºæ¬æ¸çç¯åã ### å¯é æ§æå¤éè¦ï¼ å¯é æ§ä¸å å æ¯éå°æ ¸é»ç«å空ä¸äº¤é管å¶è»é«èè¨ï¼æåä¹æææ´å¤å¹³å¡çæç¨è½å¯é å°å·è¡ãååæç¨ä¸çé¯èª¤æå°è´çç¢åæ失ï¼ä¹è¨±è³æå ±åä¸å®æ´éæææ³å¾é¢¨éªï¼ï¼èé»å網ç«çä¸æ·åå¯è½æå°è´æ¶å ¥åè²è½ç巨大æ失ã å³ä½¿å¨ âéééµâ æç¨ä¸ï¼æåä¹å°ä½¿ç¨è è² æ責任ã試æ³ä¸ä½å®¶é·æææçç §çåå©åçå½±çå²åå¨ä½ çç §çæç¨è£¡ã15ããå¦æè³æ庫çªç¶æå£ï¼ä»åææ覺å¦ä½ï¼ä»åå¯è½æç¥éå¦ä½å¾å份æ¢å¾©åï¼ å¨æäºæ æ³ä¸ï¼æåå¯è½æé¸æç§ç²å¯é æ§ä¾éä½éç¼ææ¬ï¼ä¾å¦çºæªç¶è實çå¸å ´éç¼ç¢åååï¼æéçææ¬ï¼ä¾å¦å©æ½¤ç極ä½çæåï¼ï¼ä½æåå·å·¥æ¸ææï¼æè©²æ¸ æ¥æèå°èªå·±å¨åä»éº¼ã ## å¯ä¼¸ç¸®æ§ 系統ä»å¤©è½å¯é å·è¡ï¼ä¸¦ä¸æå³æªä¾ä¹è½å¯é å·è¡ãæå **éç´ï¼degradationï¼** çä¸å常è¦åå æ¯è² è¼å¢å ï¼ä¾å¦ï¼ç³»çµ±è² è¼å·²ç¶å¾ä¸è¬åä½µç¼ä½¿ç¨è å¢é·å°åè¬åä½µç¼ä½¿ç¨è ï¼æè å¾ä¸ç¾è¬å¢é·å°ä¸åè¬ãä¹è¨±ç¾å¨èççè³æéç´è¦æ¯éå»å¤§å¾å¤ã **å¯ä¼¸ç¸®æ§ï¼Scalabilityï¼** æ¯ç¨ä¾æ述系統æå°è² è¼å¢é·è½åçè¡èªãä½æ¯è«æ³¨æï¼éä¸æ¯è²¼å¨ç³»çµ±ä¸çä¸ç¶æ¨ç±¤ï¼èªª âX å¯ä¼¸ç¸®â æ âY ä¸å¯ä¼¸ç¸®â æ¯æ²æä»»ä½æ義çãç¸åï¼è¨è«å¯ä¼¸ç¸®æ§æå³èèæ ®è«¸å¦ âå¦æ系統以ç¹å®æ¹å¼å¢é·ï¼æä»éº¼é¸é å¯ä»¥æå°å¢é·ï¼â å âå¦ä½å¢å è¨ç®è³æºä¾èçé¡å¤çè² è¼ï¼â çåé¡ã ### æè¿°è² è¼ å¨è¨è«å¢é·åé¡ï¼å¦æè² è¼å åæç¼çä»éº¼ï¼ï¼åï¼é¦å è¦è½ç°¡è¦æ述系統çç¶åè² è¼ãè² è¼å¯ä»¥ç¨ä¸äºç¨±çº **è² è¼å¼æ¸ï¼load parametersï¼** çæ¸åä¾æè¿°ãå¼æ¸çæä½³é¸æå決æ¼ç³»çµ±æ¶æ§ï¼å®å¯è½æ¯æ¯ç§å Web 伺æå¨ç¼åºçè«æ±ãè³æ庫ä¸çè®å¯«æ¯çãè天室ä¸åææ´»èºç使ç¨è æ¸éãå¿«åå½ä¸çæå ¶ä»æ±è¥¿ãé¤æ¤ä¹å¤ï¼ä¹è¨±å¹³åæ æ³å°ä½ å¾éè¦ï¼ä¹è¨±ä½ çç¶é ¸æ¯å°æ¸æ¥µç«¯å ´æ¯ã çºäºä½¿éåæ¦å¿µæ´å å ·é«ï¼æå以æ¨ç¹å¨ 2012 å¹´ 11 æéåºçè³æã16ãçºä¾ãæ¨ç¹çå ©å主è¦æ¥åæ¯ï¼ * éåºæ¨æ 使ç¨è å¯ä»¥åå ¶ç²çµ²éåºæ°è¨æ¯ï¼å¹³å 4.6k è«æ± / ç§ï¼å³°å¼è¶ é 12k è«æ± / ç§ï¼ã * 主é æéç· ä½¿ç¨è å¯ä»¥æ¥é±ä»åé注ç人éåºçæ¨æï¼300k è«æ± / ç§ï¼ã èçæ¯ç§ 12,000 æ¬¡å¯«å ¥ï¼ç¼æ¨æçéçå³°å¼ï¼éæ¯å¾ç°¡å®çãç¶èæ¨ç¹ç伸縮æ§ææ°ä¸¦ä¸æ¯ä¸»è¦ä¾èªæ¨ç¹éï¼èæ¯ä¾èª **æåºï¼fan-outï¼**[^ii]ââ æ¯å使ç¨è é注äºå¾å¤äººï¼ä¹è¢«å¾å¤äººé注ã [^ii]: æåºï¼å¾é»åå·¥ç¨å¸ä¸åç¨çè¡èªï¼å®æè¿°äºè¼¸å ¥é£ç·å°å¦ä¸åé輸åºçé輯éæ¸éã輸åºéè¦æä¾è¶³å¤ çé»æµä¾é© åææé£ç·çè¼¸å ¥ãå¨äºåèç系統ä¸ï¼æå使ç¨å®ä¾æè¿°çºäºæåä¸åå³å ¥è«æ±èéè¦å·è¡å ¶ä»æåçè«æ±æ¸éã 大é«ä¸è¬ï¼éä¸å°æä½æå ©ç¨®å¯¦ç¾æ¹å¼ã 1. éåºæ¨ææï¼åªéå°æ°æ¨ææå ¥å ¨åæ§æ¨æéåå³å¯ãç¶ä¸å使ç¨è è«æ±èªå·±ç主é æéç·æï¼é¦å æ¥è©¢ä»é注çææ人ï¼æ¥è©¢éäºè¢«é注使ç¨è éåºçæ¨æ並ææéé åºåä½µãå¨å¦ [å 1-2](../img/fig1-2.png) æ示çéä¿åè³æ庫ä¸ï¼å¯ä»¥ç·¨å¯«é樣çæ¥è©¢ï¼ ```sql SELECT tweets.*, users.* FROM tweets JOIN users ON tweets.sender_id = users.id JOIN follows ON follows.followee_id = users.id WHERE follows.follower_id = current_user ``` ![](../img/fig1-2.png) **å 1-2 æ¨ç¹ä¸»é æéç·çéä¿å模å¼ç°¡å®å¯¦ç¾** 2. çºæ¯å使ç¨è ç主é æéç·ç¶è·ä¸åå¿«åï¼å°±åæ¯å使ç¨è çæ¨ææ¶ä»¶ç®±ï¼[å 1-3](../img/fig1-3.png)ï¼ãç¶ä¸å使ç¨è éåºæ¨ææï¼æ¥è©¢ææé注該使ç¨è ç人ï¼ä¸¦å°æ°çæ¨ææå ¥å°æ¯å主é æéç·å¿«åä¸ãå æ¤è®å主é æéç·çè«æ±éé·å¾å°ï¼å çºçµæå·²ç¶æåè¨ç®å¥½äºã ![](../img/fig1-3.png) **å 1-3 ç¨æ¼åç¼æ¨ç¹è³é注è çè³ææµæ°´ç·ï¼2012 å¹´ 11 æçè² è¼å¼æ¸ã16ã** æ¨ç¹ç第ä¸åçæ¬ä½¿ç¨äºæ¹æ³ 1ï¼ä½ç³»çµ±å¾é£è·ä¸ä¸»é æéç·æ¥è©¢çè² è¼ãæä»¥å ¬å¸è½åäºæ¹æ³ 2ï¼æ¹æ³ 2 çæææ´å¥½ï¼å çºç¼æ¨é »çæ¯æ¥è©¢ä¸»é æéç·çé »çå¹¾ä¹ä½äºå ©åæ¸éç´ï¼æ以å¨é種æ æ³ä¸ï¼æ好å¨å¯«å ¥æåæ´å¤çå·¥ä½ï¼èå¨è®åæåæ´å°çå·¥ä½ã ç¶èæ¹æ³ 2 ç缺é»æ¯ï¼ç¼æ¨ç¾å¨éè¦å¤§éçé¡å¤å·¥ä½ãå¹³åä¾èªªï¼ä¸æ¢æ¨ææç¼å¾ç´ 75 åé注è ï¼æ以æ¯ç§ 4.6k çç¼æ¨å¯«å ¥ï¼è®æäºå°ä¸»é æéç·å¿«åæ¯ç§ 345k çå¯«å ¥ãä½éåå¹³åå¼é±èäºä½¿ç¨è ç²çµ²æ¸å·®ç°å·¨å¤§éä¸ç¾å¯¦ï¼ä¸äºä½¿ç¨è æè¶ é 3000 è¬çç²çµ²ï¼éæå³èä¸æ¢æ¨æå°±å¯è½æå°è´ä¸»é æéç·å¿«åç 3000 è¬æ¬¡å¯«å ¥ï¼åæå®æé種æä½æ¯ä¸å巨大çææ° ââ æ¨ç¹åè©¦å¨ 5 ç§å §åç²çµ²å³éæ¨æã å¨æ¨ç¹çä¾åä¸ï¼æ¯å使ç¨è ç²çµ²æ¸çåä½ï¼å¯è½æéäºä½¿ç¨è çç¼æ¨é »çä¾å æ¬ï¼æ¯æ¢è¨å¯ä¼¸ç¸®æ§çä¸åééµè² è¼å¼æ¸ï¼å çºå®æ±ºå®äºæåºè² è¼ãä½ çæç¨ç¨å¼å¯è½å ·æé常ä¸åçç¹å¾µï¼ä½å¯ä»¥æ¡ç¨ç¸ä¼¼çååä¾èæ ®å®çè² è¼ã æ¨ç¹è»¼äºçæçµè½æï¼ç¾å¨å·²ç¶ç©©å¥å°å¯¦ç¾äºæ¹æ³ 2ï¼æ¨ç¹éæ¥è½åäºå ©ç¨®æ¹æ³çæ··åã大å¤æ¸ä½¿ç¨è ç¼çæ¨ææ被æåºå¯«å ¥å ¶ç²çµ²ä¸»é æéç·å¿«åä¸ãä½æ¯å°æ¸æææµ·éç²çµ²ç使ç¨è ï¼å³åæµï¼æ被æé¤å¨å¤ãç¶ç¨æ¶è®å主é æéç·æï¼åå¥å°ç²ååºè©²ä½¿ç¨è æé注çæ¯ä½åæµçæ¨æï¼åè使ç¨è ç主é æéç·å¿«ååä½µï¼å¦æ¹æ³ 1 æ示ãé種混åæ¹æ³è½å§çµå¦ä¸å°æä¾è¯å¥½æè½ãå¨ [第åäºç« ](ch12.md) ä¸æåå°éæ°è¨è«éåä¾åï¼éå¨è¦èæ´å¤æè¡å±¤é¢ä¹å¾ã ### æè¿°æè½ ä¸æ¦ç³»çµ±çè² è¼è¢«æ述好ï¼å°±å¯ä»¥ç 究ç¶è² è¼å¢å æç¼çä»éº¼ãæåå¯ä»¥å¾å ©ç¨®è§åº¦ä¾çï¼ * å¢å è² è¼å¼æ¸ä¸¦ä¿æ系統è³æºï¼CPUãè¨æ¶é«ãç¶²è·¯é »å¯¬çï¼ä¸è®æï¼ç³»çµ±æ§è½å°åå°ä»éº¼å½±é¿ï¼ * å¢å è² è¼å¼æ¸ä¸¦å¸æä¿ææè½ä¸è®æï¼éè¦å¢å å¤å°ç³»çµ±è³æºï¼ éå ©ååé¡é½éè¦æè½è³æï¼æ以è®æåç°¡å®å°çä¸ä¸å¦ä½æ述系統æ§è½ã å°æ¼ Hadoop é樣çæ¹èç系統ï¼é常éå¿çæ¯ **ååéï¼throughputï¼**ï¼å³æ¯ç§å¯ä»¥èççè¨éæ¸éï¼æè å¨ç¹å®è¦æ¨¡è³æéä¸å·è¡ä½æ¥ç總æé [^iii]ãå°æ¼ç·ä¸ç³»çµ±ï¼é常æ´éè¦çæ¯æåç **é¿ææéï¼response timeï¼**ï¼å³å®¢æ¶ç«¯å³éè«æ±å°æ¥æ¶é¿æä¹éçæéã [^iii]: çæ³æ æ³ä¸ï¼æ¹æ¬¡ä½æ¥çå·è¡æéæ¯è³æéç大å°é¤ä»¥ååéãå¨å¯¦è¸ä¸ç±æ¼è³æå¾æï¼è³æä¸æ¯åå»åä½å¨æ¯åå·¥ä½ç¨åºä¸ï¼ï¼éè¦çå¾ ææ ¢çä»»åå®æï¼æ以å·è¡æéå¾å¾æ´é·ã > #### 延é²åé¿ææé > > **延é²ï¼latencyï¼** å **é¿ææéï¼response timeï¼** ç¶å¸¸ç¨ä½å義è©ï¼ä½å¯¦éä¸å®å並ä¸ä¸æ¨£ãé¿ææéæ¯å®¢æ¶æçå°çï¼é¤äºå¯¦éèçè«æ±çæéï¼ **æåæéï¼service timeï¼** ï¼ä¹å¤ï¼éå æ¬ç¶²è·¯å»¶é²åæé延é²ã延é²æ¯æåè«æ±çå¾ èçç **æçºæé·**ï¼å¨æ¤æéå®èæ¼ **ä¼ç ï¼latentï¼** çæ ï¼ä¸¦çå¾ æåã17ãã å³ä½¿ä¸æ·éè¤å³éå樣çè«æ±ï¼æ¯æ¬¡å¾å°çé¿ææéä¹é½æç¥æä¸åãç¾å¯¦ä¸çç系統æèçåå¼å樣çè«æ±ï¼é¿ææéå¯è½ææå¾å¤§å·®ç°ãå æ¤æåéè¦å°é¿ææéè¦çºä¸åå¯ä»¥æ¸¬éçæ¸å¼ **åä½ï¼distributionï¼**ï¼èä¸æ¯å®åæ¸å¼ã å¨ [å 1-4](../img/fig1-4.png) ä¸ï¼æ¯åç°æ¢ä»£è¡¨ä¸æ¬¡å°æåçè«æ±ï¼å ¶é«åº¦è¡¨ç¤ºè«æ±è±è²»äºå¤é·æéã大å¤æ¸è«æ±æ¯ç¸ç¶å¿«çï¼ä½å¶ç¾æåºç¾éè¦æ´é·çæéçç°å¸¸å¼ãéä¹è¨±æ¯å çºç·©æ ¢çè«æ±å¯¦è³ªä¸éé·æ´å¤§ï¼ä¾å¦å®åå¯è½æèçæ´å¤çè³æãä½å³ä½¿ï¼ä½ èªçºï¼ææè«æ±é½è±è²»ç¸åæéçæ æ³ä¸ï¼é¨æ©çéå 延é²ä¹æå°è´çµæè®åï¼ä¾å¦ï¼ä¸ä¸æåæå°å¾èºç¨åºï¼ç¶²è·¯è³æå ä¸å¤±è TCP éå³ï¼åå¾æ¶éæ«åï¼å¼·å¶å¾ç£ç¢è®åçé é¢é¯èª¤ï¼ä¼ºæå¨æ©æ¶ä¸çéåã18ãï¼éæå¾å¤å ¶ä»åå ã ![](../img/fig1-4.png) **å 1-4 å±ç¤ºäºä¸åæå 100 次è«æ±é¿ææéçåå¼èç¾åä½æ¸** éå¸¸å ±è¡¨é½æå±ç¤ºæåçå¹³åé¿ææéãï¼å´æ ¼ä¾è¬ âå¹³åâ ä¸è©ä¸¦ä¸æ代任ä½ç¹å®å ¬å¼ï¼ä½å¯¦éä¸å®é常被çè§£çº **ç®è¡å¹³åå¼ï¼arithmetic meanï¼**ï¼çµ¦å® n åå¼ï¼å èµ·ä¾é¤ä»¥ n ï¼ãç¶èå¦æä½ æ³ç¥é â**å ¸åï¼typicalï¼**â é¿ææéï¼é£éº¼å¹³åå¼ä¸¦ä¸æ¯ä¸åé常好çææ¨ï¼å çºå®ä¸è½åè¨´ä½ æå¤å°ä½¿ç¨è 實éä¸ç¶æ·äºéå延é²ã éå¸¸ä½¿ç¨ **ç¾åä½é»ï¼percentilesï¼** ææ´å¥½ãå¦æå°é¿ææéå表ææå¿«å°ææ ¢æåºï¼é£éº¼ **ä¸ä½æ¸ï¼medianï¼** å°±å¨æ£ä¸éï¼èåä¾åï¼å¦æä½ çé¿ææéä¸ä½æ¸æ¯ 200 毫ç§ï¼éæå³èä¸åè«æ±çè¿åæéå°æ¼ 200 毫ç§ï¼å¦ä¸åæ¯éåè¦é·ã å¦ææ³ç¥éå ¸åå ´æ¯ä¸ä½¿ç¨è éè¦çå¾ å¤é·æéï¼é£éº¼ä¸ä½æ¸æ¯ä¸å好ç度éæ¨æºï¼ä¸å使ç¨è è«æ±çé¿ææéå°æ¼é¿ææéçä¸ä½æ¸ï¼å¦ä¸åæåæéæ¯ä¸ä½æ¸é·ãä¸ä½æ¸ä¹è¢«ç¨±çºç¬¬ 50 ç¾åä½é»ï¼ææç¸®å¯«çº p50ã注æä¸ä½æ¸æ¯éæ¼å®åè«æ±çï¼å¦æ使ç¨è åæç¼åºå¹¾åè«æ±ï¼å¨ä¸åæ話éç¨ä¸ï¼æè ç±æ¼ä¸åé é¢ä¸å å«äºå¤åè³æºï¼ï¼åè³å°ä¸åè«æ±æ¯ä¸ä½æ¸æ ¢çæ©çé å¤§æ¼ 50%ã çºäºå¼æ¸ ç°å¸¸å¼æå¤ç³ç³ï¼å¯ä»¥ççæ´é«çç¾åä½é»ï¼ä¾å¦ç¬¬ 95ã99 å 99.9 ç¾åä½é»ï¼ç¸®å¯«çº p95ï¼p99 å p999ï¼ãå®åæå³è 95%ã99% æ 99.9% çè«æ±é¿ææéè¦æ¯è©²é¾å¼å¿«ï¼ä¾å¦ï¼å¦æ第 95 ç¾åä½é»é¿ææéæ¯ 1.5 ç§ï¼åæå³è 100 åè«æ±ä¸ç 95 åé¿ææéå¿«æ¼ 1.5 ç§ï¼è 100 åè«æ±ä¸ç 5 åé¿ææéè¶ é 1.5 ç§ãå¦ [å 1-4](../img/fig1-4.png) æ示ã é¿ææéçé«ç¾åä½é»ï¼ä¹ç¨±çº **å°¾é¨å»¶é²**ï¼å³ **tail latencies**ï¼é常éè¦ï¼å çºå®åç´æ¥å½±é¿ä½¿ç¨è çæåé«é©ãä¾å¦äºé¦¬éå¨æè¿°å §é¨æåçé¿ææéè¦æ±ææ¯ä»¥ 99.9 ç¾åä½é»çºæºï¼å³ä½¿å®é»å½±é¿ä¸ååè«æ±ä¸çä¸åãéæ¯å çºè«æ±é¿æææ ¢ç客æ¶å¾å¾ä¹æ¯è³ææå¤ç客æ¶ï¼ä¹å¯ä»¥èªªæ¯ææå¹å¼çå®¢æ¶ ââ å çºä»åæé¢äºã19ããä¿è網ç«é¿æè¿ éå°æ¼ä¿æ客æ¶ç滿æ度é常éè¦ï¼äºé¦¬éè§å¯å°ï¼é¿ææéå¢å 100 毫ç§ï¼é·å®éå°±æ¸å° 1%ã20ãï¼èå¦ä¸äºå ±å說ï¼æ ¢ 1 ç§éæè®å®¢æ¶æ»¿æ度ææ¨æ¸å° 16%ã21ï¼22ãã å¦ä¸æ¹é¢ï¼æä½³å第 99.99 ç¾åä½é»ï¼ä¸è¬åè«æ±ä¸ææ ¢çä¸åï¼è¢«èªçºå¤ªæè²´äºï¼ä¸è½çºäºé¦¬éçç®æ¨å¸¶ä¾è¶³å¤ 好èãæ¸å°é«ç¾åä½é»èçé¿ææéç¸ç¶å°é£ï¼å çºå®å¾å®¹æåå°é¨æ©äºä»¶çå½±é¿ï¼éè¶ åºäºæ§å¶ç¯åï¼èä¸æçä¹å¾å°ã ç¾åä½é»é常ç¨æ¼ **æåç´å¥ç®æ¨ï¼SLO, service level objectivesï¼** å **æåç´å¥åè°ï¼SLA, service level agreementsï¼**ï¼å³å®ç¾©æåé ææè½åå¯ç¨æ§çååãSLA å¯è½æ宣åï¼å¦ææåé¿ææéçä¸ä½æ¸å°æ¼ 200 毫ç§ï¼ä¸ 99.9 ç¾åä½é»ä½æ¼ 1 ç§ï¼åèªçºæåå·¥ä½æ£å¸¸ï¼å¦æé¿ææéæ´é·ï¼å°±èªçºæåä¸éæ¨ï¼ãéäºææ¨çºå®¢æ¶è¨å®äºææå¼ï¼ä¸¦å 許客æ¶å¨ SLA æªéæ¨çæ æ³ä¸è¦æ±é款ã **æé延é²ï¼queueing delayï¼** é常ä½äºé«ç¾åä½é»èé¿ææéçå¾å¤§ä¸é¨åãç±æ¼ä¼ºæå¨åªè½ä¸¦è¡èçå°éçäºåï¼å¦åå ¶ CPU æ ¸æ¸çéå¶ï¼ï¼æ以åªè¦æå°éç·©æ ¢çè«æ±å°±è½é»ç¤å¾çºè«æ±çèçï¼é種ææææè¢«ç¨±çº **é é¨é»å¡ï¼head-of-line blockingï¼** ãå³ä½¿å¾çºè«æ±å¨ä¼ºæå¨ä¸èççéå¸¸è¿ éï¼ç±æ¼éè¦çå¾ å åè«æ±å®æï¼å®¢æ¶ç«¯æçµçå°çæ¯ç·©æ ¢ç總é«é¿ææéãå çºåå¨é種ææï¼æ¸¬é客æ¶ç«¯çé¿ææéé常éè¦ã çºæ¸¬è©¦ç³»çµ±çå¯ä¼¸ç¸®æ§è人çºç¢çè² è¼æï¼ç¢çè² è¼ç客æ¶ç«¯è¦ç¨ç«æ¼é¿ææéä¸æ·å³éè«æ±ãå¦æ客æ¶ç«¯å¨å³éä¸ä¸åè«æ±ä¹åçå¾ å åçè«æ±å®æï¼é種è¡çºæç¢ç人çºæéçææï¼ä½¿å¾æ¸¬è©¦æçä½åæ¯ç¾å¯¦æ æ³æ´çï¼ä½¿æ¸¬éçµæç¢çåå·®ã23ãã > #### 實è¸ä¸çç¾åä½é» > > å¨å¤éå¼å«çå¾ç«¯æå裡ï¼é«ç¾åä½æ¸è®å¾ç¹å¥éè¦ãå³ä½¿ä¸¦è¡å¼å«ï¼çµç«¯ä½¿ç¨è è«æ±ä»ç¶éè¦çå¾ ææ ¢ç並è¡å¼å«å®æãå¦ [å 1-5](../img/fig1-5.png) æ示ï¼åªéè¦ä¸åç·©æ ¢çå¼å«å°±å¯ä»¥ä½¿æ´åçµç«¯ä½¿ç¨è è«æ±è®æ ¢ãå³ä½¿åªæä¸å°é¨åå¾ç«¯å¼å«é度è¼æ ¢ï¼å¦æçµç«¯ä½¿ç¨è è«æ±éè¦å¤åå¾ç«¯å¼å«ï¼åç²å¾è¼æ ¢å¼å«çæ©æä¹æå¢å ï¼å æ¤è¼é«æ¯ä¾ççµç«¯ä½¿ç¨è è«æ±é度æè®æ ¢ï¼è©²ææ稱çºå°¾é¨å»¶é²æ¾å¤§ï¼å³ tail latency amplificationã24ãï¼ã > > å¦æä½ æ³å°é¿ææéç¾åé»æ°å¢å°ä½ çæåçç£è¦å表æ¿ï¼åéè¦æçºææå°è¨ç®å®åãä¾å¦ï¼ä½ å¯ä»¥ä½¿ç¨æ»åè¦çªä¾è·è¹¤é£çº10åéå §çè«æ±é¿ææéãæ¯ä¸åéï¼ä½ é½æè¨ç®åºè©²è¦çªä¸çé¿ææéä¸å¼åå種ç¾åæ¸ï¼ä¸¦å°éäºåº¦éå¼ç¹ªè£½å¨åä¸ã > > ç°¡å®ç實ç¾æ¯å¨æéè¦çªå §å²åææè«æ±çé¿ææéå表ï¼ä¸¦ä¸æ¯åéå°å表é²è¡æåºãå¦æå°ä½ ä¾èªªæç太ä½ï¼é£éº¼æä¸äºæ¼ç®æ³è½å¤ 以æå°ç CPU åè¨æ¶é«ææ¬ï¼å¦ååè¡°æ¸ã25ããt-digestã26ãæ HdrHistogram ã27ãï¼ä¾è¨ç®ç¾åä½æ¸çè¿ä¼¼å¼ãè«æ³¨æï¼å¹³åç¾åæ¯ï¼ä¾å¦ï¼æ¸å°æé解æ度æåä½µä¾èªå¤èºæ©å¨çè³æï¼å¨æ¸å¸ä¸æ²ææ義 - èåé¿ææéè³æçæ£ç¢ºæ¹æ³æ¯æ°å¢ç´æ¹åã28ãã ![](../img/fig1-5.png) **å 1-5 ç¶ä¸åè«æ±éè¦å¤åå¾ç«¯è«æ±æï¼å®åå¾ç«¯æ ¢è«æ±å°±æææ ¢æ´åçµç«¯ä½¿ç¨è çè«æ±** ### æå°è² è¼çæ¹æ³ ç¾å¨æåå·²ç¶è¨è«äºç¨æ¼æè¿°è² è¼çå¼æ¸åç¨æ¼è¡¡éæè½çææ¨ãå¯ä»¥éå§èªçè¨è«å¯ä¼¸ç¸®æ§äºï¼ç¶è² è¼å¼æ¸å¢å æï¼å¦ä½ä¿æè¯å¥½çæè½ï¼ é©ææåç´å¥è² è¼çæ¶æ§ä¸å¤ªå¯è½æä» 10 åæ¼æ¤çè² è¼ãå¦æä½ æ£å¨éç¼ä¸åå¿«éå¢é·çæåï¼é£éº¼æ¯æ¬¡è² è¼ç¼çæ¸éç´çå¢é·æï¼ä½ å¯è½é½éè¦éæ°èæ ®æ¶æ§ ââ æè æ´é »ç¹ã 人åç¶å¸¸è¨è« **縱å伸縮**ï¼scaling upï¼ä¹ç¨±çºåç´ä¼¸ç¸®ï¼å³ vertical scalingï¼è½åæ´å¼·å¤§çæ©å¨ï¼å **æ©«å伸縮**ï¼scaling outï¼ä¹ç¨±çºæ°´å¹³ä¼¸ç¸®ï¼å³ horizontal scalingï¼å°è² è¼åä½å°å¤èºå°æ©å¨ä¸ï¼ä¹éçå°ç«ãè·¨å¤èºæ©å¨åé è² è¼ä¹ç¨±çº â**ç¡å ±äº«ï¼shared-nothingï¼**â æ¶æ§ãå¯ä»¥å¨å®èºæ©å¨ä¸å·è¡ç系統é常æ´ç°¡å®ï¼ä½é«éæ©å¨å¯è½é常貴ï¼æ以é常å¯éçè² è¼é常ç¡æ³é¿å å°éè¦æ©«å伸縮ãç¾å¯¦ä¸çä¸çåªç§æ¶æ§éè¦å°éå ©ç¨®æ¹æ³å實å°çµåï¼å çºä½¿ç¨å¹¾èºè¶³å¤ 強大çæ©å¨å¯è½æ¯ä½¿ç¨å¤§éçå°åèæ¬æ©å¨æ´ç°¡å®ä¹æ´ä¾¿å®ã æäºç³»çµ±æ¯ **å½æ§ï¼elasticï¼** çï¼éæå³èå¯ä»¥å¨æª¢æ¸¬å°è² è¼å¢å æèªåå¢å è¨ç®è³æºï¼èå ¶ä»ç³»çµ±åæ¯æå伸縮ï¼äººå·¥åæ容é並決å®å系統æ°å¢æ´å¤çæ©å¨ï¼ãå¦æè² è¼ **極é£é 測ï¼highly unpredictableï¼**ï¼åå½æ§ç³»çµ±å¯è½å¾æç¨ï¼ä½æå伸縮系統æ´ç°¡å®ï¼ä¸¦ä¸æå¤æä½å¯è½ææ´å°ï¼è«åé± â[åå²æ§½å平衡](ch6.md#åå²æ§½å平衡)âï¼ã è·¨å¤èºæ©å¨é¨ç½² **ç¡çæ æåï¼stateless servicesï¼** é常簡å®ï¼ä½å°å¸¶çæ çè³æ系統å¾å®ç¯é»è®çºåæ£å¼é ç½®åå¯è½å¼å ¥è¨±å¤é¡å¤è¤é度ãåºæ¼éååå ï¼å¸¸èå訴æåæ該å°è³æ庫æ¾å¨å®åç¯é»ä¸ï¼ç¸±å伸縮ï¼ï¼ç´å°ä¼¸ç¸®ææ¬æå¯ç¨æ§éæ±è¿«ä½¿å ¶æ¹çºåæ£å¼ã é¨èåæ£å¼ç³»çµ±çå·¥å ·åæ½è±¡è¶ä¾è¶å¥½ï¼è³å°å°æ¼æäºåå¥çæç¨èè¨ï¼é種常èå¯è½ææ¹è®ãå¯ä»¥é è¦åæ£å¼è³æ系統å°æçºæªä¾çé è¨è¨å®ï¼å³ä½¿å°ä¸èç大éè³æææµéçå ´æ¯ä¹å¦æ¤ãæ¬æ¸çå ¶é¤é¨åå°ä»ç´¹å¤ç¨®åæ£å¼è³æ系統ï¼ä¸å è¨è«å®åå¨å¯ä¼¸ç¸®æ§æ¹é¢ç表ç¾ï¼éå æ¬æç¨æ§åå¯ç¶è·æ§ã 大è¦æ¨¡ç系統æ¶æ§é常æ¯æç¨ç¹å®ç ââ æ²æä¸æé®®åé天çéç¨å¯ä¼¸ç¸®æ¶æ§ï¼ä¸æ£å¼çå«æ³ï¼**è¬éæ²¹ï¼magic scaling sauceï¼** ï¼ãæç¨çåé¡å¯è½æ¯è®åéãå¯«å ¥éãè¦å²åçè³æéãè³æçè¤é度ãé¿ææéè¦æ±ã訪å模å¼æè ææåé¡ç大éç´ã èåä¾åï¼ç¨æ¼èçæ¯ç§åè¬åè«æ±ï¼æ¯å大å°çº 1 kBï¼ç系統èç¨æ¼èçæ¯åé 3 åè«æ±ï¼æ¯å大å°çº 2GBï¼ç系統çä¸å»æé常ä¸ä¸æ¨£ï¼åç®¡å ©å系統æå樣çè³æååéã ä¸åè¯å¥½é©é æç¨çå¯ä¼¸ç¸®æ¶æ§ï¼æ¯åç¹è **åè¨ï¼assumptionï¼** 建ç«çï¼åªäºæä½æ¯å¸¸è¦çï¼åªäºæä½æ¯ç½è¦çï¼éå°±æ¯æè¬è² è¼å¼æ¸ãå¦æåè¨æçµæ¯é¯èª¤çï¼é£éº¼çºä¼¸ç¸®æåçå·¥ç¨æå ¥å°±ç½è²»äºï¼æç³ç³çæ¯é©å¾å ¶åãå¨æ©æåµæ¥å ¬å¸æéæ£å¼ç¢åä¸ï¼é常æ¯æ´ç¢åå¿«éè¿ä»£çè½åï¼è¦æ¯å¯ä¼¸ç¸®è³æªä¾çåæ³è² è¼è¦éè¦çå¤ã å管éäºæ¶æ§æ¯æç¨ç¨å¼ç¹å®çï¼ä½å¯ä¼¸ç¸®çæ¶æ§é常ä¹æ¯å¾éç¨çç©æ¨å¡æ建èæçï¼ä¸¦ä»¥å¸¸è¦ç模å¼æåãå¨æ¬æ¸ä¸ï¼æåå°è¨è«éäºæ§ä»¶å模å¼ã ## å¯ç¶è·æ§ ç¾æå¨ç¥ï¼è»é«ç大é¨åéé·ä¸¦ä¸å¨æåçéç¼é段ï¼èæ¯å¨æçºçç¶è·é段ï¼å æ¬ä¿®å¾©æ¼æ´ãä¿æ系統æ£å¸¸å·è¡ã調æ¥å¤±æãé©é æ°çå¹³èºãçºæ°çå ´æ¯é²è¡ä¿®æ¹ãåéæè¡åµåæ°å¢æ°çåè½ã ä¸å¹¸çæ¯ï¼è¨±å¤å¾äºè»é«ç³»çµ±è¡æ¥ç人ä¸åæ¡ç¶è·æè¬ç **éºçï¼legacyï¼** 系統ï¼ââ ä¹è¨±å çºæ¶åä¿®å¾©å ¶ä»äººçé¯èª¤ãåéæçå¹³èºæ交éï¼æè 系統被迫使ç¨æ¼ä¸äºä»½å¤å·¥ä½ãæ¯ä¸åéºç系統é½ä»¥èªå·±çæ¹å¼è®äººä¸ç½ï¼æ以å¾é£çµ¦åºä¸åéç¨ç建è°ä¾åå®åæ交éã ä½æ¯æåå¯ä»¥ï¼ä¹æ該以é樣ä¸ç¨®æ¹å¼ä¾è¨è¨è»é«ï¼å¨è¨è¨ä¹åå°±åéèæ ®åå¯è½æ¸å°ç¶è·æéççè¦ï¼å¾èé¿å èªå·±çè»é«ç³»çµ±è®æéºç系統ãçºæ¤ï¼æåå°ç¹å¥é注è»é«ç³»çµ±çä¸åè¨è¨ååï¼ * å¯æä½æ§ï¼Operabilityï¼ ä¾¿æ¼éç¶åéä¿æ系統平穩å·è¡ã * ç°¡å®æ§ï¼Simplicityï¼ å¾ç³»çµ±ä¸æ¶é¤åå¯è½å¤ç **è¤é度ï¼complexityï¼**ï¼ä½¿æ°å·¥ç¨å¸«ä¹è½è¼é¬ç解系統ï¼æ³¨æéå使ç¨è ä»é¢çç°¡å®æ§ä¸ä¸æ¨£ï¼ã * å¯æ¼åæ§ï¼evolvabilityï¼ ä½¿å·¥ç¨å¸«å¨æªä¾è½è¼é¬å°å°ç³»çµ±é²è¡æ´æ¹ï¼ç¶éæ±è®åæçºæ°æç¨å ´æ¯åé©é ãä¹ç¨±çº **å¯æ´å å¥ä»¶æ§ï¼extensibilityï¼**ã**å¯ä¿®æ¹æ§ï¼modifiabilityï¼** æ **å¯å¡æ§ï¼plasticityï¼**ã åä¹åæå°çå¯é æ§ãå¯ä¼¸ç¸®æ§ä¸æ¨£ï¼å¯¦ç¾éäºç®æ¨ä¹æ²æç°¡å®ç解決æ¹æ¡ãä¸éæåæ試èæ³è±¡å ·æå¯æä½æ§ï¼ç°¡å®æ§åå¯æ¼åæ§ç系統ææ¯ä»éº¼æ¨£åã ### å¯æä½æ§ï¼äººçè¦çï¼éæéç¶ æ人èªçºï¼âè¯å¥½çéç¶ç¶å¸¸å¯ä»¥ç¹éåå¾ï¼æä¸å®æ´ï¼è»é«çä¾·éæ§ï¼èå好çè»é«æ¤ä¸åå¾éç¶ä¹æ²æ³å¯é å·è¡âãå管éç¶çæäºæ¹é¢å¯ä»¥ï¼èä¸æ該æ¯èªååçï¼ä½å¨æå建ç«æ£ç¢ºéä½çèªååæ©å¶ä»ç¶å決æ¼äººã éç¶åéå°æ¼ä¿æè»é«ç³»çµ±é å©å·è¡è³ééè¦ãä¸ååªç§éç¶åéçå ¸åè·è²¬å¦ä¸ï¼æè æ´å¤ï¼ã29ãï¼ * ç£æ§ç³»çµ±çå·è¡çæ³ï¼ä¸¦å¨æåçæ ä¸ä½³æå¿«éæ¢å¾©æåã * è·è¹¤åé¡çåå ï¼ä¾å¦ç³»çµ±æ éææè½ä¸éã * åææ´æ°è»é«åå¹³èºï¼æ¯å¦å®å ¨è£ä¸ã * ç解系統éçç¸äºä½ç¨ï¼ä»¥ä¾¿å¨ç°å¸¸è®æ´é ææ失åé²è¡è¦é¿ã * é 測æªä¾çåé¡ï¼ä¸¦å¨åé¡åºç¾ä¹åå 以解決ï¼ä¾å¦ï¼å®¹éè¦åï¼ã * 建ç«é¨ç½²ãé ç½®ã管çæ¹é¢çè¯å¥½å¯¦è¸ï¼ç·¨å¯«ç¸æå·¥å ·ã * å·è¡è¤éçç¶è·ä»»åï¼ä¾å¦å°æç¨ç¨å¼å¾ä¸åå¹³èºé·ç§»å°å¦ä¸åå¹³èºã * ç¶é ç½®è®æ´æï¼ç¶æ系統çå®å ¨æ§ã * å®ç¾©å·¥ä½æµç¨ï¼ä½¿éç¶æä½å¯é 測ï¼ä¸¦ä¿æçç¢ç°å¢ç©©å®ã * éµæççç¤æµæ°´çå µï¼ç¶æçµç¹å°ç³»çµ±çç解ã è¯å¥½çå¯æä½æ§æå³èæ´è¼é¬çæ¥å¸¸å·¥ä½ï¼é²èéç¶åéè½å°æ³¨æ¼é«å¹å¼çäºæ ãè³æ系統å¯ä»¥ééå種æ¹å¼ä½¿æ¥å¸¸ä»»åæ´è¼é¬ï¼ * ééè¯å¥½çç£æ§ï¼æä¾å°ç³»çµ±å §é¨çæ åå·è¡æè¡çºç **å¯è¦æ§ï¼visibilityï¼**ã * çºèªååæä¾è¯å¥½æ¯æ´ï¼å°ç³»çµ±èæ¨æºåå·¥å ·ç¸æ´åã * é¿å ä¾è³´å®èºæ©å¨ï¼å¨æ´å系統繼çºä¸éæ·å·è¡çæ æ³ä¸å 許æ©å¨åæ©ç¶è·ï¼ã * æä¾è¯å¥½çæ件åææ¼ç解çæä½æ¨¡åï¼âå¦æå Xï¼æç¼ç Yâï¼ã * æä¾è¯å¥½çé è¨è¡çºï¼ä½éè¦æä¹å 許管çå¡èªç±è¦èé è¨å¼ã * ææ¢ä»¶æé²è¡èªæ修復ï¼ä½éè¦æä¹å 許管çå¡æåæ§å¶ç³»çµ±çæ ã * è¡çºå¯é 測ï¼æ大é度æ¸å°æå¤ã ### ç°¡å®æ§ï¼ç®¡çè¤é度 å°åè»é«å°æ¡å¯ä»¥ä½¿ç¨ç°¡å®è¨åçãå¯è¡¨ç¾åçç¨å¼ç¢¼ï¼ä½é¨èå°æ¡è¶ä¾è¶å¤§ï¼ç¨å¼ç¢¼å¾å¾è®å¾é常è¤éï¼é£ä»¥ç解ãé種è¤é度ææ ¢äºææ系統ç¸é人å¡ï¼é²ä¸æ¥å¢å äºç¶è·ææ¬ãä¸åé·å ¥è¤éæ³¥æ½çè»é«å°æ¡ææ被æè¿°çº **çæ³¥æ½ï¼a big ball of mudï¼** ã30ãã **è¤é度ï¼complexityï¼** æå種å¯è½çççï¼ä¾å¦ï¼çæ 空éæ¿å¢ã模çµéç·å¯è¦åãç³¾çµçä¾è³´éä¿ãä¸ä¸è´çå½ååè¡èªã解決æè½åé¡ç Hackãéè¦ç¹éçç¹ä¾ççï¼ç¾å¨å·²ç¶æå¾å¤éæ¼éå話é¡çè¨è«ã31,32,33ãã å çºè¤é度å°è´ç¶è·å°é£æï¼é ç®åæéå®æé常æè¶ æ¯ãå¨è¤éçè»é«ä¸é²è¡è®æ´ï¼å¼å ¥é¯èª¤ç風éªä¹æ´å¤§ï¼ç¶éç¼äººå¡é£ä»¥ç解系統æï¼é±èçåè¨ãç¡æçå¾æåæå¤çäºåå°±æ´å®¹æ被忽ç¥ãç¸åï¼éä½è¤é度è½æ¥µå¤§å°æé«è»é«çå¯ç¶è·æ§ï¼å æ¤ç°¡å®æ§æ該æ¯æ§å»ºç³»çµ±çä¸åééµç®æ¨ã ç°¡å系統並ä¸ä¸å®æå³èæ¸å°åè½ï¼å®ä¹å¯ä»¥æå³èæ¶é¤ **é¡å¤çï¼accidentalï¼** çè¤é度ãMoseley å Marksã32ãæ **é¡å¤è¤é度** å®ç¾©çºï¼ç±å ·é«å¯¦ç¾ä¸æ¹§ç¾ï¼èéï¼å¾ä½¿ç¨è è¦è§çï¼ç³»çµ±æ解決çï¼åé¡æ¬èº«åºæçè¤é度ã ç¨æ¼æ¶é¤ **é¡å¤è¤é度** çæå¥½å·¥å ·ä¹ä¸æ¯ **æ½è±¡ï¼abstractionï¼**ãä¸å好çæ½è±¡å¯ä»¥å°å¤§é實ç¾ç´°ç¯é±èå¨ä¸å乾淨ï¼ç°¡å®ææçå¤è§ä¸é¢ãä¸å好çæ½è±¡ä¹å¯ä»¥å»£æ³ç¨æ¼åé¡ä¸åæç¨ãæ¯èµ·éè¤é å¾å¤è¼ªåï¼éç¨æ½è±¡ä¸å æ´ææçï¼èä¸æå©æ¼éç¼é«è³ªéçè»é«ãæ½è±¡å 件ç質éæ¹é²å°ä½¿ææ使ç¨å®çæç¨åçã ä¾å¦ï¼é«éç¨å¼èªè¨æ¯ä¸ç¨®æ½è±¡ï¼é±èäºæ©å¨ç¢¼ãCPU æ«åå¨å系統å¼å«ãSQL ä¹æ¯ä¸ç¨®æ½è±¡ï¼é±èäºè¤éçç£ç¢ / è¨æ¶é«è³æçµæ§ãä¾èªå ¶ä»å®¢æ¶ç«¯çä½µç¼è«æ±ãå´©æ½°å¾çä¸ä¸è´æ§ãç¶ç¶å¨ç¨é«éèªè¨ç¨å¼è¨è¨æï¼æåä»ç¶ç¨å°äºæ©å¨ç¢¼ï¼åªä¸éæ²æ **ç´æ¥ï¼directlyï¼** 使ç¨ç½·äºï¼æ£æ¯å çºç¨å¼èªè¨çæ½è±¡ï¼æåæä¸å¿ å»èæ ®éäºå¯¦ç¾ç´°ç¯ã æ½è±¡å¯ä»¥å¹«å©æåå°ç³»çµ±çè¤é度æ§å¶å¨å¯ç®¡ççæ°´å¹³ï¼ä¸éï¼æ¾å°å¥½çæ½è±¡æ¯é常å°é£çãå¨åæ£å¼ç³»çµ±é åéç¶æ許å¤å¥½çæ¼ç®æ³ï¼ä½æå並ä¸æ¸ æ¥å®åæ該æå æä»éº¼æ¨£æ½è±¡ã æ¬æ¸å°ç·ç¯é£äºå 許æåå°å¤§å系統çé¨åæåçºå®ç¾©æ確çãå¯éç¨çå 件çåªç§æ½è±¡ã ### å¯æ¼åæ§ï¼ææ±è®å 系統çéæ±æ°¸é ä¸è®ï¼åºæ¬æ¯ä¸å¯è½çãæ´å¯è½çæ æ³æ¯ï¼å®åèæ¼å¸¸æ çè®åä¸ï¼ä¾å¦ï¼ä½ ç解äºæ°çäºå¯¦ãåºç¾ææ³ä¸å°çæç¨å ´æ¯ãæ¥ååªå é åºç¼çè®åã使ç¨è è¦æ±æ°åè½ãæ°å¹³èºå代èå¹³èºãæ³å¾æç£ç®¡è¦æ±ç¼çè®åã系統å¢é·è¿«ä½¿æ¶æ§è®åçã å¨çµç¹æµç¨æ¹é¢ï¼**ææ·ï¼agileï¼** å·¥ä½æ¨¡å¼çºé©æè®åæä¾äºä¸åæ¡æ¶ãææ·ç¤¾ç¾¤ééç¼äºå°å¨é »ç¹è®åçç°å¢ä¸éç¼è»é«å¾æ幫å©çæè¡å·¥å ·å模å¼ï¼å¦ **æ¸¬è©¦é© åéç¼ï¼TDD, test-driven developmentï¼** å **éæ§ï¼refactoringï¼** ã éäºææ·æè¡ç大é¨åè¨è«é½éä¸å¨ç¸ç¶å°çè¦æ¨¡ï¼åä¸åæç¨ä¸çå¹¾åç¨å¼ç¢¼æªæ¡ï¼ãæ¬æ¸å°æ¢ç´¢å¨æ´å¤§è³æ系統層é¢ä¸æé«ææ·æ§çæ¹æ³ï¼å¯è½ç±å¹¾åä¸åçæç¨ææåçµæãä¾å¦ï¼çºäºå°è£é 主é æéç·çæ¹æ³å¾æ¹æ³ 1 è®çºæ¹æ³ 2ï¼ä½ æå¦ä½ âéæ§â æ¨ç¹çæ¶æ§ ï¼ ä¿®æ¹è³æç³»çµ±ä¸¦ä½¿å ¶é©æä¸æ·è®åéæ±ç容æç¨åº¦ï¼æ¯è **ç°¡å®æ§** å **æ½è±¡æ§** å¯åç¸éçï¼ç°¡å®ææç系統é常æ¯è¤é系統æ´å®¹æä¿®æ¹ãä½ç±æ¼éæ¯ä¸åé常éè¦çæ¦å¿µï¼æåå°ç¨ä¸åä¸åçè©ä¾æ代è³æ系統層é¢çææ·æ§ï¼ **å¯æ¼åæ§ï¼evolvabilityï¼** ã34ãã ## æ¬ç« å°çµ æ¬ç« æ¢è¨äºä¸äºéæ¼è³æå¯éåæç¨çåºæ¬æèæ¹å¼ãéäºååå°æå°æåé±è®æ¬æ¸çå ¶é¤é¨åï¼é£è£¡å°ææ·±å ¥æè¡ç´°ç¯ã ä¸åæç¨å¿ é 滿足å種éæ±æ稱å¾ä¸æç¨ãæä¸äº **åè½éæ±**ï¼functional requirementsï¼å³å®æ該åä»éº¼ï¼æ¯å¦å 許以å種æ¹å¼å²åï¼æª¢ç´¢ï¼æå°åèçè³æï¼ä»¥åä¸äº **éåè½æ§éæ±**ï¼nonfunctionalï¼å³éç¨å±¬æ§ï¼ä¾å¦å®å ¨æ§ãå¯é æ§ãåè¦æ§ãå¯ä¼¸ç¸®æ§ãç¸å®¹æ§åå¯ç¶è·æ§ï¼ãå¨æ¬ç« 詳細è¨è«äºå¯é æ§ï¼å¯ä¼¸ç¸®æ§åå¯ç¶è·æ§ã **å¯é æ§ï¼Reliabilityï¼** æå³èå³ä½¿ç¼çæ éï¼ç³»çµ±ä¹è½æ£å¸¸å·¥ä½ãæ éå¯è½ç¼çå¨ç¡¬é«ï¼é常æ¯é¨æ©çåä¸ç¸éçï¼ãè»é«ï¼é常æ¯ç³»çµ±æ§ç Bugï¼å¾é£èçï¼å人é¡ï¼ä¸å¯é¿å å°æä¸æåºé¯ï¼ã**容é¯æè¡** å¯ä»¥å°çµç«¯ä½¿ç¨è é±èæäºåå¥çæ éã **å¯ä¼¸ç¸®æ§ï¼Scalabilityï¼** æå³èå³ä½¿å¨è² è¼å¢å çæ æ³ä¸ä¹æä¿ææè½ççç¥ãçºäºè¨è«å¯ä¼¸ç¸®æ§ï¼æåé¦å éè¦å®éæè¿°è² è¼åæè½çæ¹æ³ãæåç°¡è¦äºè§£äºæ¨ç¹ä¸»é æéç·çä¾åï¼ä»ç´¹æè¿°è² è¼çæ¹æ³ï¼ä¸¦å°é¿ææéç¾åä½é»ä½çºè¡¡éæè½çä¸ç¨®æ¹å¼ãå¨å¯ä¼¸ç¸®ç系統ä¸å¯ä»¥æ°å¢ **èç容éï¼processing capacityï¼** 以å¨é«è² è¼ä¸ä¿æå¯é ã **å¯ç¶è·æ§ï¼Maintainabilityï¼** æ許å¤æ¹é¢ï¼ä½å¯¦è³ªä¸æ¯éæ¼å·¥ç¨å¸«åéç¶åéçç活質éçãè¯å¥½çæ½è±¡å¯ä»¥å¹«å©éä½è¤é度ï¼ä¸¦ä½¿ç³»çµ±ææ¼ä¿®æ¹åé©ææ°çæç¨å ´æ¯ãè¯å¥½çå¯æä½æ§æå³èå°ç³»çµ±çå¥åº·çæ å ·æè¯å¥½çå¯è¦æ§ï¼ä¸¦ææææç管çæ段ã ä¸å¹¸çæ¯ï¼ä½¿æç¨å¯é ãå¯ä¼¸ç¸®æå¯ç¶è·ä¸¦ä¸å®¹æãä½æ¯æäºæ¨¡å¼åæè¡æä¸æ·éæ°åºç¾å¨ä¸åçæç¨ä¸ãå¨æ¥ä¸ä¾çå¹¾ç« ä¸ï¼æåå°çå°ä¸äºè³æ系統çä¾åï¼ä¸¦åæå®åå¦ä½å¯¦ç¾éäºç®æ¨ã å¨æ¬æ¸å¾é¢ç [第ä¸é¨å](part-iii.md) ä¸ï¼æåå°çå°ä¸ç¨®æ¨¡å¼ï¼å¹¾åå 件ååå·¥ä½ä»¥æ§æä¸åå®æ´ç系統ï¼å¦ [å 1-1](../img/fig1-1.png) ä¸çä¾åï¼ ## åèæç» 1. Michael Stonebraker and UÄur Ãetintemel: â['One Size Fits All': An Idea Whose Time Has Come and Gone](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.68.9136&rep=rep1&type=pdf),â at *21st International Conference on Data Engineering* (ICDE), April 2005. 1. Walter L. Heimerdinger and Charles B. Weinstock: â[A Conceptual Framework for System Fault Tolerance](http://www.sei.cmu.edu/reports/92tr033.pdf),â Technical Report CMU/SEI-92-TR-033, Software Engineering Institute, Carnegie Mellon University, October 1992. 1. Ding Yuan, Yu Luo, Xin Zhuang, et al.: â[Simple Testing Can Prevent Most Critical Failures: An Analysis of Production Failures in Distributed Data-Intensive Systems](https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf),â at *11th USENIX Symposium on Operating Systems Design and Implementation* (OSDI), October 2014. 1. Yury Izrailevsky and Ariel Tseitlin: â[The Netflix Simian Army](http://techblog.netflix.com/2011/07/netflix-simian-army.html),â *techblog.netflix.com*, July 19, 2011. 1. Daniel Ford, François Labelle, Florentina I. Popovici, et al.: â[Availability in Globally Distributed Storage Systems](http://research.google.com/pubs/archive/36737.pdf),â at *9th USENIX Symposium on Operating Systems Design and Implementation* (OSDI), October 2010. 1. Brian Beach: â[Hard Drive Reliability Update â Sep 2014](https://www.backblaze.com/blog/hard-drive-reliability-update-september-2014/),â *backblaze.com*, September 23, 2014. 1. Laurie Voss: â[AWS: The Good, the Bad and the Ugly](https://web.archive.org/web/20160429075023/http://blog.awe.sm/2012/12/18/aws-the-good-the-bad-and-the-ugly/),â *blog.awe.sm*, December 18, 2012. 1. Haryadi S. Gunawi, Mingzhe Hao, Tanakorn Leesatapornwongsa, et al.: â[What Bugs Live in the Cloud?](http://ucare.cs.uchicago.edu/pdf/socc14-cbs.pdf),â at *5th ACM Symposium on Cloud Computing* (SoCC), November 2014. [doi:10.1145/2670979.2670986](http://dx.doi.org/10.1145/2670979.2670986) 1. Nelson Minar: â[Leap Second Crashes Half the Internet](http://www.somebits.com/weblog/tech/bad/leap-second-2012.html),â *somebits.com*, July 3, 2012. 1. Amazon Web Services: â[Summary of the Amazon EC2 and Amazon RDS Service Disruption in the US East Region](http://aws.amazon.com/message/65648/),â *aws.amazon.com*, April 29, 2011. 1. Richard I. Cook: â[How Complex Systems Fail](http://web.mit.edu/2.75/resources/random/How%20Complex%20Systems%20Fail.pdf),â Cognitive Technologies Laboratory, April 2000. 1. Jay Kreps: â[Getting Real About Distributed System Reliability](http://blog.empathybox.com/post/19574936361/getting-real-about-distributed-system-reliability),â *blog.empathybox.com*, March 19, 2012. 1. David Oppenheimer, Archana Ganapathi, and David A. Patterson: â[Why Do Internet Services Fail, and What Can Be Done About It?](http://static.usenix.org/legacy/events/usits03/tech/full_papers/oppenheimer/oppenheimer.pdf),â at *4th USENIX Symposium on Internet Technologies and Systems* (USITS), March 2003. 1. Nathan Marz: â[Principles of Software Engineering, Part 1](http://nathanmarz.com/blog/principles-of-software-engineering-part-1.html),â *nathanmarz.com*, April 2, 2013. 1. Michael Jurewitz:â[The Human Impact of Bugs](http://jury.me/blog/2013/3/14/the-human-impact-of-bugs),â *jury.me*, March 15, 2013. 1. Raffi Krikorian: â[Timelines at Scale](http://www.infoq.com/presentations/Twitter-Timeline-Scalability),â at *QCon San Francisco*, November 2012. 1. Martin Fowler: *Patterns of Enterprise Application Architecture*. Addison Wesley, 2002. ISBN: 978-0-321-12742-6 1. Kelly Sommers: â[After all that run around, what caused 500ms disk latency even when we replaced physical server?](https://twitter.com/kellabyte/status/532930540777635840)â *twitter.com*, November 13, 2014. 1. Giuseppe DeCandia, Deniz Hastorun, Madan Jampani, et al.: â[Dynamo: Amazon's Highly Available Key-Value Store](http://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf),â at *21st ACM Symposium on Operating Systems Principles* (SOSP), October 2007. 1. Greg Linden: â[Make Data Useful](http://glinden.blogspot.co.uk/2006/12/slides-from-my-talk-at-stanford.html),â slides from presentation at Stanford University Data Mining class (CS345), December 2006. 1. Tammy Everts: â[The Real Cost of Slow Time vs Downtime](http://www.webperformancetoday.com/2014/11/12/real-cost-slow-time-vs-downtime-slides/),â *webperformancetoday.com*, November 12, 2014. 1. Jake Brutlag:â[Speed Matters for Google Web Search](http://googleresearch.blogspot.co.uk/2009/06/speed-matters.html),â *googleresearch.blogspot.co.uk*, June 22, 2009. 1. Tyler Treat: â[Everything You Know About Latency Is Wrong](http://bravenewgeek.com/everything-you-know-about-latency-is-wrong/),â *bravenewgeek.com*, December 12, 2015. 1. Jeffrey Dean and Luiz André Barroso: â[The Tail at Scale](http://cacm.acm.org/magazines/2013/2/160173-the-tail-at-scale/fulltext),â *Communications of the ACM*, volume 56, number 2, pages 74â80, February 2013. [doi:10.1145/2408776.2408794](http://dx.doi.org/10.1145/2408776.2408794) 1. Graham Cormode, Vladislav Shkapenyuk, Divesh Srivastava, and Bojian Xu: â[Forward Decay: A Practical Time Decay Model for Streaming Systems](http://dimacs.rutgers.edu/~graham/pubs/papers/fwddecay.pdf),â at *25th IEEE International Conference on Data Engineering* (ICDE), March 2009. 1. Ted Dunning and Otmar Ertl: â[Computing Extremely Accurate Quantiles Using t-Digests](https://github.com/tdunning/t-digest),â *github.com*, March 2014. 1. Gil Tene: â[HdrHistogram](http://www.hdrhistogram.org/),â *hdrhistogram.org*. 1. Baron Schwartz: â[Why Percentiles Donât Work the Way You Think](https://www.vividcortex.com/blog/why-percentiles-dont-work-the-way-you-think),â *vividcortex.com*, December 7, 2015. 1. James Hamilton: â[On Designing and Deploying Internet-Scale Services](https://www.usenix.org/legacy/events/lisa07/tech/full_papers/hamilton/hamilton.pdf),â at *21st Large Installation System Administration Conference* (LISA), November 2007. 1. Brian Foote and Joseph Yoder: â[Big Ball of Mud](http://www.laputan.org/pub/foote/mud.pdf),â at *4th Conference on Pattern Languages of Programs* (PLoP), September 1997. 1. Frederick P Brooks: âNo Silver Bullet â Essence and Accident in Software Engineering,â in *The Mythical Man-Month*, Anniversary edition, Addison-Wesley, 1995. ISBN: 978-0-201-83595-3 1. Ben Moseley and Peter Marks: â[Out of the Tar Pit](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.93.8928),â at *BCS Software Practice Advancement* (SPA), 2006. 1. Rich Hickey: â[Simple Made Easy](http://www.infoq.com/presentations/Simple-Made-Easy),â at *Strange Loop*, September 2011. 1. Hongyu Pei Breivold, Ivica Crnkovic, and Peter J. Eriksson: â[Analyzing Software Evolvability](http://www.mrtc.mdh.se/publications/1478.pdf),â at *32nd Annual IEEE International Computer Software and Applications Conference* (COMPSAC), July 2008. [doi:10.1109/COMPSAC.2008.50](http://dx.doi.org/10.1109/COMPSAC.2008.50) ------ | ä¸ä¸ç« | ç®é | ä¸ä¸ç« | | ----------------------------------- | ------------------------------- | ------------------------------------ | | [第ä¸é¨åï¼è³æ系統åºç¤](part-i.md) | [è¨è¨è³æå¯éåæç¨](README.md) | [第äºç« ï¼è³æ模åèæ¥è©¢èªè¨](ch2.md) |