ãŠãŒãªã»ã¯ã©ã¹ãã·ã¥ãã§ãã¯ïŒDelphi LLCãDellïŒ
ãã£ãã·ã³ã°ã«ã€ããŠå°ã説æããŸãã äžè¬ã«ããã£ãã·ã¥ã¯ããŸãé¢çœããªãã®ã§ãååŸããŠãã£ãã·ã¥ããã®ã§ãmemcachedã®éåžžã«è©³çŽ°ãªæ å ±ã«ã€ããŠã説æããŸãã
ãã£ãã·ã³ã°ã«ã€ããŠã¯ããªã ãããŠã ãã«ã·ã¡ãŒã¿ãŒã®è£œé å·¥å Žãéçºããããšããå§ããŸãããã ããã¯æšæºçãªã¿ã¹ã¯ã§ãããäž»ãªããšã¯éå±ãªé¡ãããŠãå·¥å Žã®éçºã«å žåçãªã¹ããŒã ãé©çšããŸãããšèšãããšã§ãã
äžè¬ã«ãå·¥å Žçç£ã«è¿ããã€ãŸã åé¡ã¯ã©ãããæ¥ãã®ã§ããïŒ å·¥å Žã¯éåžžã«é«éã§åäœãããã«ã·ã¡ãŒã¿ãŒã補é ããŸãã ãŸããåããã€ã¹ã®ãã£ãªãã¬ãŒã·ã§ã³ã«ã¯ãããããªãªã ãããŠã ãå¿ èŠã§ãããã®ãªã ãããŠã ãé ãã«é£ã°ãå¿ èŠããããŸãããããã£ãŠããã®ãªã ãããŠã ãæœåºããéçšã§ãããã€ã¹ã¯ãã£ãªãã¬ãŒã·ã§ã³ããããå®éããã¹ãŠã®çç£ãåæ¢ããŸãã ãã®ãããå·¥å Žã®è¿ãã«å庫ã建èšããŠããŸãã ããããããã¯ç¡æã§ã¯ãããŸããã
çšèªã«ç§»ããŸãã 1ã€ã®èšèªã§ãã£ãã·ã¥ã«ã€ããŠèª¬æããããã«ãããªã確ç«ãããçšèªããããŸãã
ãœãŒã¹ã¯originãšåŒã°ããŸãã å庫éãããªãã¡ ãã£ãã·ã¥ãµã€ãº- ãã£ãã·ã¥ ãµã€ãº ã åžæã®åœ¢ç¶ã®ãµã³ãã«ã®ããã«å庫ã«è¡ããšãã¹ãã¢ããŒããŒã¯ç§ãã¡ãèŠæ±ãããã®ãæäŸããŸã-ããã¯ãã£ãã·ã¥ ããããšåŒã°ãã圌ãèšããªãïŒããã®ãããªããšã¯ãããŸããããããã¯ãã£ãã·ã¥ãã¹ãšåŒã°ããŸãã
ããŒã¿-ç§ãã¡ã®ãªã ãããŠã -ã¯æåéãæ°é®®ããæã£ãŠããŸã -ããã¯æ°é®®ãã§ãã æ°é®®ããã©ãã§ã䜿ãããŠããŸãã ããŒã¿ãæ¬æ¥ã®æ°é®®ãã倱ããšããã«ã å€ã ããŒã¿ã«ãªããŸã ã
ããŒã¿ã®æå¹æ§ããã§ãã¯ããããã»ã¹ã¯æ€èšŒãšåŒã°ããããŒã¿ã䜿çšäžå¯ã§ããããŠã§ã¢ããŠã¹ããç Žæ£ããããšèšãç¬éãç¡å¹åãšåŒã³ãŸãã
ã¹ããŒã¹ãæ®ã£ãŠããªããšãã«ãã®ãããªäžå¿«ãªç¶æ³ãçºçããå ŽåããããŸãããæ°é®®ãªãªã ãããŠã ãä¿ç®¡ããæ¹ããããããäœããã®åºæºã§æãå€ããªã ãããŠã ãèŠã€ããŠæšãŠãŸãã ããã¯ãšãã¯ã·ã§ã³ãšåŒã°ããŸãã
ã¹ããŒã ã¯ããã©ãŠã¶ããããã¯ãšã³ããŸã§ããã§ãŒã³å ã«å€ãã®ãªã³ã¯ããããããªãã®ã§ãã 質åïŒã©ãã«ãã£ãã·ã¥ããŸããïŒ å®éãã©ãã§ã絶察ã«ãã£ãã·ã¥ããå¿ èŠããããŸãã ãããŠãããªãããããæããã©ããã«ããããããããŒã¿ã¯ãã£ãã·ã¥ãããŸãã 質åã¯ãããããã©ã®ããã«ããã«åœ±é¿ãäžããããšãã§ããŸããïŒ
ãŸããé©åãªãã£ãã·ã¥ããŒã¿ãèŠã€ããå¿ èŠããããŸãã äœããã®ãã£ãã·ã¥ãå®è¡ããŠãããšããäºå®ã«ããããã§ãŒã³ã«ã¯ããã«å¥ã®äžéãªã³ã¯ãããããã£ãã·ã¥ãç©äºãé«éåããå¿ èŠã¯ãããŸããã ããŒã¿ãé©åã«éžæããªããã°ãããããé床ã«åœ±é¿ãããææªã®å Žåãã·ã¹ãã å šäœã®çç£ããã»ã¹ãé ããªããŸãã
é »ç¹ã«å€æŽãããããŒã¿ããã£ãã·ã¥ããããšã¯æå³ããããŸããã é »ç¹ã«äœ¿çšãããããŒã¿ããã£ãã·ã¥ããå¿ èŠããããŸãã ããŒã¿ã®ãµã€ãºãã€ãŸã ãã«ãŒã¬ã€ã¡ã¢ãªã«ã ãŒããŒããã£ãã·ã¥ããããšã«ããå Žå-ã¯ãŒã«ã§ããéåžžã«ãã°ããã¡ã¢ãªããåãåºããŸãããã»ãšãã©ã®å Žåããããã¯ãŒã¯çµç±ã§ã©ããã§ãã³ãããå¿ èŠããããéåžžã«é ããªããŸãã ãã®ãããªå€§éã®ããŒã¿ã¯ãé ä¿¡ã®é床ãšé£ãåã£ãŠããŸããã ãã®ãããªããŒã¿ãã¡ã¢ãªã«ä¿æããããšã¯æå³ããããŸããã ãã£ã¹ã¯ã¯ä¿æã§ããŸãããé床ãæ¯èŒããå¿ èŠããããŸãã
ãšããã§ãããã°ã©ãã³ã°ã®ã¬ã€ãã³ã·ãŒãã°ãŒã°ã«ã§æ€çŽ¢ã§ããŸãã ããã§ããµã€ãã§ã¯ãCPUãã£ãã·ã¥ãžã®ã¢ã¯ã»ã¹é床ãããŒã¿ã»ã³ã¿ãŒã§ã®ã©ãŠã³ãããªãããã±ããã®éä¿¡é床ãªã©ããã¹ãŠã®æšæºé 延ãéåžžã«é©åã«æäŸãããŸãã ãããŠãããªããäœããè£ ã£ãŠãã¶ã€ã³ãããšããããã¯èŠãã®ãè¯ãã§ããããã¯ã©ããããã®æéãšããããããããšæ¯èŒããŠããã«éåžžã«ã¯ã£ãããšç€ºãããŠããŸãã
ãããã¯ãã£ãã·ã¥çšã®æ¢è£œã®ã¬ã·ãã§ãïŒ
ãããã¯é¢é£ããHTTPããããŒã§ãã
ããã€ãã«ã€ããŠå°ãã話ããŸãããå®éã«ã¯ããã«ã€ããŠèªãå¿ èŠããããŸãã åºæ¬çã«ãWebã§ãã£ãã·ã¥ã«åœ±é¿ãäžããããšãã§ããå¯äžã®æ¹æ³ã¯ããããã®ããããŒãæ£ããã€ã³ã¹ããŒã«ããããšã§ãã
以åã«äœ¿çšãããæå¹æéã ããŒã¿ã«æ°é®®ããèšå®ããæåéãããã®ã³ã³ãã³ãã¯ãã®æ¥ä»ãŸã§æå¹ã§ãããšèšããŸãã ãããŠä»ããã®ããããŒã䜿çšããå¿ èŠããããŸããããã©ãŒã«ããã¯ãšããŠã®ã¿ã æ°ããããããŒããããŸãã ç¹°ãè¿ãã«ãªããŸããããã®ãã§ãŒã³ã¯éåžžã«é·ãããã®ããããŒã®ã¿ãç解ããäœããã®çš®é¡ã®ãããã·ïŒExpiresïŒã䜿çšã§ããŸãã
ãã£ãã·ã¥ãæ åœããæ°ããããããŒã¯Cache-Controlã§ãã
ããã§ã¯ã鮮床ãæ€èšŒã¡ã«ããºã ãããã³ç¡å¹åã¡ã«ããºã ã®äž¡æ¹ãããã«æå®ããããããããªãã¯ããŒã¿ã§ããããã©ã€ããŒãã§ãããã瀺ãããããããã£ãã·ã¥ããæ¹æ³ãæå®ã§ããŸã...
ãšããã§ããã£ãã·ã¥ãªãã¯éåžžã«èå³æ·±ãã§ãã ååã§èšããšãããã£ãã·ã¥ã¯ã©ãã§ãããã£ãã·ã¥ãªãããšèšãå Žåã¯å¥œããªããã«ãã£ãã·ã¥ããŠãã ããã ãã ãããã®ã³ã³ãã³ãã®ããŒã¿ã䜿çšãããã³ã«ãããšãã°ãã©ãŒã ãããããã®ãã©ãŒã ã§éä¿¡ãããšããã£ãã·ã¥ããããã¹ãŠã®ããŒã¿ãé¢é£ããŠããªãå Žåã¯ãå確èªããå¿ èŠããããšèšããŸãã
äžè¬ã«ãã³ã³ãã³ãã®ãã£ãã·ã¥ããªãã«ãããå Žåããã¹ãã¢ãªãããšèšããŸãã
ãããã®ããã£ãã·ã¥ãªããããã¹ãã¢ãªããã¯ãèªèšŒãã©ãŒã ãã€ãŸã èªèšŒãããŠããªããŠãŒã¶ãŒããã£ãã·ã¥ããããªãã®ã§ãå¥åŠã«ãªã£ãããèŠããããã誀解ãçãããããããšã¯ãããŸããã ãšããã§ããã®Cache-Controlã«ã€ããŠïŒno-cache ...ããšãã°ãCache-ControlããããŒããµããŒããããŠããªãå Žåããã®åäœãã·ãã¥ã¬ãŒãã§ããŸãã ããããŒã®æå¹æéãååŸããŠãéå»ã®æ¥ä»ãèšå®ã§ããŸãã
Content-Lengthãå«ããããã®ããããŒã¯ãã¹ãŠããã£ãã·ã¥ã«é¢é£ããŠããŸãã äžéšã®ãã£ãã·ã³ã°ãããã·ã¯ãContent-Lengthããªãå Žåãåã«ãã£ãã·ã¥ããããªãå ŽåããããŸãã
å®éãmemcachedãã€ãŸãããã¯ãšã³ãåŽã®ãã£ãã·ã¥ã«ã¢ã¯ã»ã¹ããŸãã
ç¹°ãè¿ããŸãããããŸããŸãªæ¹æ³ã§ãã£ãã·ã¥ã§ããŸãã ããŒã¿ããŒã¹ããããã€ãã®ããŒã¿ãååŸããã³ãŒãã§äœããè¡ããŸãããå®éã«ã¯ãã£ãã·ã¥ã§ããäœåºŠãåå©çšããããã«äžåºŠååŸããŸããã ã³ãŒãå ã®ããçš®ã®ã³ã³ããŒãã³ãããã¬ãŒã ã¯ãŒã¯ã䜿çšã§ããŸãã ãã£ãã·ã³ã°çšã®ãã®ã³ã³ããŒãã³ããå¿ èŠãªã®ã¯ã補åã«åççãªå¶éãå¿ èŠã ããã§ãã ããã¯ãã¹ãŠãããçš®ã®ãªãã¬ãŒãã£ã³ã°ãšã³ãžãã¢ãæ¥ãŠãã補åã®èŠä»¶ã説æããŠãã ããããšèšã£ãŠãããšããäºå®ããå§ãŸããŸãã ãããŠãããªãã¯åœŒã«ããããéåžžã«å€ãã®RAMãéåžžã«å€ãã®ãã£ã¹ã¯ã¹ããŒã¹ããããŠãã®ãããªäºæž¬ãããã¢ããªã±ãŒã·ã§ã³ã®æé·ã§ããããšãäŒããå¿ èŠããããŸã...ãããã£ãŠãäœãããã£ãã·ã¥ããå Žåãå¶éãå¿ èŠã§ãã ç°¡åã«æäŸã§ããæåã®å¶éã¯ããã£ãã·ã¥å ã®èŠçŽ ã®æ°ã«ãããã®ã ãšããŸãã ããããç°ãªããµã€ãºã®èŠçŽ ãããå Žåã¯ãäžå®éã®ã¡ã¢ãªã§ãããéããŸãã ã€ãŸã ä»»æã®ãã£ãã·ã¥ãµã€ãºãèšããŸã-ããã¯æãéèŠãªå¶éã§ãããæãéèŠãªå¢çã§ãã ãã®ãããªããšãã§ããã©ã€ãã©ãªã䜿çšããŸãã
ããŠããŸãã¯ãäžè¬çã«ã¹ã¿ã³ãã¢ãã³ã®å¥åã®ãã£ãã·ã³ã°ãµãŒãã¹ã䜿çšããŸãã ãªãããçš®ã®åå¥ã®ãã£ãã·ã³ã°ãµãŒãã¹ãå¿ èŠãªã®ã§ããïŒ ã»ãšãã©ã®å Žåãããã¯ãšã³ãã¯ããã»ã©ã¢ããªã·ãã¯ã§ã¯ãªãã1ã€ã®ããã»ã¹ã§ãã ããã€ãã®ç°ãªãããã»ã¹ãããã€ãã®ã¹ã¯ãªããããããåå¥ã®ãã£ãã·ã³ã°ãµãŒãã¹ãããå Žåãã€ãŸããããã¯ãšã³ãã€ã³ãã©ã¹ãã©ã¯ãã£å šäœããã®ãã£ãã·ã¥ãåç §ããããããã®ããŒã¿ã䜿çšã§ããŸãã ããã¯çŽ æŽãããã
2çªç®ã®ãã€ã³ã-æé·ããæ©äŒããããŸãã ããšãã°ã1ã€ã®ãµãŒãã¹ãæå ¥ããçŸéã䜿ãæãããå¥ã®ãµãŒãã¹ãæå ¥ããŸãã åœç¶ãããã¯ç¡æã§ã¯ãããŸããã ããããŠä»æ¥ãç§ãã¡ã¯ã¹ã±ãŒãªã³ã°ããããšã決ããŸãããã¯èµ·ããããŸããã äºåã«ãã®ãããªããšãèšç»ããå¿ èŠããããŸãããå¥ã®ãã£ãã·ã³ã°ãµãŒãã¹ããã®ãããªæ©äŒãæäŸããŸãã
ãã£ãã·ã¥ã¯ãŸããã»ãŒç¡æã§å¯çšæ§ãæäŸããŸãã ãã£ãã·ã¥ã«ããŒã¿ãããããã®ããŒã¿ããã£ãã·ã¥ããååŸããããšããŠãããšããŸãã äœããç§ãã¡ã®ã©ããã«èœã¡ãäœãèœã¡ãªãã£ããµããããŠããã£ãã·ã¥ããããŒã¿ãæäŸããŸãã ãã®æç¹ã§äœããã®åœ¢ã§è§£é€ãããå¯èœæ§ããããå¯çšæ§ããããŸãã
å®éãmemcachedã«å°éããŸããã Memcachedã¯å žåçãªnoSQLã§ãã
noSQLãã£ãã·ã³ã°ãåªããŠããã®ã¯ãªãã§ããïŒ
æ§é ã«ãã£ãŠã éåžžã®ããã·ã¥ããŒãã«ããããŸãã åŸ ã¡æéãçããªããŸãã memcachedãªã©ã®ããŒãšå€ã®ã¹ãã¬ãŒãžã®å Žåãé 延ãå°ãªãã ãã§ãªãã倧èŠæš¡ãªè¡šèšã§ã¯ãã»ãšãã©ã®æäœãè€éã«ãªããŸããããã¯1ã€ã®å®æ°ã§ãã ãããã£ãŠãäœããã®äžæçãªå¶çŽããããšèšããŸãã ããšãã°ããªã¯ãšã¹ãã«ã¯10ââããªç§ããããããŸããã ãããã®åŸ ã¡æéã«åºã¥ããŠäœããã®å¥çŽã«åæããããšãã§ããŸãã ããã¯ããã§ãã
ã»ãšãã©ã®å Žåãæããããã®ã¯äœã§ããã£ãã·ã¥ããŸã-CCSãšJSãæ··ãã£ãåçãã¬ã³ããªã³ã°ããããã©ãŒã ã®äžéšããã®ä»ã®ãã®ã ã©ã®ããŒã¿ãæ確ã§ã¯ãªããããããŒãšå€ã®æ§é ã«ãããéåžžã«ç°¡åã«ä¿åã§ããŸãã account.300.avatarãããããšãèšãããšãã§ããŸããããã¯åçã§ãããããã§æ©èœããŸãã ãã®äŸã§ã¯ã300ãã¢ã«ãŠã³ãIDã§ãã
éèŠãªç¹ã¯ãããŒãšå€ã®noSQLãããå Žåãã¹ãã¬ãŒãžã³ãŒãèªäœãåçŽåãããããšã§ããææªã®å Žåã¯ãäœããã®æ¹æ³ã§ããŒã¿ãå°ç¡ãã«ããã倱ã£ããããããã§ãã ããŒã¿ãåŠçããã³ãŒããå°ãªãã»ã©ãããŒã¿ãæãªãå¯èœæ§ãäœããªããããåçŽãªæ§é ã®åçŽãªãã£ãã·ã¥ãé©ããŠããŸãã
memcached Key-Valueã«ã€ããŠã æå¹æéããŒã¿ã§æå®ã§ããŸãã äžå®éã®ã¡ã¢ãªã§ã®äœæ¥ããµããŒãããŸããã 16ããããã©ã°ã«ã¯ä»»æã®å€ãèšå®ã§ããŸã-memcachedã«å¯ŸããŠééçã§ãããã»ãšãã©ã®å Žåãäžéšã®ã¯ã©ã€ã¢ã³ãããmemcachedã䜿çšããŸããããããããã®ã¯ã©ã€ã¢ã³ãã¯æ¢ã«ãããã®16ããããååŸããŠããŸãã 圌ã¯äœãšããããã䜿çšããŸãã ãã®ãããªæ©äŒããããŸãã
memcachedã¯vikshinsã®ãµããŒããã€ãŸã ã¹ããŒã¹ãäžè¶³ãããšãæãå€ãããŒã¿ãããã·ã¥ããææ°ã®ããŒã¿ãè¿œå ããŸãã ãŸãã¯ããããŒã¿ãåé€ããªãããšèšãããšãã§ããŸããæ°ããããŒã¿ãè¿œå ãããšãã¡ã¢ãªäžè¶³ãšã©ãŒãè¿ãããŸã-ããã¯ã-Mããã©ã°ã§ãã
memcachedã«ã¯æ§é åãããçµ±äžãããããã¥ã¡ã³ãã¯ãããŸããããããã³ã«ã®èª¬æãèªãããšããå§ãããŸãã åºæ¬çã«ãGoogleã§ãmemcachedãããã³ã«ããšå ¥åãããšããããæåã®ãªã³ã¯ã«ãªããŸãã ãããã³ã«ã¯ãã³ãã³ãã®åœ¢åŒã ãã§ãªããéä¿¡ãããã®ãå¿çãããã®ãèšè¿°ããŸã...ãã®ã³ãã³ãã¯ããã®ããã«åäœãããã€ãŸã ããã€ãã®ã³ãŒããŒã±ãŒã¹ããããŸãã
ã³ãã³ãã®æŠèŠïŒ
get-ããŒã¿ãååŸããŸãã
èšå®/ è¿œå / åé€/ 眮æ -ãã®ããŒã¿ãæ¶å»ããæ¹æ³ãã€ãŸãïŒ
- èšå®ã¯ãä¿åãæ°èŠè¿œå ããŸãã¯çœ®æã§ãã
- addã¯ããã®ãããªããŒããªãå Žåã«ã®ã¿è¿œå ããããšã§ãã
- åé€ -åé€;
- replace-ãã®ãããªããŒãååšããå Žåã®ã¿çœ®æã ãããã§ãªãå Žåã¯ãšã©ãŒã
ã·ã£ãŒããããç°å¢ã§ãã ã¯ã©ã¹ã¿ãŒãããå Žåãããã¯äžè²«æ§ãä¿èšŒããŸããã ãã ãã1ã€ã®ã€ã³ã¹ã¿ã³ã¹ã§ã¯ããããã®ã³ãã³ãã§äžè²«æ§ããµããŒãã§ããŸãã ãã®ãããªå¶çŽãæ§ç¯ããããšã¯ãå€ããå°ãªããå¯èœã§ãã
prepend / append-ãããååŸããŠãããŒã¿ã®åã«ããŒã¹ãæ¿å ¥ããããããŒã¿ã®åŸã«ããŒã¹ãæ¿å ¥ããŸãã ãããã¯ãmemcachedå ã«ããŸãå¹ççã«å®è£ ãããŠããŸããã æ°ããã¡ã¢ãªãå²ãåœãŠããããŸãŸã«ãªããããããšsetã®éã«æ©èœçãªéãã¯ãããŸããã
ä¿åããããŒã¿ã«ããçš®ã®æå¹æéã瀺ãããšãã§ããŸãããã®åŸãã¿ããã³ãã³ãã䜿çšããŠãã®ããŒã¿ã«è§Šããããšãã§ãããã®ããŒã«ç¹ã«å¯¿åœã延ã°ããŸãã 圌ã¯åé€ãããŸããã
å¢åã³ãã³ããšæžåã³ãã³ãããããŸã-incr / decrã§ãã ããã¯æ¬¡ã®ããã«æ©èœããŸãïŒæååãšããŠããã€ãã®æ°åãæ¶å»ããŠããã incrãšèšã£ãŠå€ãäžããŸãã ãŸãšãããšã ãã¯ãªã¡ã³ãã¯åãã§ãããæžç®ããŸãã èå³æ·±ãç¹ããããŸããããšãã°ãmemcachedã®èŠ³ç¹ããã¯2-3 = 0ã§ãã ã¢ã³ããŒãããŒã¯èªåçã«åŠçãããŸãããè² ã®æ°ãäœæããããšã¯ã§ããŸããããããã«ããŠãããŒããè¿ãããŸãã
äœããã®äžè²«æ§ãæãããããšãã§ããå¯äžã®ã³ãã³ãã¯casã§ã ïŒããã¯ã¢ãããã¯ãªæ¯èŒããã³ã¹ã¯ããæäœã§ãïŒã 2ã€ã®å€ãæ¯èŒãããããã®å€ãäžèŽããå Žåã¯ãããŒã¿ãæ°ããå€ã«çœ®ãæããŸãã æ¯èŒããå€ã¯å éšã®ã°ããŒãã«ã«ãŠã³ã¿ãŒã§ã
memcachedãããã«ããŒã¿ãè¿œå ãããã³ã«ããã®ã«ãŠã³ã¿ãŒãå¢å ããããŒãšå€ã®ãã¢ãäœããã®å€ãååŸããŸãã getsã³ãã³ãã䜿çšããŠãã®å€ãååŸãã casã³ãã³ãã§äœ¿çšã§ããŸãã ãã®ããŒã ã«ã¯ãéåžžã®ååãæ±ããŠããåé¡ãšåãåé¡ããããŸãã ç¹ã«memcachedã«ã¯ã³ãã³ãã®å®è¡é åºãä¿èšŒãããŠããªããããå€ãã®ã¬ã€ãºæ¡ä»¶ãèå³æ·±ããã®ã«ããããšãã§ããŸãã
Memcachedã«ã¯ã-CãããŒãããã casããªãã«ããŸãã ã€ãŸã ã©ãããã® ãã®ã«ãŠã³ã¿ã¯ããŒãšå€ã®ãã¢ããæ¶ããŸããã-CãããŒãè¿œå ãããšãåå€ã64ãããã«ãŠã³ã¿ã§ããããã8ãã€ããç¯çŽã§ããŸãã å€ãå°ããå ŽåãããŒã¯å°ãããããå€§å¹ ã«ç¯çŽã§ããŸãã
memcachedãå¹ççã«äœ¿çšããã«ã¯ïŒ
å€ãã®ã»ãã·ã§ã³ã§åäœããããã«èšèšãããŠããŸãã å€ãã¯æ°çŸã§ãã ã€ãŸã æ°çŸããå§ãŸããŸãã ãããŠäºå®ã¯ãRPSïŒ1ç§ãããã®ãªã¯ãšã¹ãïŒã®èŠ³ç¹ããã2ã3ã»ãã·ã§ã³ã䜿çšããŠmemcachedããå€ããåŸãããšã¯ãããŸããã ãããæºãããã«ã¯ãå€ãã®æ¥ç¶ãå¿ èŠã§ãã ã»ãã·ã§ã³ã¯é·æéå®è¡ããå¿ èŠããããŸããmemcachedå ã«ã»ãã·ã§ã³ãäœæããã®ã¯ããªãè²»çšã®ãããããã»ã¹ã§ãããããäžåºŠããã¯ãããšããã ããªã®ã§ããã®ã»ãã·ã§ã³ãç¶æããå¿ èŠããããŸãã
ãªã¯ãšã¹ãã¯ãããã§ãªããã°ãªããŸããã èŠæ±ããããã§éä¿¡ããå¿ èŠããããŸãã getã³ãã³ãã§ã¯ãããã€ãã®ããŒã転éããæ©äŒããããŸããããã䜿çšããå¿ èŠããããŸãã ã€ãŸã getãškey-key-keyãšèšããŸãã ä»ã®ããŒã ã«ã¯ãã®ãããªå¯èœæ§ã¯ãããŸããããããããå®è¡ã§ããŸãã ããã€ãã®ã³ãã³ãã䜿çšããŠãã¯ã©ã€ã¢ã³ãåŽã§ããŒã«ã«ã«ãªã¯ãšã¹ããäœæãããã®ãªã¯ãšã¹ãå šäœãéä¿¡ã§ããŸãã
memcachedã¯ãã«ãã¹ã¬ããã§ãããããŸããã«ãã¹ã¬ããã§ã¯ãããŸããã 圌女ã¯å éšã«å€ãã®ããã¯ãæã¡ãéåžžã«ã¢ãããã¯ãªã®ã§ã4ã€ä»¥äžã®ã¹ã¬ãããå éšã§éåžžã«åŒ·ã競åãåŒãèµ·ãããŸãã ä¿¡ããå¿ èŠã¯ãããŸããããã¹ãŠãèªåã§å確èªããå¿ èŠããããŸããã©ã€ãã·ã¹ãã ã§ã©ã€ãããŒã¿ã䜿çšããŠå®éšããå¿ èŠããããŸãããéåžžã«å€ãã®ã¹ã¬ãããæ©èœããŸããã ããããè©ŠããŠãã-tãããŒã§æé©ãªæ°å€ãéžæããå¿ èŠããããŸãã
memcachedã¯UDPããµããŒãããŠããŸãã ããã¯ãfacebookã«ãã£ãŠmemcachedã«è¿œå ããããããã§ãã facebook memcachedã®äœ¿çšæ¹æ³-ãã¹ãŠã®ã»ãããäœæããŸãã ãã¹ãŠã®ããŒã¿å€æŽã¯TCPçµç±ã§è¡ãããUDPçµç±ã§ååŸãããŸãã ãŸããããŒã¿éãéåžžã«å€§ããå Žåããã±ãããµã€ãºãå°ãããããUDPãå€§å¹ ã«åäžããããšãããããŸãã 圌ãã¯ãã°ãªãããéããŠããå€ãã®ããŒã¿ãéãåºãããšã«æåããŠããŸãã
incr / decrã«ã€ããŠèª¬æããŸãã-ãããã®ã³ãã³ãã¯ãããã¯ãšã³ãã®çµ±èšãä¿åããã®ã«çæ³çã§ãã
HighLoadã®çµ±èšã¯ããããã®ãªããã®ã§ãã çµ±èšããªããã°ãç¹å®ã®åé¡ã®åå ãåå ãçºçå Žæãç解ããããšãã§ããŸããã30åéã®äœæ¥ã®åŸããã·ã¹ãã ãå¥åŠã«åäœãããããã§ãã次ã«çµ±èšã çµ±èšãå€ãã»ã©è¯ãã§ãã ãããŠãååãšããŠãåé¡ãããããšãç解ããããã«ã¯ãçµ±èšãå¿ èŠã§ãã ããšãã°ãããã¯ãšã³ãã¯30ããªç§ã§ããŒãžãè¿ãã40ã§éå§ããèŠãç®ã§åºå¥ããããšã¯ã§ããŸããããããã©ãŒãã³ã¹ã¯4åã®1äœäžããŸãã-ã²ã©ãã§ãã
Memcachedèªäœãçµ±èšããµããŒãããŠããŸããã€ã³ãã©ã¹ãã©ã¯ãã£ã§æ¢ã«memcachedã䜿çšããŠããå Žåãmemcachedçµ±èšã¯çµ±èšã®äžéšã§ãããããã£ãŠããããèŠãŠãããã¯ãšã³ãããã£ãã·ã¥ãæ£ãã䜿çšããŠããããããŒã¿ãé©åã«ãã£ãã·ã¥ããŠãããã確èªããå¿ èŠããããŸãã
ãŸããåããŒã ã«ããããšãã¹ããããŸãã ãã£ãã·ã¥ã«ç®ãåããããŒã¿ãæäŸããããšãããã®ã³ãã³ãã®ããããå¢å ããŸããã ããšãã°ãåé€ããŒãäœæããŸãããåé€ããã1ããããããã³ãã³ãããšã«åé€ããŸãã åœç¶ããããã¯100ïŒ ã§ããå¿ èŠãããããã¹ã¯ãŸã£ãããããŸããã§ããã èŠãªããã°ãªããŸããã éåžžã«é«ããã¹çãæã€ããšãã§ãããšããŸãããã æãäžè¬çãªçç±ã¯ãééã£ãããŒã¿ãåçŽã«èª¿ã¹ãŠããããšã§ãã ãã£ãã·ã¥ã«å°ãã®ã¡ã¢ãªãå²ãåœãŠããã£ãã·ã¥ã絶ããåå©çšãããããªãªãã·ã§ã³ããããããããŸããã ããŒã¿ãè¿œå ããè¿œå ããè¿œå ããŸãããããæç¹ã§ãæåã®ããŒã¿ããã£ãã·ã¥ããèœã¡ãããããè¿œããããŠããããã¯ããååšããŠããŸããã ç§ãã¡ã¯ä»ã®äººã®åŸã«ç»ããŸããã圌ããããã«ããŸããã ãããŠãããããã¹ãŠãå€ããæ¹æ³ã§ãã ã€ãŸã ããã¯ãšã³ãåŽãããmemcachedã®è² è·ãæžããå¿ èŠããããŸãããŸãã¯ãã-mããã©ã¡ãŒã¿ãŒã§äœ¿çšã§ããã¡ã¢ãªã®éãå¢ããããšãã§ããŸãã
ç«ã¡éãã¯éåžžã«éèŠãªãã€ã³ãã§ãã ç§ã話ããŠããç¶æ³ã¯ãç«ã¡éãçãéåžžã«é«ããšããäºå®ããæããã§ãã ããã¯ãé©åãªããŒã¿ã®æå¹æéãåããŠããªããšãã®éã§ãã ãããã¯æ°é®®ã§ãè¯ããã®ã¯ãã£ãã·ã¥ããæåºããããã®åŸãç«ã¡éãã®åæ°ãå¢ããŸãã
ãããã䜿çšãã¹ãã ãšèšã£ãã batch'aã®ãµã€ãºã®éžææ¹æ³ã¯ïŒ ç¹å¹è¬ã¯ãããŸãããããããã¹ãŠå®éšçã«éžæããå¿ èŠããããŸãã ãã¹ãŠã¯ãã€ã³ãã©ã¹ãã©ã¯ãã£ã䜿çšãããããã¯ãŒã¯ãã€ã³ã¹ã¿ã³ã¹ã®æ°ãããã³ãã®ä»ã®èŠå ã«äŸåããŸãã ããããéåžžã«å€§ããªããããããå Žåã¯...ããããå®è¡ããŠããŠãä»ã®ãã¹ãŠã®æ¥ç¶ãç«ã£ãŠãããããããå®äºããã®ãåŸ ã£ãŠãããšæ³åããŠãã ããã ããã¯é£¢starãšåŒã°ããŸã-æé£ãããªãã¡ æ®ãã®æ¯æè ã飢ããŠããŠãèèªåã®å€ããã®ãå®äºããã®ãåŸ ã£ãŠãããšãã ãããåé¿ããããã«ãmemcachedå ã«ã¯åŒ·å¶çã«ãããå®è¡ãäžæããã¡ã«ããºã ããããŸãã ããã¯éåžžã«ç¡äœæ³ã«å®è£ ãããããŒã-RãããããŸããããã¯ã1ã€ã®æ¥ç¶ãé£ç¶ããŠå®è¡ã§ããããŒã ã®æ°ã瀺ããŸãã ããã©ã«ãå€ã¯20ã§ãããŸããçµ±èšãèŠããšãconn_yieldsçµ±èšãäœããã®çç±ã§éåžžã«é«ãå Žåãmemcachedãåãããšãã§ãããããå€ãã®ãããã䜿çšããããšãæå³ãããã®æ¥ç¶ã®ã³ã³ããã¹ããé »ç¹ã«åŒ·å¶çã«åãæ¿ããå¿ èŠããããŸãã ããã§ã¯ãã-RãããŒã䜿çšããŠãããã®ãµã€ãºãå¢ããããããã¯ãšã³ãåŽãããã®ãããªãããã䜿çšããªãããšãã§ããŸãã
ãŸããmemcachedã¯ã¡ã¢ãªããæãå€ãããŒã¿ãæ¶å»ãããšè¿°ã¹ãŸããã ã ãããç§ã¯åãã€ããã ããã¯å®éã«ã¯ããã§ã¯ãããŸããã Memcachedã«ã¯ããããã®ã¢ãã ãç Žæ£ããããã«ãã®ã¡ã¢ãªãå¹æçã«äœ¿çšããããã®ç¬èªã®ã¡ã¢ãªãããŒãžã£ããããŸãã ã¹ã©ãïŒæåéããã¹ã¿ããïŒãæã€ããã«èšèšãããŠããŸãã ããã¯ãã¡ã¢ãªã®äžéšã«å¯ŸããŠã¡ã¢ãªãããŒãžã£ãããã°ã©ãã³ã°ããéã«ç¢ºç«ãããçšèªã§ãã 倧ããªã¡ã¢ãªãã£ã³ã¯ãããããããããŒãžã«åå²ãããŠããŸãã memcachedå ã®ããŒãžã¯MBãªã®ã§ãè€æ°ã®MBã®Key-ValueããŒã¿ãããã«äœæããããšã¯ã§ããŸããã ããã¯ç©ççãªå¶éã§ã-memcachedã¯è€æ°ããŒãžã®ããŒã¿ãäœæã§ããŸããã ãããŠãæçµçã«ã¯ããã¹ãŠã®ããŒãžããã£ã³ã¯ã«åå²ãããŸããããã¯ã96ã120ã®åçã«è¡šç€ºãããŠãããã®ã§ã-ç¹å®ã®ãµã€ãºã§ãã ã€ãŸã 96 MBã®ããŒã¹ãããã次ã«32ãã1 MBãŸã§ã®1.25åã®120ã®ããŒã¹ããããŸãã . - , memcached ( + + + + , memcached ( 24-50 )), . head. - , memcached head. .., , , tail, .
, memcached . list recently used , .. - , â 96 120 120- .. memcached , .
slab'. memcached â , Telnet' , stats, Enter, «». stats slabs, stats items â , , stats slabs , , stat' â , memcached , stat items â , , . , , .
. , memcached â . ? - . , . availability, â , , -, , Round Robin', . - , , memcached, .
? . , - - , . , .
latency. 90% â round trip, .. memcached â , . , , .. . , memcached , . , , , memcached ? , , memcached â .
, , , , , â .
â consistent hashing ring. ã€ãŸã ? , , int32, . ã ãã â , - - . , . , , .. , , , , â , .
. , -, . , . â , â , , , . , , , â .
memcached consistancy - , .. availability, , - cas' - .
» cachelot@cachelot.io
» http://cachelot.io/
â HighLoad++ Junior .
ãŸãããããã®è³æã®äžéšã¯ãé«è² è·ã·ã¹ãã HighLoadã®éçºã«é¢ãããªã³ã©ã€ã³ãã¬ãŒãã³ã°ã³ãŒã¹ã§äœ¿çšãããŸãã¬ã€ãã¯ãç¹å¥ã«éžæãããæåãèšäºãè³æããããªã®ãã§ãŒã³ã§ãã ç§ãã¡ã®æç§æžã«ã¯ãã§ã«30以äžã®ãŠããŒã¯ãªè³æããããŸãã æ¥ç¶ããŠãã ããïŒ
â " - ", , HighLoad++ Junior .