# 第äºé¨åï¼åå¸å¼æ°æ® > ä¸ä¸ªæåçææ¯ï¼ç°å®çä¼å çº§å¿ é¡»é«äºå ¬å ³ï¼ä½ å¯ä»¥ç³å¼å«äººï¼ä½ç³å¼ä¸äºèªç¶è§å¾ã > > ââ ç½æ°æ¯å§åä¼æ¥åï¼1986ï¼ > ------- å¨æ¬ä¹¦ç [第ä¸é¨å](part-i.md) ä¸ï¼æ们讨论äºæ°æ®ç³»ç»çå个æ¹é¢ï¼ä½ä» éäºæ°æ®åå¨å¨åå°æºå¨ä¸çæ åµãç°å¨æ们å°äº [第äºé¨å](part-ii.md)ï¼è¿å ¥æ´é«çå±æ¬¡ï¼å¹¶æåºä¸ä¸ªé®é¢ï¼å¦æ **å¤å°æºå¨** åä¸æ°æ®çåå¨åæ£ç´¢ï¼ä¼åçä»ä¹ï¼ ä½ å¯è½ä¼åºäºåç§åæ ·çåå ï¼å¸æå°æ°æ®åºåå¸å°å¤å°æºå¨ä¸ï¼ * å¯ä¼¸ç¼©æ§ å¦æä½ çæ°æ®éã读åè´è½½ãåå ¥è´è½½è¶ åºåå°æºå¨çå¤çè½åï¼å¯ä»¥å°è´è½½åæ£å°å¤å°è®¡ç®æºä¸ã * 容é / é«å¯ç¨æ§ å¦æä½ çåºç¨éè¦å¨åå°æºå¨ï¼æå¤å°æºå¨ï¼ç½ç»ææ´ä¸ªæ°æ®ä¸å¿ï¼åºç°æ éçæ åµä¸ä»ç¶è½ç»§ç»å·¥ä½ï¼åå¯ä½¿ç¨å¤å°æºå¨ï¼ä»¥æä¾åä½ãä¸å°æ éæ¶ï¼å¦ä¸å°å¯ä»¥æ¥ç®¡ã * å»¶è¿ å¦æå¨ä¸çåå°é½æç¨æ·ï¼ä½ ä¹è®¸ä¼èèå¨å ¨çèå´é¨ç½²å¤ä¸ªæå¡å¨ï¼ä»èæ¯ä¸ªç¨æ·å¯ä»¥ä»å°çä¸æè¿çæ°æ®ä¸å¿è·åæå¡ï¼é¿å äºçå¾ ç½ç»æ°æ®å ç©¿è¶å个ä¸çã ## 伸缩è³æ´é«çè½½è· å¦æä½ éè¦çåªæ¯ä¼¸ç¼©è³æ´é«ç **è½½è·ï¼loadï¼**ï¼æç®åçæ¹æ³å°±æ¯è´ä¹°æ´å¼ºå¤§çæºå¨ï¼ææ¶ç§°ä¸º **åç´ä¼¸ç¼©**ï¼å³ vertical scalingï¼æ **åä¸ä¼¸ç¼©**ï¼å³ scale upï¼ã许å¤å¤çå¨ï¼å ååç£çå¯ä»¥å¨åä¸ä¸ªæä½ç³»ç»ä¸ç¸äºè¿æ¥ï¼å¿«éçç¸äºè¿æ¥å 许任æå¤çå¨è®¿é®å åæç£ççä»»æé¨åãå¨è¿ç§ **å ±äº«å åæ¶æï¼shared-memory architectureï¼** ä¸ï¼ææçç»ä»¶é½å¯ä»¥çä½ä¸å°åç¬çæºå¨ [^i]ã [^i]: å¨å¤§åæºä¸ï¼å°½ç®¡ä»»æå¤çå¨é½å¯ä»¥è®¿é®å åçä»»æé¨åï¼ä½æ»æä¸äºå ååºåä¸ä¸äºå¤çå¨æ´æ¥è¿ï¼ç§°ä¸º **éååå å访é®ï¼nonuniform memory access, NUMAï¼**ã1ãï¼ã 为äºææå©ç¨è¿ç§æ¶æç¹æ§ï¼éè¦å¯¹å¤çè¿è¡ç»åï¼ä»¥ä¾¿æ¯ä¸ªå¤çå¨ä¸»è¦è®¿é®ä¸´è¿çå åï¼è¿æå³çå³ä½¿è¡¨é¢ä¸çèµ·æ¥åªæä¸å°æºå¨å¨è¿è¡ï¼**ååºï¼partitioningï¼** ä»ç¶æ¯å¿ è¦çã å ±äº«å åæ¹æ³çé®é¢å¨äºï¼ææ¬å¢é¿é度快äºçº¿æ§å¢é¿ï¼ä¸å°æçååå¤çå¨æ°éï¼ååå å大å°ï¼ååç£ç容éçæºå¨ï¼é常ææ¬ä¼è¿è¿è¶ è¿åæ¥ç两åãèä¸å¯è½å 为åå¨ç¶é¢ï¼å¹¶ä¸è¶³ä»¥å¤çååçè½½è·ã å ±äº«å åæ¶æå¯ä»¥æä¾æéç容éè½åï¼é«ç«¯æºå¨å¯ä»¥ä½¿ç¨çææçç»ä»¶ï¼ä¸å ³æºæ´æ¢ç£çï¼å å模åï¼çè³å¤çå¨ï¼ââ ä½å®å¿ ç¶å¿äºå个å°çä½ç½®çæ¡æ¢ã å¦ä¸ç§æ¹æ³æ¯ **å ±äº«ç£çæ¶æï¼shared-disk architectureï¼**ï¼å®ä½¿ç¨å¤å°å ·æç¬ç«å¤çå¨åå åçæºå¨ï¼ä½å°æ°æ®åå¨å¨æºå¨ä¹é´å ±äº«çç£çéµåä¸ï¼è¿äºç£çéè¿å¿«éç½ç»è¿æ¥ [^ii]ãè¿ç§æ¶æç¨äºæäºæ°æ®ä»åºï¼ä½ç«äºåéå®çå¼ééå¶äºå ±äº«ç£çæ¹æ³çå¯ä¼¸ç¼©æ§ã2ãã [^ii]: ç½ç»éå±åå¨ï¼Network Attached Storage, NASï¼ï¼æ **åå¨åºç½ç»ï¼Storage Area Network, SANï¼** ### æ å ±äº«æ¶æ ç¸æ¯ä¹ä¸ï¼**æ å ±äº«æ¶æ**ã3ãï¼shared-nothing architectureï¼ææ¶è¢«ç§°ä¸º **水平伸缩**ï¼å³ horizontal scalingï¼æ **åå¤ä¼¸ç¼©**ï¼å³ scaling outï¼å·²ç»ç¸å½æ®åãå¨è¿ç§æ¶æä¸ï¼è¿è¡æ°æ®åºè½¯ä»¶çæ¯å°æºå¨ / èææºé½ç§°ä¸º **èç¹ï¼nodeï¼**ãæ¯ä¸ªèç¹åªä½¿ç¨åèªçå¤çå¨ï¼å ååç£çãèç¹ä¹é´çä»»ä½åè°ï¼é½æ¯å¨è½¯ä»¶å±é¢ä½¿ç¨ä¼ ç»ç½ç»å®ç°çã æ å ±äº«ç³»ç»ä¸éè¦ä½¿ç¨ç¹æ®ç硬件ï¼æä»¥ä½ å¯ä»¥ç¨ä»»ææºå¨ ââ æ¯å¦æ§ä»·æ¯æ好çæºå¨ãä½ ä¹è®¸å¯ä»¥è·¨å¤ä¸ªå°çåºååå¸æ°æ®ä»èåå°ç¨æ·å»¶è¿ï¼æè å¨æ失ä¸æ´ä¸ªæ°æ®ä¸å¿çæ åµä¸å¹¸å äºé¾ãéçäºç«¯èææºé¨ç½²çåºç°ï¼å³ä½¿æ¯å°å ¬å¸ï¼ç°å¨æ é Google 级å«çè¿ç»´ï¼ä¹å¯ä»¥å®ç°å¼å°åå¸å¼æ¶æã å¨è¿ä¸é¨åéï¼æ们å°éç¹æ¾å¨æ å ±äº«æ¶æä¸ãå®ä¸è§å¾æ¯ææåºæ¯çæä½³éæ©ï¼ä½å®æ¯æéè¦ä½ è°¨æ ä»äºçæ¶æãå¦æä½ çæ°æ®åå¸å¨å¤ä¸ªèç¹ä¸ï¼ä½ éè¦æè¯å°è¿æ ·ä¸ä¸ªåå¸å¼ç³»ç»ä¸çº¦æåæè¡¡ ââ æ°æ®åºå¹¶ä¸è½éæ¯è¬å°æè¿äºä¸è¥¿éèèµ·æ¥ã è½ç¶åå¸å¼æ å ±äº«æ¶ææ许å¤ä¼ç¹ï¼ä½å®é常ä¹ä¼ç»åºç¨å¸¦æ¥é¢å¤çå¤æ度ï¼ææ¶ä¹ä¼éå¶ä½ å¯ç¨æ°æ®æ¨¡åç表达åãå¨æäºæ åµä¸ï¼ä¸ä¸ªç®åçå线ç¨ç¨åºå¯ä»¥æ¯ä¸ä¸ªæ¥æè¶ è¿ 100 个 CPU æ ¸çé群表ç°å¾æ´å¥½ã4ããå¦ä¸æ¹é¢ï¼æ å ±äº«ç³»ç»å¯ä»¥é常强大ãæ¥ä¸æ¥çå ç« ï¼å°è¯¦ç»è®¨è®ºåå¸å¼æ°æ®ä¼å¸¦æ¥çé®é¢ã ### å¤å¶ vs ååº æ°æ®åå¸å¨å¤ä¸ªèç¹ä¸æ两ç§å¸¸è§çæ¹å¼ï¼ * å¤å¶ï¼Replicationï¼ å¨å 个ä¸åçèç¹ä¸ä¿åæ°æ®çç¸åå¯æ¬ï¼å¯è½æ¾å¨ä¸åçä½ç½®ã å¤å¶æä¾äºåä½ï¼å¦æä¸äºèç¹ä¸å¯ç¨ï¼å©ä½çèç¹ä»ç¶å¯ä»¥æä¾æ°æ®æå¡ã å¤å¶ä¹æå©äºæ¹åæ§è½ã [第äºç« ](ch5.md) å°è®¨è®ºå¤å¶ã * ååº (Partitioning) å°ä¸ä¸ªå¤§åæ°æ®åºæåæè¾å°çåéï¼ç§°ä¸º **ååº**ï¼å³ partitionsï¼ï¼ä»èä¸åçååºå¯ä»¥ææ´¾ç»ä¸åç **èç¹**ï¼nodesï¼äº¦ç§° **åç**ï¼å³ shardingï¼ã [第å ç« ](ch6.md) å°è®¨è®ºååºã å¤å¶åååºæ¯ä¸åçæºå¶ï¼ä½å®ä»¬ç»å¸¸åæ¶ä½¿ç¨ãå¦ [å¾ II-1](img/figii-1.png) æ示ã ![](img/figii-1.png) **å¾ II-1 ä¸ä¸ªæ°æ®åºåå为两个ååºï¼æ¯ä¸ªååºé½æ两个å¯æ¬** ç解äºè¿äºæ¦å¿µï¼å°±å¯ä»¥å¼å§è®¨è®ºå¨åå¸å¼ç³»ç»ä¸éè¦ååºçå°é¾ææ©ã[第ä¸ç« ](ch7.md) å°è®¨è®º **äºå¡ (Transaction)**ï¼è¿å¯¹äºäºè§£æ°æ®ç³»ç»ä¸å¯è½åºç°çåç§é®é¢ï¼ä»¥åæ们å¯ä»¥åäºä»ä¹å¾æ帮å©ã[ç¬¬å «ç« ](ch8.md) å [第ä¹ç« ](ch9.md) å°è®¨è®ºåå¸å¼ç³»ç»çæ ¹æ¬å±éæ§ã å¨æ¬ä¹¦ç [第ä¸é¨å](part-iii.md) ä¸ï¼å°è®¨è®ºå¦ä½å°å¤ä¸ªï¼å¯è½æ¯åå¸å¼çï¼æ°æ®åå¨éæ为ä¸ä¸ªæ´å¤§çç³»ç»ï¼ä»¥æ»¡è¶³å¤æçåºç¨éæ±ã ä½é¦å ï¼æ们æ¥èèåå¸å¼çæ°æ®ã ## ç´¢å¼ 5. [å¤å¶](ch5.md) 6. [ååº](ch6.md) 7. [äºå¡](ch7.md) 8. [åå¸å¼ç³»ç»ç麻ç¦](ch8.md) 9. [ä¸è´æ§ä¸å ±è¯](ch9.md) ## åèæç® 1. Ulrich Drepper: â[What Every Programmer Should Know About Memory](https://people.freebsd.org/~lstewart/articles/cpumemory.pdf),â akkaâdia.org, November 21, 2007. 1. Ben Stopford: â[Shared Nothing vs. Shared Disk Architectures: An Independent View](http://www.benstopford.com/2009/11/24/understanding-the-shared-nothing-architecture/),â benstopford.com, November 24, 2009. 1. Michael Stonebraker: â[The Case for Shared Nothing](http://db.cs.berkeley.edu/papers/hpts85-nothing.pdf),â IEEE Database EngineeringBulletin, volume 9, number 1, pages 4â9, March 1986. 1. Frank McSherry, Michael Isard, and Derek G. Murray: â[Scalability! But at What COST?](http://www.frankmcsherry.org/assets/COST.pdf),â at 15th USENIX Workshop on Hot Topics in Operating Systems (HotOS),May 2015. ------ | ä¸ä¸ç« | ç®å½ | ä¸ä¸ç« | | ---------------------------- | ------------------------------- | ---------------------- | | [第åç« ï¼ç¼ç ä¸æ¼å](ch4.md) | [设计æ°æ®å¯éååºç¨](README.md) | [第äºç« ï¼å¤å¶](ch5.md) |