ãŽã£ãã§ã¹ã©ãã»ã¢ã¹ã«ã¬ã³ã³ïŒã¬ã³ãŽã§ã³ãïŒ
é«è² è·ãããžã§ã¯ãã®ããŒã«ããã£ãã·ã³ã°ãç¹ã«memcachedãRedisãRabbitMQãã¥ãŒãµãŒãã¹ããŸãã¯äžè¬ã®äººã
ã®ããŠãµã®ãã«ã€ããŠèª¬æããŸãã
ã¬ããŒãã®æåã®éšåã§ã¯ãmemcachedãšã¯äœã-Redisã®åºæ¬æŠå¿µããã®æ©èœãããã³ããã2ã€ã®ãµãŒãã¹ã®éãã«ã€ããŠèª¬æããŸãã ç§ãã¡ã®ãããžã§ã¯ãã§ã®äž¡æ¹ã®ãµãŒãã¹ã®å®çšåã«ã€ããŠã話ããŸãã
第2éšã§ã¯ãRabbitMQã¡ãã»ãŒãžãããŒã«ãŒãããŠãµã®ãã«ããåºæ¬æŠå¿µããããã¥ãŒãµãŒãšã³ã³ã·ã¥ãŒããŒéã®ã¡ãã»ãŒãžã«ãŒãã£ã³ã°ã®ä»çµã¿ã«ã€ããŠèª¬æããŸãã ãŸãããã®ã¡ãã»ãŒãžãããŒã«ãŒã®ãããžã§ã¯ãã§ã®å®éçãªå¿çšã«ã€ããŠã説æããŸãã
ãã£ãã·ã³ã°ã«ã€ããŠã ããªãã®å€ãã¯ããªãã®ãŠã§ããããžã§ã¯ãã«å°ãªããšãäœãããã£ãã·ã¥ããŠãããšæãã®ã§ããã¹ãŠãéåžžã«ã·ã³ãã«ã§æé ãªäŸ¡æ Œã«ãªãã§ãããã
ãã£ãã·ã¥ãšã¯äœã§ããïŒ ããã¯ãããŒã¿ãèŠæ±ããã¯ã©ã€ã¢ã³ããšã¡ã€ã³ã®ïŒéåžžã¯äœéã®ïŒã¹ãã¬ãŒãžãšã®éã®ä»²ä»ã§ãã ãã®ãããªä»²ä»ã«ãããããŒã¿ãéåžžã«è¿
éã«åä¿¡ã§ããŸãã éåžžãmemcachedããã³Redis-aã®å ŽåãããŒã¿ã¯RAMã«ä¿åãããŸãã ãã£ãã·ã¥ãå¹æçã«äœ¿çšããããšã«ãããããŒã¿ããŒã¹ãµãŒããŒã®è² è·ã軜æžã§ããŸãã
åé¡ã¯ããã€ãäœããã£ãã·ã¥ãã¹ãããšããããšã§ãã é »ç¹ã«èŠæ±ãããããŒã¿ããã£ãã·ã¥ããããšãæçšã§ããããšã¯æããã§ãã ããçš®ã®å°ããªå¹Œçšåãããã1æéããã100人ã®ãŠãŒã¶ãŒãããå ŽåãããŒã¹ã«å€§ããªè² è·ã¯ãªãããã£ãã·ã¥ã¯ç¡å¹ã«ãªããŸãã ããã§ã倧èŠæš¡ãªé«è² è·ãããžã§ã¯ãã§ã¯ãããŒã¿ããŒã¹ã®è² è·ãæžããããå Žåããã£ãã·ã¥ã䜿çšããŸãã
ãã£ãã·ã¥ã§ãã/ã§ããªãããŒã¿ãç解ããããšãå¿
èŠã§ãã ç°¡åãªäŸïŒãŠãŒã¶ãŒããªã³ã©ã€ã³ã¹ãã¢ã§æ³šæããæ®ãã®è£œåãå€éšã·ã¹ãã ããååŸããå¿
èŠãããå Žåããã®ããŒã¿ããã£ãã·ã¥ã§ããªãããããªã³ã©ã€ã³ã§è¡ãå¿
èŠããããŸãã 次ã®ãŠãŒã¶ãŒããã£ãã·ã¥ããããŒã¿ãååŸãããšã©ãŒãçºçããå¯èœæ§ããããŸãã ãããã£ãŠãããšãã°æ°æéã1æ¥ãªã©ãä¿åã§ããããŒã¿ã®ã¿ããã£ãã·ã¥ã§ããŸãã
説æãããã£ãã·ã³ã°ããŒã«ã¯ãmemcachedãšRedisã§ãã
æåã®ãã®ããå§ããŸãããã Memcachedã¯ãRAMã«ããŒã¿ããã£ãã·ã¥ããããã®é«æ§èœãµãŒãã¹ã§ãã ãã®æŽå²ã¯2003幎ã«å§ãŸããŸãããã©ãããã£ãããããªãã¯ã¯Livejournalåãã«éçºããããã§æåè£ã«å®è£
ããããµãŒãã¹ãå éããŸããã
Memcachedã®æ©èœïŒæ ŒçŽããããŒã¿ã®éã«é¢ä¿ãªããéåžžã«é«éã§ãã·ã³ãã«ãªã€ã³ã¿ãŒãã§ã€ã¹ããããŸããããŒã¿ãå
¥åïŒèšå®ïŒããããååŸããããæå¹æéåŸã«ããŒãåé€ãããã§ããŸãã memcachedã¯ã¢ãããã¯æäœããµããŒãããŠããŸã-incr / decrãappend / prepend; ãµãŒããŒã®æ°ãç°¡åã«å¢ããããšãã§ãããµãŒããŒã®1ã€ãèœã¡ããšããŠããåã«ãã£ãã·ã¥ãã¹ãšããŠèšç®ãããŸãã ãã£ãã·ã¥ã«ã¯ããŒã¿ããããŸããã
memcachedã®å¶éïŒããŒã®æ倧é·ã¯250ãã€ãã§ããã1ã€ã®ããŒã®äžã«ä¿åã§ããããŒã¿ã®éã¯1 MBã«å¶éãããŠããŸãã memcachedã®ããŒæ倱ã¯ãã©ã€ãã¿ã€ã ãã¡ã¢ãªå¶éããŸãã¯ãµãŒããŒã®é害ã«ãã£ãŠçºçããå¯èœæ§ããããŸãã
ãªããªã ç§ã¯PHPããã°ã©ããŒã§ããPHPã§memcachedã䜿çšããæ¹æ³ã®äŸã瀺ããŸããã
PHPã«ã¯2ã€ã®æ¡åŒµæ©èœããããŸãã1ã€ã¯libmemcachedã©ã€ãã©ãªã䜿çšãã2ã€ç®ã¯php-memcacheæ¡åŒµæ©èœã®ã¿ã§ãã Libmemcachedã«ã¯ãããŒã¿ãå®è£
ããããã®ããå€ãã®ãªãã·ã§ã³ããããããã©ã«ãã§ã¯PHPã䜿çšããŠã·ãªã¢ã«åãããŸãããããšãã°JSONã·ãªã¢ã©ã€ã¶ãŒãå®çŸ©ã§ããŸãã memcachedãªããžã§ã¯ããäœæãããµãŒããŒãlocalhostã«è¿œå ããŸããããã©ã«ãããŒãã¯11211ã§ããç¹å®ã®æååãå
¥åãããarrayãããŒã®äžã«ç¹å®ã®é
åãå
¥åããããŒã¿ããè
æãããæå¹æéãèšå®ã§ããŸãã åçŽãªgetæäœã§ãããŒã¿ãååŸããŸãã ã€ãŸã è€éãªããšã¯äœããããŸããã ãŸã 䜿çšããŠããªãã·ã¹ãã 管çè
ã«memcachedãphpæ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããmemcachedçšã®ç¬èªã®æèœãªãã©ãããŒããäœæããããã䜿çšããŠããŒã¿ããŒã¹ãããŒããããã£ãã·ã¥ã§ããé »ç¹ã«èŠæ±ãããããŒã¿ããã£ãã·ã¥ããŸãã
次ã«ãRedisãšã¯äœããmemcachedãšã®éãã«ã€ããŠèª¬æããŸãã
Redisã¯ãæååãããã·ã¥ããªã¹ããã»ããããœãŒããããã»ãããªã©ãå€æ°ã®ããŒã¿åããµããŒãããŠããŸãã Redisã¯ãããŒã¿ãå®æçã«ãã£ã¹ã¯ã«ããªããããæ¹æ³ãç¥ã£ãŠããŸããããšãã°ãæ°å件ã®ããŒã¿ãæŽæ°ããåŸããã¹ãŠããã£ã¹ã¯ã«ãã©ãã·ã¥ã§ããŸãã Redisã¯LRUã¯ãªãŒã³ã¢ããããµããŒãããŠãããããŸããŸãªããŒã¯ãªãŒãã³ã°æŠç¥ãå®çŸ©ã§ããŸããããšãã°ãã¯ãªãŒãã³ã°ãé·æé䜿çšã§ããªãã寿åœã®ããããŒã®ã¿ãåé€ãããªã©ãã©ã³ãã ã«å®è¡ã§ããŸãã ãŸãã圌ãã¡ã¢ãªããŸã£ããã¯ãªã¢ããªãããã«ããããšãã§ããŸãããããŒã¿ãæŽæ°ãããšãRedisã¯ã©ã€ã¢ã³ãã¯ãšã©ãŒãã¹ããŒããŸãã æãæªäœ¿çšã®ããŒã¿ãã¯ãªã¢ããããã«ããŸãããã
Redisã¯ãã¹ã¿ãŒã¹ã¬ãŒãã¬ããªã±ãŒã·ã§ã³ããµããŒãããã·ã³ãã«ãã¥ãŒããµããŒãããŸãã ãã£ã³ãã«ã®äœæããã£ã³ãã«ç»é²ããã£ã³ãã«ãžã®ã¡ãã»ãŒãžã®å
¬éãé²èŠ§ãã§ããŸãã MULTI / EXECã³ãã³ããLUAã¹ã¯ãªããã䜿çšãããã©ã³ã¶ã¯ã·ã§ã³ããµããŒãããŸãã Redisã«ã¯åªããããã¥ã¡ã³ãããããŸã-redis.ioã®Webãµã€ãã«ã¢ã¯ã»ã¹ãããšããã¹ãŠãå©çšå¯èœã§ãã
次ã«ãããŒã¿åãšãRedisã§äœ¿çšã§ããã³ãã³ãã«ã€ããŠèª¬æããŸãã
æåã®ããŒã¿åã¯æååã§ãã ã€ã³ã¿ãŒãã§ãŒã¹ã¯ã·ã³ãã«ã§ãã ç¹å®ã®ããŒã«å€ãå
¥åã§ããŸãã ã¹ã©ã€ãã¯ãã³ã³ãœãŒã«ã¯ã©ã€ã¢ã³ãããRedisãžã®ã¹ã¯ãªãŒã³ã·ã§ããã®äŸã瀺ããŠããŸãã ç¹å®ã®ããŒããç¹å®ã®ãã¹ãã§SQLã«æ¥ç¶ããã®ãšåãããã«ãRedisãšé£æºããŠå€ãèšå®ããããŒã¿ãååŸãã寿åœãç§åäœã§èšå®ããŠãæ®ãã®æéãèŠæ±ã§ããŸãã
次ã®ããŒã¿åã¯ããã·ã¥ã§ãã ããã·ã¥ã¯ãç¹å®ã®ãªããžã§ã¯ãã®ãã£ãŒã«ããšãã®å€ãæ ŒçŽã§ããæ§é ã§ãã
ããã·ã¥ãåŠçããã«ã¯ãHSETããã³HMSEã³ãã³ãã䜿çšãããŸãã ããã·ã¥ãã£ãŒã«ãã®å€ãååŸããã«ã¯ãHGETALLã³ãã³ãã䜿çšããŠãããã·ã¥ã®ãã¹ãŠã®ããããã£ãååŸããŸãã
ç¹å®ã®äŸã¯ããŠãŒã¶ãŒã»ãã·ã§ã³ãããã·ã¥ã«æ ŒçŽã§ããããšã§ãã
次ã®ããŒã¿åã¯ã»ããã§ãã Redisã§ã¯ãç¹å®ã®ããŒã«ç¹å®ã®èŠçŽ ã»ãããä¿åã§ããŸãããRedisã®å€ãã¯ãã®äžææ§ã«è²¬ä»»ããããŸãã ã€ãŸã 2ã€ã®åäžã®èŠçŽ ãã»ããã«è¿œå ãããšã圌ã¯åžžã«åç¬ã§ããã«ããŸãã ã»ããã«èŠçŽ ãè¿œå ããã«ã¯ãSADDã³ãã³ãã䜿çšããã»ããã®ãã¹ãŠã®èŠçŽ ãååŸããã«ã¯ãSMEMBERSã³ãã³ãã䜿çšããŸãã æå¹æéã®EXPIREã³ãã³ãã§ããŒãèšå®ããããããŒãåé€ãããã§ããŸãã
å¥ã®ããŒã¿åã¯ãœãŒããããã»ããã§ãã ãããã¯ã»ãããšã»ãŒåãããã«æ©èœããŸãããã»ããå
ã®åèŠçŽ ã®ããããããã€ã³ãããèšå®ã§ããããšãé€ããŸãã äžèšã®ã¹ã©ã€ãã®äŸã«ããããã«ãã³ã¡ã³ãã§TIMESTAMPãèšäº13ã«æž¡ããŸããã ããŒã«ååãä»ããŠãããã第13æ¡ã®ã³ã¡ã³ãã§ããããšãæ確ã«ããŸãã
2ã€ã®èŠçŽ ãã»ããã«è¿œå ãããšããã€ã³ãã®éé ãŸãã¯æé ã§äžŠã¹æ¿ãããããªã¹ããååŸã§ããŸãã
Redisã«ã¯ãŸã ãªã¹ããªã©ã®ããŒã¿åããããŸãã ããã§ãå·ŠåŽãå³åŽã®èŠçŽ ã»ããã«ããã·ã¥ããŠãç¹å®ã®ã€ã³ããã¯ã¹ããç¹å®ã®ã€ã³ããã¯ã¹ã«èŠçŽ ãååŸã§ããŸãã
PHPã®ã¯ã©ã€ã¢ã³ãã¯äœã§ããïŒ
phpredisæ¡åŒµæ©èœããããCã§èšè¿°ãããŠããŸããPHPãRediskaãRedisServerã§èšè¿°ãããPredisã©ã€ãã©ãªããããŸããç¹å®ã®ããŒãã§ãœã±ãããéããRedisãšéä¿¡ããã¯ã©ã¹ã§ããResidentã¯RedisServerã®ãã©ãŒã¯ã§ãããããã§ãæ¡åŒµæ©èœã䜿çšããŸãã¹ããŒããšããã©ãŒãã³ã¹ã®åäžã®ããã®phpredisã
ãã¡ãããphpredisã䜿çšããããšããå§ãããŸããããã¯ããã¹ãŠã®ãã³ãããŒã¯ãšãã¹ãã§é«éã§ãããCã§èšè¿°ãããŠããããã¹ãŠã®phpå®è£
ãé
ãããã§ãã
次ã®ã¹ã©ã€ãã¯ãmemcachedãšRedisã®éãã瀺ããŠããŸãã
å®éãRedisãšmemcachedã®äž¡æ¹ãç¹å®ã®ã¿ã¹ã¯ã«äœ¿çšããå¿
èŠããããŸãã ããŒã¿æ§é ãã»ããããœãŒããããã»ããã®äžéšãä¿åããå¿
èŠããããããŒã¿ã倱ãããšãã§ããªãå Žåã¯ããã¡ãããRedisãå©ãã«ãªããŸãã Redisã¯ã·ã³ã°ã«ã¹ã¬ããã§ããããšã«æ³šæããŠãã ããã
次ã«äŸã«ã€ããŠèª¬æããŸãã
ã©ããããããããããžã§ã¯ãã§ã¯ã補åã®ã¯ã€ãã¯ãã¥ãŒã«ãŒãã衚瀺ããã ãã§ããã ãã®ããŒãžã«ã¯è£œåã®ãããã¥ã¢ããããã¯ãªãã¯ãããšè£œåã®è©³çŽ°ãªèª¬æã衚瀺ããå¿
èŠããããŸãã ã¿ã¹ã¯ã¯ãããã¯ãšã³ãã®è² è·ãå¯èœãªéãæžããããã«ãªããŸããã ããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ã®æžå°ãªã©ã
ãã®ããã«æ±ºå®ããŸããïŒ
ã€ãŸã AJAXãªã¯ãšã¹ããNgnixããã³ããšã³ãã«å°çãããšãNgnixã«ã¯memcachedã§åäœã§ããã¢ãžã¥ãŒã«ããããŸãã æåã«ããŒã§memcachedã®ããŒã¿ãèŠæ±ããããŒã¿ãããå ŽåïŒãããŠããã«è£œåã®JSONãããå ŽåïŒãããã«ãã®JSONãè¿ããŸãã éåžžã«é«éã«åäœããŸãã
ããŒã¿ããªãå Žåããªã¯ãšã¹ãã¯PHPã«ãããã·ããã2ã€ã®ç¶æ³ããããŸã-補åã«ãŒãã¯ãJSONã®åœ¢åŒã§Redisã«ãããRedisããååŸããŠmemcachedã«ä¿åããã¯ã©ã€ã¢ã³ãã«æž¡ããŸãã
Redisãšmemcachedã®ã©ã¡ãã«ããªãå Žåã¯ãMySQLãã補åã«ãŒãããªã¯ãšã¹ãããRedisã«ä¿åãããã®ããŒã¿ãmemcachedã«è€è£œããŠè¿ããŸãã 以äžã®ãªã¯ãšã¹ãã§ã補åã«ãŒãã¯ãã§ã«memcachedããçŽæ¥çºè¡ãããŠããŸãã
ã»ãšãã©ã®RedisããŒã¿åã䜿çšããã次ã®ããè€éãªäŸã¯ããã©ã¡ããªãã¯æ€çŽ¢ã§ãã
ã«ã¿ãã°ã«ã¯ã«ããŽãªããããåã»ã¯ã·ã§ã³ã«ã¯ç¬èªã®ãã£ã«ã¿ã»ãããã€ãŸãæšæºã®ãã£ã«ã¿ããã«ããããŸãã åãã£ã«ã¿ãŒã°ã«ãŒãã«ã¯ç¬èªã®ãªãã·ã§ã³ããããç¹å®ã®ãªãã·ã§ã³ãéžæããå Žåããããã®ãã£ã«ã¿ãŒãæºãã補åã®ãªã¹ãããŠãŒã¶ãŒã«è¡šç€ºããå¿
èŠããããŸãã
以åã¯ãããã¯ãã¹ãŠMySQLã®ã¯ãšãªã«ãã£ãŠè¡ãããè€éãªéžæãåæãããããçš®é¡ã®ããããã£ããããŸããããã®ã»ã¯ã·ã§ã³ã«ã¯ã©ã®ãã£ã«ã¿ããããŸãããªã©ã ããã¯ãã¹ãŠéåžžã«ãã£ãããšåããŸããã ããŒã¿ã¹ãã¬ãŒãžã¢ãã«ãå®å
šã«å€æŽããRedisã䜿çšããããšã«ããŸããã åæã«ãã»ã¯ã·ã§ã³ã®ãã£ã«ã¿ãŒãªãã·ã§ã³ããšã«ãåãªãã·ã§ã³ãæºãã補åIDãä¿åããããšã«ããŸããã
ããšãã°ãIDã100ã®ã«ããŽãªãé»è©±ãã«ã¯ããã¡ãŒã«ãŒããšãè²ããšãã2ã€ã®ãã£ã«ã¿ãŒã°ã«ãŒãããããŸãã
Samsungã®Redisã®4ã€ã®è£œå-201ã202ã203ã204ãããã³Philips-301ã302ã303ã®4ã€ã®è£œåããããšããŸããããããã®ããŒã«ã¯ãã«ããŽãªIDããã£ã«ã¿ãŒããã£ã«ã¿ãŒãªãã·ã§ã³ãå«ãŸããŠããŸãã ãŠãŒã¶ãŒããã£ã«ã¿ãŒããã«ã§Samsungãéžæããå ŽåãRedisã«ãªã¯ãšã¹ããã補åIDãååŸããŠè£œåãªã¹ãã³ã³ããŒãã³ãã«æž¡ããŸããã³ã³ããŒãã³ãã«ã¯4ã€ã®è£œåã衚瀺ãããŸãã ãŠãŒã¶ãŒãå¥ã®ãã£ãªããã¹ã¡ãŒã«ãŒãéžæããå ŽåãRedisã§2ã€ã®ã¯ãšãªãäœæãããããã®ã»ãããçµåããŠãã«ã¿ãã°ã«7ã€ã®èŠçŽ ã衚瀺ããŸãã
ããã«ããŠãŒã¶ãŒãå¥ã®ãã£ã«ã¿ãŒã°ã«ãŒããããã£ã«ã¿ãŒãªãã·ã§ã³ãéžæããå Žåãããšãã°ãèµ€è²ã衚瀺ãããŸãã ãµã ã¹ã³ãšãã£ãªããã¹ã®ãã¹ãŠãèµ€ããããã®ã§ãæåã®2ã€ã®ãªãã·ã§ã³ãçµã¿åãããŠãããããèµ€ã®æºåž¯é»è©±ãšäº€å·®ããã202ã303ã®2ã€ã®ååãååŸããŸãã
ãã®å®è£
ã®æ©èœ-MySQLã䜿çšãããããã¯ããã«é«éã§ããã1ã€ã ããããŸãããšã³ãã£ãã£ã®å€æŽããšã«å¿
èŠã§ãã 補åã®ããããã£ãå€æŽãããå Žå-補åãèŠåºãããèŠåºãã«ç§»åããã¡ãŒã«ãŒã®è£œåãå€æŽããã補åãæå¹å/ç¡å¹åããããã£ã«ã¿ãŒãäœæãå€æŽãåé€ãããå Žåãããããã¹ãŠã®ã»ãããåèšç®ããå¿
èŠããããŸãã ã€ãŸã ãããç§ãã¡ãããªããã°ãªããªãäž»ãªä»äºã§ããããã¥ãŒãéããŠå®è£
ããŠããŸãã RabbitMQã¡ãã»ãŒãžãããŒã«ãŒã䜿çšããŠã»ãããåèšç®ããŸããããã«ã€ããŠã¯åŸã§èª¬æããŸãã
ãã¥ãŒãšããã°ãããŠãµã®ãã«ã€ããŠè©±ããŸãã RabbitMQã¯ãAMQPãããã³ã«ãä»ããŠã¡ãã»ãŒãžã³ã°ã·ã¹ãã ãå®è£
ãããã©ãããã©ãŒã ã§ãã ãã®ãµãŒãã¹ã®æ©èœã¯ãä¿¡é Œæ§ãæè»ãªã¡ãã»ãŒãžã«ãŒãã£ã³ã°ã·ã¹ãã ãã¯ã©ã¹ã¿ãªã³ã°ã®ãµããŒãããã¥ãŒã®ã¹ããŒã¿ã¹ã確èªã§ããããŸããŸãªãã©ã°ã€ã³ã®ãµããŒãããã¥ãŒå
ã®ã¡ãã»ãŒãžæ°ã®ç¢ºèªãåŠçããã³ã³ã·ã¥ãŒããŒãã«ã¹ã¿ã ãã©ã°ã€ã³ãäœæããŠæšæºåäœãå€æŽããããšã§ããããŒã«ãŒã Erlangã®RabbitMQã«ãã£ãŠæžãããŸããã ãŸããJavaãRubyãPythonã.NETãPHPãPerlãC / C ++ãªã©ãã»ãšãã©ã®èšèªã®ããŠãµã®ããæäœããã¯ã©ã€ã¢ã³ããããŸãããŠãµã®ã®Webãµã€ãã«ã¯ãåªãããã¥ãŒããªã¢ã«ãšååã«ææžåãããæ©èœããããŸãã åèšèªã«ã¯äŸãããããã¹ãŠãã¢ã¯ã»ã¹å¯èœãªèšèªã§èšè¿°ãããŠããŸãã
ããŠãµã®ãã䜿çšããéã®åºæ¬çãªæŠå¿µã¯äœã§ããïŒ
ããŠãµã®ãã«å«ãŸãã亀ææ©ã®çš®é¡ãã«ãŒãã£ã³ã°ã®é²è¡ç¶æ³ã«ã€ããŠèª¬æãããããã¥ãŒãµãŒããã³ã³ã·ã¥ãŒããŒãžã®ã¡ãã»ãŒãžãã¯ãŒã¯ãããŒã§ã©ã®ããã«çºçãããã瀺ãå³ã瀺ããŸãã
ãããã¥ãŒãµãŒïŒPïŒã¯ãã¡ãã»ãŒãžãéä¿¡ããããã°ã©ã ã§ãã ã¡ãã»ãŒãžã¯ãã¥ãŒã«çŽæ¥å
¥ããããšã¯ã¹ãã§ã³ãžã£ãŒ-ExchangeïŒXïŒãçµç±ããŸãããšã¯ã¹ãã§ã³ãžã£ãŒã¯ãã®ã¡ãã»ãŒãžãŸãã¯ãã®ã¡ãã»ãŒãžãéä¿¡ãããã¥ãŒããã§ã«æ±ºå®ããŠããŸãã ã¡ãã»ãŒãžãæ ŒçŽããããã¥ãŒãååšããããšã¯æããã§ãããã³ã³ã·ã¥ãŒãããããã®ãã¥ãŒãèªã¿åããäœããã®æ¹æ³ã§åŠçããããã°ã©ã ããããŸãã
æãåçŽãªã¯ãŒã¯ãããŒ-ãããã¥ãŒãµãŒã¯äº€ææ©ã«ã¡ãã»ãŒãžãéä¿¡ãã亀ææ©ã¯ãã€ã³ãã£ã³ã°ããŒã䜿çšããŠã¡ãã»ãŒãžãéä¿¡ãããã¥ãŒã決å®ããã³ã³ã·ã¥ãŒããŒã¯æ¢ã«ç¹å®ã®ãã¥ãŒãèªã¿åã£ãŠããŸãã ãã¥ãŒããã¡ãã»ãŒãžãåä¿¡ãããšãã³ã³ã·ã¥ãŒããŒã¯ãã¯ããåä¿¡ãåŠçãã¡ãã»ãŒãžããã¥ãŒããåé€ã§ããããšã確èªã§ããŸãã ã¡ãã»ãŒãžãããŠãµã®ãã§åŠçãããããšã確èªããã¡ã«ããºã ããããŸãã æ¶è²»è
ãã¡ãã»ãŒãžãåãåã£ãŠçªç¶èœã¡ãå Žåãã¡ãã»ãŒãžãåŠçãããããšã確èªãããŸã§ã¡ãã»ãŒãžã¯ãã¥ãŒã«æ®ããŸãã
ãã¥ãŒããã®èªã¿åããèšå®ããŠãã³ã³ã·ã¥ãŒããŒãååŸããã¡ãã»ãŒãžãåžžã«ããã¯ã¢ãããããããã«ããããšãã§ããŸãã èªå確èªãtrueã«èšå®ããéèŠã§ãªãå Žåã¯äœã確èªããå¿
èŠã¯ãããŸããã
ã©ã®äº€ææ©ããããŸããïŒ
æåã®ã¿ã€ãã¯çŽæ¥äº€æã§ããããã®æ¬è³ªã¯æ¬¡ã®ãšããã§ãã亀ææ©ã¯ããŸããŸãªã«ãŒã«ã®ãã¥ãŒã«ãã€ã³ãã§ããŸãã ããšãã°ãããã§ã¯ããã€ã³ãããŒãšã©ãŒãä»ããŠExchangeã«ãã€ã³ããããäžäœãã¥ãŒãããã³èŠåããŒãä»ããŠãšã¯ã¹ãã§ã³ãžã£ãŒã«ãã€ã³ããããäžäœãã¥ãŒããããŸãã 亀ææ©ã«ã¡ãã»ãŒãžãéä¿¡ãããããã¥ãŒãµãŒã¯ãã¡ãã»ãŒãžã®ã«ãŒãã£ã³ã°ããŒãæž¡ããŸããããšãã°ãã¹ã©ã€ãäžã§ãèµ€ãã¡ãã»ãŒãžã«ã«ãŒãã£ã³ã°ããŒãšã©ãŒãããããã€ã³ãããŒãšäžèŽããå Žåããªã¹ãã®å
é ã«ç§»åããŸãã ã¡ãã»ãŒãžã«èŠåã«ãŒãã£ã³ã°ããŒãããå Žåãã€ãŸã ã«ãŒãã£ã³ã°ããŒãšç¹å®ã®ãã¥ãŒã®ãã€ã³ãã£ã³ã°ããŒãšã®å³å¯ãªäžèŽã ç°ãªãæ¶è²»è
ã«ç°ãªãã¡ãã»ãŒãžãæäŸã§ããŸãã
次ã®ã¿ã€ãã®äº€ææ©ã¯ãã¡ã³ã¢ãŠãã§ãã
ããã§ã®ãã€ã³ãã¯ãã©ã®ããŒã«é¢ä¿ãªããã¥ãŒããšã¯ã¹ãã§ã³ãžã£ãŒã«ãã€ã³ãããããã€ã³ããããã ãã§ãFanoutã¿ã€ãã§Exchangeã«éä¿¡ããããã¹ãŠã®ã¡ãã»ãŒãžããã®ãšã¯ã¹ãã§ã³ãžã£ãŒã«ãã€ã³ãããããã¹ãŠã®ãã¥ãŒã«åé¡ãããããšã§ãã ãããã£ãŠã1ã€ã®ã¡ãã»ãŒãžãéä¿¡ããããšã§ãããã€ãã®æ
å ±ãè€æ°ã®ãµãŒãã¹ã«éä¿¡ããå¿
èŠãããå ŽåãFanoutã¿ã€ãã®äº€ææ©ã䜿çšã§ããã¡ãã»ãŒãžã¯äž¡æ¹ã®æ¶è²»ã«ãŒã ã«åé¡ãããŸãã
次ã®ã¿ã€ãã¯ãã¿ã€ãããããã¯ã®äº€ææ©ã§ãã
ãã®ã¿ã€ãã®ãšã¯ã¹ãã§ã³ãžã£ãŒã¯ãããŒã䜿çšããŠãã¥ãŒã«ãã€ã³ãã§ããŸããããŒã«ã¯ãã¢ã¹ã¿ãªã¹ã¯ïŒ*ïŒãã©ãã£ã¹ïŒïŒïŒãªã©ã®ç¹æ®æåãå«ããããšãã§ããŸãã ããã¯ã©ãããæå³ã§ããïŒ ãã€ã³ãã£ã³ã°ããŒã®ã¢ã¹ã¿ãªã¹ã¯ã¯1ã€ã®åèªã«çœ®ãæããããšãã§ããã©ãã£ã¹ã¯0å以äžã®åèªã«çœ®ãæããããšãã§ããŸãã
ãã®äŸã§ã¯ãQ 1ãã¥ãŒã¯* .orangeã*ããŒã䜿çšããŠãã€ã³ãããã2çªç®ã®ãã¥ãŒã¯2ã€ã®ããŒã«ãã€ã³ããããŸãã 圌女ã¯æ zyã§å§ãŸãã¡ãã»ãŒãžãåä¿¡ããæ®ãã¯éèŠã§ã¯ãããŸãã-奜ããªã ãä»ã®åèªããããåèªã¯ãããã§åºåããã2çªç®ã®ãã€ã³ãã£ã³ã°ããŒã¯3åèªã§ãïŒæåã®2ã€ã¯éèŠã§ã¯ãªããéèŠãªã®ã¯ãããããã
ãããã¥ãŒãµãŒãã¹ã©ã€ãã®æåã®äŸã®ãããªã«ãŒãã£ã°ããŒãæã€ã¡ãã»ãŒãžãéä¿¡ããå Žåã3ã€ã®åèªã§æ§æããã2çªç®ã®åèªã«ã¯ãªã¬ã³ãžãå«ãŸããæåŸã«ãŠãµã®ãšããåèªããããããäž¡æ¹ã®ãã¥ãŒã«åé¡ãããŸãã
å®éã®RabbitMQã
ããšãã°ãRedis-eã®ããŒã¿ãåèšç®ããå ŽåïŒäžèšåç
§ïŒãããŠãµã®ããå€ã䜿çšããŸãã ã€ãŸã ããŒã¿ãå€æŽããå€ãã®ãããã¥ãŒãµãŒããã»ã¹ãããããããã®ã³ãã³ãããã¥ãŒã®å€æŽã«éä¿¡ããŸãã2ã€ã®ãã¥ãŒã¯ãããŸãããããã«å€ããããã³ã³ã·ã¥ãŒãã¯æ¢ã«ç¹å®ã®ã¡ãã»ãŒãžãåŠçããŠããŸãã ããšãã°ãã¢ã€ãã Aã¯ç¡å¹ã«ãªã£ãŠãããããåé€ããå¿
èŠããããŸãã JSONã®åœ¢åŒã§ã¡ãã»ãŒãžãéä¿¡ãã次ã«æ¶è²»è
ããããèªã¿åããRedisã«æ¥ç¶ããããã«ãã¹ã¿ãŒã¹ã¬ãŒãã¬ããªã±ãŒã·ã§ã³ãããããããããã¹ã¿ãŒã«æžã蟌ã¿ããã®JSONã解æãããã®ãããªãã®ãåé€ããå¿
èŠãããããšãããããŸããã®ãããªã«ããŽãªããã®ãããªã»ããããååãåé€ããããã³ããšã³ãã¯ãã§ã«ã¹ã¬ãŒãã®Redisããèªã¿åããæŽæ°ãããããŒã¿ã衚瀺ããŸãã
å®éãããããããã®åçŽãªããŒã«-ãã£ãã·ã³ã°ãšãã¥ãŒ-ã«ã€ããŠäŒãããã£ãããšã®ãã¹ãŠã§ãã 質åããããŸããïŒ
èŽè¡ããã®è³ªå ïŒãã£ãã·ã¥ã®ããã£ã±ã€ããã©ã®ããã«å®è£
ãããŠããããå
·äœçã«æããŠãã ããã ã©ã®ããã«èšç®ããã©ã®ãããªå€ãèšå®ããŸããïŒ ããšãã°ã補åã«ãŒãã衚瀺ããããšãã°äŸ¡æ Œãå€æŽãããå Žåããã£ãã·ã¥ã¯ã©ããããã®éãã§æŽæ°ãããŸããïŒ
åç ïŒå®éããã¹ãŠãããã§åçŽã§ã-äŸ¡æ ŒãæŽæ°ãããšãããã£ãã·ã¥ã¯æŽæ°ããŸãããã¿ã¹ã¯ã®æ¡ä»¶ã«åŸã£ãŠç¹ã«éèŠã§ã¯ãããŸããã1æéã ããã£ãã·ã¥ããŸãã1æéåŸã«ãã®ããŒã¿ã¯ãæªããªããŸãããããªãã¡ äŸ¡æ Œã¯1æéã§æŽæ°ãããŸãã
èŽè¡ããã®è³ªå ïŒããã§ã¯
ãããé¢é£æ§ãé«ãã§ããããïŒ ããã¢ãŒã·ã§ã³äŸ¡æ Œã§è²©å£²ãããŠãã補åããããšããŸããæããã«ãããã«åºè·ãããŸãã 次ã«ãã©ã®ãããã®é »åºŠã§æ®é«ãæŽæ°ããŸããïŒ
åç ïŒæ®é«ããã£ãã·ã¥ããŸããã , , , memcached , ID, .
: â ?
: , . , memcached, memcached. .
: - , , ? ?
: .
: ?
: 20- «». , Redis, , , , , , ⊠20 , . , MySQL. , , , - .
: Redis-. ?
: , , ID , .. , ID .
: â memcached, Redis. , , , memcached , ?
: emcached , ngnix , memcached , Redis , , Redis. , , , popup. Redis , , , , popup, memcached, PHP, , framework, Redis. , . , Redis- , framework, MySQL Redis memcached.
: , - ?
: , , «», , munin- - .
: , , , , . . , , , memcached , , ?
: , , , -
: RabbitMQ , , «» - ?
: , . callback, , .
: RabbitMQ? , , , , , , , , ?
: , , , , . , .
: , RabbitMQ , , ?
: , , .
: , Redis , memcached. memcached ?
: , Redis , memcached, Redis, memcached. , Redis-e . - , , , memcached, . , , .
: memcached? 10%, 20%, 50%?
: , , â - , - , Redis 10% , memcached, . , , . , . .
â HighLoad++ .
- HighLoad.Guide â , , , . 30 . !
â " - ", , HighLoad++ Junior . , , , â