# 第ä¸ç« ï¼å¯é æ§ãå¯ä¼¸ç¼©æ§åå¯ç»´æ¤æ§ ![](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) |