ã¯ããã«
åºç¤ãã¼ã ã§ããã¯ã¨ã³ãã¨ã³ã¸ãã¢ããã£ã¦ããæ¾ç°ï¼ @tadamatu ï¼ã§ãã
以åã«CTOå·å£ãå½ããã°å ã§å ¬éãã以ä¸ã®è¨äºãããã¾ãã
æ°è¦æ¥ç¶ã®éç
BASE ã®ã¢ã¯ã»ã¹éã®ä¼¸ã³ã¯åã¾ãããã®æ§æã§ãæ¥ç¶ã¨ã©ã¼ãçºçããããã«ãªã£ã¦ãã¾ãã¾ããã ãã¼ã¯æã«ç§é 2 ä¸ãã®æ°è¦æ¥ç¶ã primary ã¤ã³ã¹ã¿ã³ã¹ã¸è¡ããã¦ããã¨ãã£ãç¶æ ã§ãã
ãã®è¨äºãå ¬éãããã®ãç´ï¼å¹´åã§ãå½æ100ä¸ç¨åº¦ ã ã£ãã·ã§ããæ°ã¯170ä¸ãè¶ ããæã ã¯ã¾ã ã¾ã 伸ã°ãããã¨èãã¦ãã¾ãã ããã¯ãã·ã§ããæ°ã®ä¼¸ã³ã¨ã¨ãã«ãææ°é¢æ°çã«å¢ãã¦ããã¦ã¼ã¶ã®ã¢ã¯ã»ã¹ãæãå¿ è¦ããããã¨ãæå³ãã¾ãã
ããã°å ¬éå½æãæã ã¯ãã¾ãã¾ãªæ¤è¨ã®æ«ã以ä¸ã®ãããªå¯¾çãåãã¾ããã
æ®ãããæ段㯠primary ã®ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ãã¦ã®æ¥ç¶æ°ãå¦ä½ã«ãã¦æ¸ããããã¨ãããã¨ã®ã¿ã§ãã ããã§åºæ¥ããã¨ã¢ããªã±ã¼ã·ã§ã³å´ã®æ¥ç¶ãããã« reader ã¤ã³ã¹ã¿ã³ã¹ã«è¡ãããã¨ãããã¨ã§ãã ããã¯ã¯ã¨ãªã reader ã«åããã¨ããããããè² è·å¯¾çã§ã¯ãªããæ°è¦æ¥ç¶èªä½ã reader ã«æåããåãã
対å¿å¾ãã¡ãã£ã¢é²åºãªã©ã«ããã¢ã¯ã»ã¹ãéä¸ããã¨ããã³ãã³MySQLã¸ã®æ°è¦æ¥ç¶ãããã«ããã¯ã¨ãªããæ¥ç¶ãã¥ããç¶æ ã«é¥ã£ã¦ãã¾ããã ããã§BASEã§ã¯ãRDS Proxy ã2020/06ã«GAããããã¨ããããæ¤è¨¼ãéå§ããå°å ¥ããã¾ã§ã«è³ãã¾ããã aws.amazon.com
æ¬è¨äºã§ã¯ãããã§å¾ãç¥è¦ãPHPã¨ã®ç¸æ§ã¯ã©ããªã®ããæ¤è¨¼ããæ¹æ³ãå°å ¥å¾ã©ã®ç¨åº¦å¹æããã£ãã®ããå°å ¥å¾çºçããé害ããªã©ãRDS Proxyå°å ¥ã«ãããã¡ãªããã»ãã¡ãªãã ãå ¬éããã¦ããã ããã¨æãã¾ãã
RDS Proxyå°å ¥æ¹æ³ãªã©åºæ¬çãªãã¨ã¯ä»ã®è¨äºã«è²ãã¾ãããã®è¨äºã§ã¯å®éã®å°å ¥ãéãã¦å¾ãTips ãã§ããã ãç¶²ç¾ ãã¾ããã®ã§ãRDS Proxyãæ°ã«ãªã£ã¦ããæ¹ãå°å ¥ãæ¤è¨ãã¦ããæ¹ã®ãå½¹ã«ç«ã¦ãã°å¬ããã§ãã
RDS Proxyã¨ã¯
ã¾ãã RDS Proxy ãå°å ¥ãããã¨ã§å ¬å¼ã«è¨è¼ããã¦ããã¡ãªãããç°¡åã«æ¸ãã¦ããã¾ãã aws.amazon.com
ã(1) æ¥ç¶ãã¼ãªã³ã°ã«ããããã©ã¼ãã³ã¹ã®åä¸ ã(2) ãã«ããã¼ã¸ã ã(3) ãã§ã¤ã«ãªã¼ãã¼çºçæã®æéç縮ãªã©ã«ããã¢ããªã±ã¼ã·ã§ã³ã®å¯ç¨æ§åä¸ ã(4) IAM èªè¨¼ãå©ç¨ãã»ãã¥ãªãã£ã¬ãã«ã®åä¸ï¼ãªãã·ã§ã³ï¼
ãªã©ããã¤ãããã¾ããããã¡ããæã
ãä¸çªå¾ããã£ãã¡ãªããã¯(1)
ã«ãªãã¾ãã
å°å ¥åã®æ¤è¨¼
ãã¦ãæ¤è¨¼ãå§ãã¦ããããã§ããããã¤ã³ãã¨ãªã£ããã®ãè¨è¼ãã¦ããã¾ãã
ã¢ããªã±ã¼ã·ã§ã³çãªéå£ã¯ã»ã¼ãªãã£ã
ã¾ãæå§ãã«å®éã«DEVç°å¢ã«RDS Proxyãæ§ç¯ãã¦ã¿ã¦ãã¢ããªã±ã¼ã·ã§ã³ããã®DBæ¥ç¶ãRDS Proxyçµç±ã«åãæ¿ãã¦æ¤è¨¼ããã¦ã¿ã¾ãã ããã«é¢ãã¦ã¯QAãã¼ã ã«ååããã¦ããã ããä¸éããªã°ã¬ãã·ã§ã³ãã¹ããéããã¨ã§æ¤è¨¼ãåä½æ ä¿ãè¡ãã¾ããã
çµæããã£ãããªã°ã¬ãã·ã§ã³ãã¹ãããã¹ï¼
ã¤ã¾ããRDS Proxyã®åãæ¿ãã«é¢ãã¦ã³ã¼ãã®å¤æ´ã¯ã»ã¼ãªãã§å¯è½ã§ãã³ã¼ãå¤æ´ããã®ã¯æ¥ç¶å ã®åãæ¿ããããã¨ããã©ã¤ããªæè¦ã§åãæ¿ããå¯è½ ã¨ãããã¨ãåããã¾ããã ï¼å¾è¿°ãã¾ãããBASEã§ã¯RDS Proxyã®åãæ¿ãã§ãå ¨ãã¢ããªã®ã³ã¼ãã¯å¤æ´ãã¾ããã§ããï¼
è²»ç¨é¢ã«ã¤ãã¦è¦ç©ãã
RDS Proxyã¯RDSã¤ã³ã¹ã¿ã³ã¹ã®vCPUã®ç·æ°ã«å¿ãã¦è²»ç¨ããããã¾ãã aws.amazon.com
BASEã§ã¯ãéå»ã«é害ãçºçãã¦ããçµç·¯ããããå®å®éç¨ã®ãããå°ãåæã§Auroraã®ã¤ã³ã¹ã¿ã³ã¹ãå¢ãããã¤ã³ã¹ã¿ã³ã¹ãµã¤ãºã大ãããããã®ãå©ç¨ãã¦ãã¾ããã
ãã®ã¾ã¾ã·ãããã¦RDS Proxyæ¡ç¨ããå ´åã§è¦ç©ããã¨ãå¹´é300ä¸åç¨åº¦ã®ä¸ä¹ãè²»ç¨ãçºçãããã¨ãåããã¾ããã 決ãã¦å°ããªé¡ã§ã¯ãªãã§ãããBASEã§ã¯å°æ¥ã®æ¥ç¶å®å®æ§ãå¾ããã®ã§ããã°å°å ¥ãããã¨ãããã¨ã§ãæ¤è¨¼ãç¶ãã¾ããã
ãããå°å ¥å¾ãåæåã®ã¤ã³ã¹ã¿ã³ã¹ãæ¸ãããã¤ã³ã¹ã¿ã³ã¹ãµã¤ãºãè½ã¨ããã¨ãã調æ´ãã§ãããã¨ã§ãçµæçã«RDSã®åæ¸åãå«ãã㨠年é960ä¸åãã®åæ¸ ãã§ããè¨ç®ã«ãªãã¾ãã ããã¯é常ã«å¤§ããªã¡ãªããã§ããã
ãã³çããå¿é
RDS Proxyãå°å ¥ããã«ããã£ã¦ãä¸çªæ°ã«ãªã£ã¦ããã®ã¯ãã³çãã¨ããç¾è±¡ã§ãã
ãã³çããåé¿ãã ããæç²
RDS Proxy ã¯ãä»ã®ã»ãã·ã§ã³ã«ä¸é©åãªã»ãã·ã§ã³ç¶æ ã®å¤åãæ¤åºããã¨ãã¯ã©ã¤ã¢ã³ãæ¥ç¶ãç¹å®ã® DB æ¥ç¶ã«èªåçã«ãã³çããã¾ãããã³çãã«ãããæ¥ç¶ã®åå©ç¨ã®æå¹æ§ãä½ä¸ãã¾ãã
ãã³çã㯠CloudWatch
ã® DatabaseConnectionsCurrentlySessionPinned
ã¡ããªã¯ã¹ã«ãã£ã¦ç¢ºèªãã§ãã¾ãã
æ¤è¨¼ã®çµæãBASEã®ã¢ããªã±ã¼ã·ã§ã³ããã®æ¥ç¶ã§ã¯ ãã³çããå
¨ãçºçãã¾ããã§ããã
BASEã§ã¯CakePHPããã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦å©ç¨ãã¦ãã¾ãããPHPã¯ä¸è¬çã«ï¼ããã«ã¦ã§ã¢ãªã©ã§æ¥ç¶ãã¼ãªã³ã°ãå®è£
ãã¦ããªãéãï¼ãªã¯ã¨ã¹ãã®ãã³ã«æ¥ç¶ã»åæãç¹°ãè¿ãããããã³çãã®å½±é¿ãå
¨ãåããªãã£ãã®ã§ã¯ãªããã¨æ¨æ¸¬ãã¦ãã¾ãã
ã¡ãªã¿ã«ããã®æªéã®è¨¼æã¨ãè¨ããããªã¡ããªã¯ã¹ã«è¡¨ç¤ºãããªããã³çããã©ã®ããã«æ¤è¨¼ãããã¨ããã¨ãã¾ãRDS Proxyçµç±ã§mysqlã¯ã©ã¤ã¢ã³ãã«ããæ¥ç¶ããSET
ã¹ãã¼ãã¡ã³ããLOCK TABLE
æä½ããããã¨ã«ããç¡çãããã³çããçºçãããã¡ããªã¯ã¹ã¨ãã¦ã¯æ¤ç¥ã§ãããã¨ã確èªãã¾ãã
ãã®å¾ãQAã®ãªã°ã¬ãã·ã§ã³ãã¹ããéããã¨ãã«ãã³çãã¡ããªã¯ã¹ãæ¤åºãããªããã¨ã確èªãããã¨ã§çºçãã¦ããªãã¨çµè«ã¥ãã¾ããã
ï¼å®éãæ¬çªãªãªã¼ã¹å¾ããã®ã¡ããªã¯ã¹ã¯ã»ã¼æ¤ç¥ããã¾ããã§ããï¼
è² è·è©¦é¨ã«ã¤ãã¦
BASEã§ã¯ãè² è·è©¦é¨ç¨ã®DEVç°å¢ãããã¾ãã ä»åã¯ããã®ç°å¢ã§åããã¢ããªã±ã¼ã·ã§ã³ããã®DBæ¥ç¶ãã
ã(A) RDSç´æ¥æ¥ç¶ããå ´åï¼ç¾ç¶ã®ç°å¢æ³å®ï¼ ã(B) RDS Proxyçµç±ãæ¥ç¶ããå ´å
ã§æ¯è¼ããæ¤è¨¼ãã¾ããã
æ¤è¨¼ãã軸ã¨ãã¦ã¯ä»¥ä¸ã®ï¼è»¸
ã(1) ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã«ããèª¿æ´ ã(2) ã¹ã¯ãªããã«ããã¢ã¯ã»ã¹æ°ã調æ´
ã¾ã (A) ã®éçå¤ ãè¦æ¥µãã¾ãã
(1)
ãæ¬çªã¨åããã®ã«åºå®ãã(2)
ã®ã¢ã¯ã»ã¹æ°ãä¸ãã¦ãããã¨ã©ã¼ãåºãéçå¤ãã ãã¾ããã
次ã«ã(B)ã®éçå¤ ãå軸ã§ä¸ä¸ããããã¨ã§åºãã¦ããã¾ãã
(2)
ãåºå®ã«ãã¦ã(1)
ãä¸ãã¦ããã¾ãã
çµæãã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã1/4 ãµã¤ãºã«è½ã¨ãã¦ãã¨ã©ã¼ãåºãªãã¨ãã好æ績 ã«ã
ãã以ä¸ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããè½ã¨ãç¶ãã¦ãæå³ããªãããã次ã«(1)
ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã1/4
ã®ç¶æ
ã§åºå®ãã(2)
ã®ã¢ã¯ã»ã¹æ°ãå¢ããéçå¤ãè¦æ¥µãã¾ãã
ãã¡ããçµæã¨ãã¦ã5å以ä¸ã®ã¢ã¯ã»ã¹æ°ã«ãã¦ãDBã®ã¨ã©ã¼ãåºã¾ãã ã§ããããªãã¨ãããã«ããã¯ãRedisãApacheãªã©ä»ã«ç§»ã£ã¦ãã¾ããéçå¤ãè¨æ¸¬ã§ããªãã£ããããå¹æãããã¾ããã
æ¥ç¶åæãç¹°ãè¿ãã¨ãããªã¼ãã¼ããããããã»ã©å¤§ããã£ãã®ã ããã¨ããçµè«ã«ãããã¾ããã PHPã¨ç¸æ§ãã¨ã¦ãè¯ãã£ãã¨ããçµæã ã¨æãã¾ãã
ã«ã¹ã¿ã ã¨ã³ããã¤ã³ãåé¡
RDS Proxyãå°å ¥ããã¨ãDBã¸ã®æ¥ç¶ã¯RDS Proxyãclusteråä½ã§ã³ã³ããã¼ã« ãããããã«ãªãã¾ãã
BASEã§ã¯ãDBã¬ããªã±ã¼ã·ã§ã³ãclusterã«ä¾åããWriter/Readeræ§é ãå©ç¨ãã¦éç¨ããã¦ãã¾ããã å°ãç¹æ®ãªé¨åã¨ãã¦ã調æ»ãåæãªã©ã§ãµã¼ãã¹ã¸ã®å½±é¿ãä¸ããªããããReaderã®ãã¡ã®ï¼ã¤ãåæç¨ã¨ãã¦å©ç¨ããä»ã®DBãã«ã¹ã¿ã ã¨ã³ããã¤ã³ãã«ããDBæ¥ç¶ãã³ã³ããã¼ã«ãã¦ãã¾ãããï¼ä¸è¨ã¤ã¡ã¼ã¸ã®AS-ISã®é¨åï¼
RDS Proxyãå°å ¥ããã¨ããã¹ã¦ã®DBãã³ã³ããã¼ã«å¯¾è±¡ã¨ãªã£ã¦ãã¾ãããµã¼ãã¹ã«å½±é¿ãä¸ããåæã§ããDBã確ä¿ã§ããªãã¨ããç¶æ ã«ãªãããå°ãåé¡ã§ãã ããã§ç§ãã¡ãåã£ã解決çã¨ãã¦ã¯ãBinlogã«ããã¬ããªã±ã¼ã·ã§ã³ããå¥clusterãèªåãã¡ã§æ§ç¯ ãã¾ãããï¼ä¸è¨ã¤ã¡ã¼ã¸ã®TO-BEï¼
ä½è«ã§ãããå®ã¯æã ãRDS Proxyã®å°å ¥ãããä¸ã§ä¸çªæãç¼ããã®ãããã®å¥clusterãã¤ããã¨ããé¨åã§ããã ã¹ãããã·ã§ãããã¨ãããã®ãã³ãã¤ã³ãã®ã¿ã¤ãã³ã°ã®ãã¸ã·ã§ã³ãã¨ããå¥clusterã§Binlogã®ã¬ããªã±ã¼ã·ã§ã³ãéå§ããããã®æä½ããã¦ã³ã¿ã¤ã ãªãã§ã¯é£ãããã¡ã³ããã³ã¹ã³ã³ããã¼ã«ãªã©å¿ è¦ã§ããã
ãã ããã¯ãBASEã®ç¬ç¹ãªç°å¢ã®åé¡ãªã®ã§RDS Proxyå°å ¥ã§å¿ é ã§ã¯ããã¾ããã
MySQLã¦ã¼ã¶ã®ã¢ã¯ã»ã¹ã³ã³ããã¼ã«
RDS Proxyãå°å ¥ããå ´åãRDS Proxyã«å¯¾ãã¦MySQLã¸ã®ã¢ã¯ã»ã¹æ å ±(ã¦ã¼ã¶/ãã¹ã¯ã¼ã)ãã¢ã¿ãããã¦ããå¿ è¦ãããã¾ãã ããã¯ããã¹ã¦ã®ã¢ã¯ã»ã¹ãRDS Proxyçµç±ã«ããå ´åãMySQLã«ç»é²ãã¦ããã¦ã¼ã¶ããã¹ã¦ã¢ã¿ãããã¦ããå¿ è¦ãããã¨ãããã¨ã§ãã ã¦ã¼ã¶ãå¢ãããå ´åãé½åº¦è¿½å ããå¿ è¦ãããã¾ãã権é管çã®ããã«ã¦ã¼ã¶ãå¢ãããã¨ãããããã¾ããã管ççã«ãç ©éã§ããããã¾ããã
ããã§ç§ãã¡ã¯å°ããã«ã¼ã«ã¥ãããã¦ãã³ã³ããã¼ã«ãããã¨ã«ãã¾ããã以ä¸ã®ãããªãã®ã§ãã
- SREãã³ã³ããã¼ã«ããã¦ã¼ã¶ã«é¢ãã¦ã¯ãRDS Proxyãçµç±ãã¦ã¢ã¯ã»ã¹ããã - åºæ¬çã«ã¯ãµã¼ãã¹ããã®ã¢ã¯ã»ã¹ - ãã以å¤ã®ã¦ã¼ã¶ã«é¢ãã¦ã¯RDS Proxyãçµç±ããã¢ã¯ã»ã¹ãã
åè ã®ã¦ã¼ã¶ãå¢ãããå ´åã®ã¿ãã¢ã¿ãããå¿ è¦ã¨ãªãã¾ãããã¨ãã¢ã¿ãããæ¼ããã¨ãã¦ãåä½æ¤è¨¼æã«çºè¦ã§ãã¾ãã ä¸è¬ã¦ã¼ã¶è¿½å ãªã©ã®é »åº¦ã®é«ãæä½ã§ã¯ã¢ã¿ãããä¸è¦ã§ããDBæä½éçºè ãå¢ãã¦ã¦ã¼ã¶ä½æããããDBã«ã¢ã¯ã»ã¹ã§ããªãããªãã§ã ããã¨ãã£ãæ··ä¹±ãé²ãã¾ãã
ãããªãªã¼ã¹
æ¥ç¶ã¨ã³ããã¤ã³ãã®åãæ¿ã
BASEã§ã¯ãã¢ããªã±ã¼ã·ã§ã³ããã®RDSã¸ã®æ¥ç¶ã¯ clusterã®ã¨ã³ããã¤ã³ã ãå©ç¨ãããRoute53çµç±ãããã¨ã§è¡ãªã£ã¦ãã¾ãã ãªãªã¼ã¹ã¯ããã RDS Proxyã®ã¨ã³ããã¤ã³ã ã«Route53ä¸ã§åãæ¿ãããã¨ã§å®æ½ãã¾ããã
å®è¡ã¯ã¢ã¯ã»ã¹ã®å°ãªãæ·±å¤å¸¯ã«ããã¦ã³ã¿ã¤ã ãªãï¼ã¦ã¼ã¶ãµã¤ãããè¦ãã¡ã³ããã³ã¹ç¶æ ã«ããï¼ã§åãæ¿ãå®äºã åãæ¿ãå¾ãã¢ãã¿ãªã³ã°ã§ãéã«å¿é ã«ãªããããä½ãåé¡ãªããã¬ã¤ãã³ã·ã¼ãå°ãçºçãã¦ãããªã¼ãããã§å®äºãã¾ããã
ãªãã¼ã
å®éã¯ããªãã£ãã®ã§ããããªãã¼ãã«ã¤ãã¦ãRoute53ä¸ã§ã¨ã³ããã¤ã³ããæ»ãã ãã¨ããã©ã¤ããªãã®ã§ããã®ã§ãä»åã¯æãåã£ãå®æ½ãã§ãã¾ããã å¿ã®å®å¿ã¯å¤§åã§ããã
(ä½è«)åãæ¿ãå¾ãæ¥ç¶ãå¢ãç¶ãä¸å®ã«
åãæ¿ãç´å¾ãDBã¸ã®æ¥ç¶ã24æéã®ããã ä¸æ¹çã«å¢ãç¶ãã¢ãã¿ãªã³ã°ãã¦ãã¦ä¸å®ã«ãªãã¾ããããåå ã¯ä»¥ä¸ã®éãã§ããã
MaxIdleConnectionsPercent ããæç²
RDS ãããã·ã¯ããã¼ã¿ãã¼ã¹æ¥ç¶ã使ç¨ãããªããªã£ã 24 æéå¾ã«ãã®æ¥ç¶ãéãã¾ãããããã·ã¯ãã¢ã¤ãã«ç¶æ ã®æ大æ¥ç¶æ°ã®è¨å®å¤ã«é¢ä¿ãªãããã®ã¢ã¯ã·ã§ã³ãå®è¡ãã¾ãã
以ä¸ã¯ãCloudWatch
ã® DatabaseConnections
ã¡ããªã¯ã¹ãªã®ã§ãããåãæ¿ãç´å¾ã¯24æéã§æ¥ç¶ãã¬ã¯ã³ã¨è½ã¡ããã®å¾ãããã¥ã¤å¹³æºåããã¦ããåãã«ãªã£ã¦ãããã¨ããããã¨æãã¾ãã
å°å ¥å¾ã®æ¸¬å®ã»å¹æ
ConnectionAttemptsãç¡é¢¨ã«
ããã¾ã§ã®é害ã§æ¥ç¶ãµã¼ã¸ãçºçãã¦ããæã¯ãæ°è¦æ¥ç¶ã試ãæ°ã§ãã ConnectionAttempts
ã¨ããã¡ããªã¯ã¹ãç°å¸¸ãªå¤ã示ã㦠ãã¾ããã
RDS Proxyãå°å
¥ããåã¾ã§ã¯ããããªãã®æ°å¤ã示ãã¦ããã®ã§ãããå°å
¥å¾ã¯æ¥ç¶ãã¼ã«ã§ã³ã³ããã¼ã«ããããã1æ¡ã«ãªãã¾ããã
ãããï¼ã¤ã®å®å®æ¥ç¶ãå¾ãã¨ãã証æ ã¨ãªãã¾ãã
ï¼ã°ã©ãã§ã¯ã¼ãã«è¦ãã¾ããå®éã¯å°ãããã¾ããããã ãæ¸ã£ãã¨ãããã¨ã§ããï¼
æ¥ç¶ãå®å®
åè¿°ãã¾ããããDatabaseConnections
ãé常ã«å®å® ãã¾ããï¼ä¸å³ï¼ã
å°å
¥åã«æ¯ã¹ã¦è¥å¹²å¢å ãã¦ãã®ã¯ãRDS Proxyãã¢ã¤ãã«ç¶æ
ã«ãªã£ãã³ãã¯ã·ã§ã³ãéããã¾ã¾ä¿æããããã¨èãããã¾ãã
ã¢ã¤ãã«ç¶æ
ã®ã³ãã¯ã·ã§ã³ä¿ææ大å¤ã«ã¤ãã¦ã¯ã MaxIdleConnectionsPercent
ã¨ããå¤ã§è¨å®ã§ãã¾ãã®ã§ç°å¢ã«åããã¦èª¿æ´ããã¨è¯ãã¨æãã¾ãã
ä¸å³ã¯ãæ大æ¥ç¶æ°ã®ã°ã©ããªã®ã§ãããå¤ãã¦ã 1,200
ç¨åº¦ã«ãããªã£ã¦ãã¾ããã
RDSã«è¨å®ãã¦ãã max_connections
ã 12,000
ãªã®ã§ãç¾ç¶ã¯ããªãã®ä½è£ãããçµæã¨ãªã£ã¦ãã¾ãã
Readerã¤ã³ã¹ã¿ã³ã¹ãæ¸ããã
ä¸è¨ã®æ¥ç¶å®å®ã®çµæãåããæ¥ç¶ã«ä½è£ããã¦ãã¨åãã£ããã¨ã§ãReaderã¤ã³ã¹ã¿ã³ã¹ãï¼ã¤åé¤ã§ãã¾ããã
åé¤ããå¾ãCPU使ç¨éãå°ãå¢ããåDBã®ãããã¯ã¼ã¯ã¹ã«ã¼ãããéãå¢ãããããã§ãæ³å®éãã®çµæã¨ãªãã¾ããã ã¡ã¢ãªä½¿ç¨éã¯å¢ãã¾ããã§ããã
ä¸å³ã¯åé¤åå¾ã®CPU使ç¨é (CPUUtilizationã¡ããªã¯ã¹)
ãªã®ã§ãããåé¤å¾ã¯ 30-35%
ã§é·ç§»ãã¦ãããããã¾ã§æ¥ç¶å®å®åã®ããã«ç¡é§ã«ãµã¤ãºãä¸ãã¦ã¾ãããããããæé©åã§ããã®ã§ã¯ãªããã¨èãã¦ãã¾ãã
åé¤ãã¦ä»¥éãåé¡ã¯çºçãã¦ããããè²»ç¨åæ¸ã«è²¢ç®ãã¾ããã
Writerã¤ã³ã¹ã¿ã³ã¹ã®ãµã¤ãºãä¸ãããã¨ãã§ãã
ããã«æ¥ç¶å®å®ã®çµæãåããWriterã¤ã³ã¹ã¿ã³ã¹ãååã«ãããã¨ãã§ãã¾ããã
ãµã¤ãºãä¸ããå¾ãReaderã¨åæ§ã§CPU使ç¨éãå°ãå¢ã ããããã§ãåé¡ã¯çºçãã¦ããããè²»ç¨åæ¸ã«è²¢ç®ãã¾ããã
ããã§ç¹çãã¹ãã¯ãWriterã¤ã³ã¹ã¿ã³ã¹ã®ãµã¤ãºãä¸ããã¨ãã® ãã§ã¼ã«ãªã¼ãã¼ã®åã ã§ãã
ãµã¤ãºã®å¤æ´ã¯ãã¾ãclusterå ã«ãåãæ¿ãå ã¨ãªãDBããäºåã«ä½æãããã§ã¼ã«ãªã¼ãã¼ããããã¨ã§åãæ¿ããåãæ¿ããå¾ã«ãåãæ¿ãå ã®DBããåé¤ããã®ã§ãããããã§ãRDS Proxyã®ãããããåããè¦ã¦ã¨ããã¨ãã§ãã¾ããã
ä¸å³ã¯ããã§ã¼ã«ãªã¼ãã¼ãããã¨ãã® RDS Proxyã®ã¡ããªã¯ã¹ ã§ãã
åãæ¿ããç¬éãClientConnections
ãæ¥æ¿ã«å¢ã ãã¯ã©ã¤ã¢ã³ãããã®æ¥ç¶ãRDS Proxyãå¾
æ©ããã¦ãããã¨ãè¦ã¦åãã¾ãã
ããã¨åæã« DatabaseConnections
ãæ¥æ¿ã«å¢ãã¦ãã ãã¨ãåããã¾ããããã¯ããããå¾
æ©ãããæ¥ç¶ããã£ãã«æãããã ã¨èãããã¾ãã
ããã¦ä¸å³ã QueryResponseLatency
ã¡ããªã¯ã¹ ã§ãã
ãããè¦ã¦ãæ大ã§4ç§ã»ã©å¾
æ©ããã¦ãããã¨ãåããã¾ãã
ã¤ã¾ãã¦ã¼ã¶ããè¦ãã¨ããããï¼ã¡ãã£ã¨é
ããªãç¨åº¦ã§æ¸ãã§ããã¨ãããã¨ã§ãã
ãã¡ããã¨ã©ã¼ãå
¨ããªãã£ã訳ã§ã¯ããã¾ãããSentryã«ã¨ã©ã¼ 2006 MySQL server has gone away
ãåºåããã¦ãã¾ããããããªãå°ãªãé常ã®ãã§ã¼ã«ãªã¼ãã¼ã¨æ¯ã¹ãã¨ããªãå°ããªå½±é¿ã§æ¸ãã ã¨è¨ããã¨æãã¾ãã
ããã¦ä¸å³ã Databaseå´ããè¦ã DatabaseConnections
ã¡ããªã¯ã¹ï¼1æ¥ä»¥ä¸çµéãããã®ï¼ ã§ãã
åè¿°ãã¾ãããããã§ã¼ã«ãªã¼ãã¼ç´å¾ãªã¯ã¨ã¹ããæãããä¸æ°ã«å¢ããã¾ãã¢ã¤ãã«ç¶æ
ã§24æéçµéãããã®ãã解æ¾ããã¦ããã¨ããã®ãè¦ã¦åããã¡ããªã¯ã¹ã«ãªã£ã¦ãã¾ãã
24æéå¾ã¯æ¥ç¶ãå¿
è¦åã ãã¨ãªããå®å®ãã¦ãã¾ãã
RDS Proxyã®ç¹å¾´ã®ä¸ã¤ã§ããã(3) ãã§ã¤ã«ãªã¼ãã¼çºçæã®æéç縮ãªã©ã«ããã¢ããªã±ã¼ã·ã§ã³ã®å¯ç¨æ§åä¸ãã確èªãããã¨ãã§ãã¾ããã
ã¬ã¤ãã³ã·ã¼ãçºçãã
AWSå
¬å¼ã§ã¯å¿çæéã« å¹³å5ããªç§/ã¯ã¨ãª
ã®ãããã¯ã¼ã¯ã¬ã¤ãã³ã·ã¼ãçºçããã¨è¨è¼ãããã¾ãã
BASEã§ãä¾å¤ãªããå°å
¥ãããã¨ã§APIã®ã¬ã¹ãã³ã¹ã¿ã¤ã ã 0.05ã0.1ç§
ç¨åº¦å¢å ãã¾ããã
BASEã§ã¯RDS Proxy ã«ããå¤æ®µã«ãªã£ããã¨ã«ãããä»æ¹ã®ãªãã³ã¹ãã¨ãã¦ãå°æ¥ã®ã¢ã¯ã»ã¹å®å®æ§ãåã許容ãããã¨ã«ãã¾ããã
ã¢ãã¿ãªã³ã°ã®çµ±åã«ã¤ãã¦
BASEã§ã¯ç£è¦ãµã¼ãã¹ã¨ã㦠Mackerel ã New Relic ãå©ç¨ããã¢ãã¿ãªã³ã°ãã¦ããã®ã§ãããRDS Proxyã®ã¡ããªã¯ã¹ããããã« çµ±åã§ãã¾ããã§ãããï¼ çµ±åãããã¨ã¯ã§ãã¾ãï¼ä¸ã«è¿½è¨ããï¼ï¼
RDS Proxyã¯ãã¾ã ã¾ã å©ç¨è ãå¤ãã¨è¨ããç£è¦ãµã¼ãã¹å´ã§é©ç¨ããã¦ããªãã®ã ã¨æãã¾ãã ä»å¾ãRDS Proxyã®å©ç¨è ãå¢ãã¦ããã°å¯¾å¿ããã¦ããå¯è½æ§ãããããããã¾ããã
以ä¸ããåãµã¼ãã¹ã®ã¡ããªã¯ã¹ã«ãªãã¾ãã®ã§ãç¶æ³ã¯ãã¡ãã§ç¢ºèªãã ããã
- Mackerel - AWSã¤ã³ãã°ã¬ã¼ã·ã§ã³ - RDS
- NewRelic - Amazon RDS monitoring integration
2023/03/10 追è¨
ä¸è¨ãã¼ã¸ã®ã¡ããªã¯ã¹ã¯æ§æ¥ããã®API Pollingã®å¯¾å¿è¡¨ã§ãããæ°è¦ã®å¯¾å¿ããã¦ããªãããã ããã§ãã CloudWatch Metric Streams ã§ã®å¯¾å¿ããããã¨ã§ãçµ±åãããã¨ãå¯è½ã§ãã ï¼New Relic ã®æ å½è æ§ãããé£çµ¡ããã ãã¾ãããããããããï¼
å°å ¥å¾ã«çºçããé害
ããã¯æ¤è¨¼ã§çºè¦ã§ããªãã£ãBASEã§çºçããé害ï¼å¤±æè«ï¼ã«ãªãã¾ãã ã¤ã¾ãç°å¢ã«ä¾åããå 容ãå«ã¾ãã¾ãããåèã«ãªãã°ã¨ãããã¨ã§æ¸ãã¦ããã¾ãã
é·æéæ¥ç¶åé¡
BASEãµã¼ãã¹ã«ã¯å¸¸æåä½ãã¦ããWorkerãããã¾ãã ãã¡ããPHPã§å®è£ ããã¦ãããåºæ¬ã¯ããã»ã¹ãçãã¦ããéã¯DBã¸æ¥ç¶ããã£ã±ãªãã«ãªã£ã¦ããã®ã§ããããããå½±é¿ãã¨ã©ã¼ãçºçãã¾ããã
RDS Proxy ã®å°å
¥åã¯ãMySQLã®è¨å®å¤ wait_timeout = 28800 (8æéã»ããã©ã«ãå¤)
ã«ããé·æéæ¥ç¶ãã§ãã¦ããã®ã§ãããRDS Proxy ã®å°å
¥å¾ã¯ãå段ã®RDS Proxyãµã¤ãã§ã¿ã¤ã ã¢ã¦ãã«ããåæããã¦ãã¾ããã¨ãåå ã§ããã
RDS Proxy ã«ã¯ãã¢ã¤ãã«ã¯ã©ã¤ã¢ã³ãã®æ¥ç¶ã¿ã¤ã ã¢ã¦ã(IdleClientTimeout)
ã¨ããè¨å®ããããããã30å
ã«ãªã£ã¦ãããããã¿ã¤ã ã¢ã¦ããããã¾ã§ãããçæéã§é »çºããããã«ãªã£ã¦ãã¾ããã
ä»åã¯ãããMySQLã®æéã¨åã 8æé
ã«è¨å®ãã ãã¨ã§è§£æ±ºãã¾ããã
ããã©ã«ãå¤ã30å
ã§ãã®ã§ãDBæ¥ç¶ãé·æéç¶æããé¨åãããå ´åã¯æ³¨æãå¿
è¦ã§ãã
大éã®ã¬ã³ã¼ããçºçãããã®ã¯æ¥µç«¯ã«ã¬ã¤ãã³ã·ã¼ãçºçãã
RDS Proxyå°å ¥å¾ããããã¼ã¸ãç¹å®ã¦ã¼ã¶ã§è¡¨ç¤ºã§ããªãç¾è±¡ãçºçãã¾ããã
åå 調æ»ããçµæãSQLã¯ã¨ãªã®çµæã大éã¬ã³ã¼ããè¿ããã¨ãåãããRDS Proxyå°å ¥å¾ããã®ã¯ã¨ãªã ããç°å¸¸ã«é ããªã£ã¦ãããã¨ãåããã¾ãããï¼æ°ç§ç¨åº¦ã ã£ãã¬ã¹ãã³ã¹ããæ°åãããããã«ãªã£ã¦ããï¼
転éã¬ã³ã¼ãéãé©åã«ãªãããä¿®æ£ãã ãã¨ã§ããã解決ãã¾ããã
å ¬å¼ã«è¨è¿°ã¯ãªãã®ã§ãããå¤æ®µã«ãªã£ããã¨ã§è»¢éãéã«å¿ãã¦æéããããããã«ãªã£ãã®ã§ã¯ãªããã¨æ³åãã¦ãã¾ãã å®éãDBã¯ã©ã¤ã¢ã³ããªã©ã§ã大éã¬ã³ã¼ããè¿ãåãã¯ã¨ãªããRDSç´æ¥ç¶ã¨ãRDS Proxyçµç±æ¥ç¶ããå ´åã§æ¯è¼ããã¨æããã«ã¬ã¹ãã³ã¹ã¿ã¤ã ãå¤ãã£ã¦æ¥ã¾ãã
大éã¬ã³ã¼ããè¿ãå¦çãããå ´åã«ã¯æ³¨æãã¤ã³ãã ã¨æãã¾ãã
ã¯ã¨ãªæ°ã®èª¿æ»
é害ã§ã¯ãªãã§ãããåè¿°ããéãã¯ã¨ãªæ°ã«å¿ãã¦ã¬ã¤ãã³ã·ã¼ãçºçãããã¨ãåãã£ã¦ããã®ã§ãå¾è¿½ãã§ï¼ãªã¯ã¨ã¹ãã®ã¯ã¨ãªæ°ã®èª¿æ»ãå®æ½ãã¾ããã
調æ»ã®çµæãN+1åé¡ãã¡ãã»ãçºçãã¦ãããã¨ã確èªã§ããã®ã§ãã²ã©ããã®ã«é¢ãã¦ã¯å³æ対å¿ãå®æ½ãã¾ããã ããã¯RDS Proxyé¢ä¿ãªãã±ã¢ãã¦ããããã¨ããã§ãã
RDS Proxy èªä½ã®è¨å®å¤æ´ã¯å®è¡ä¸ãå°å ¥ã¦ã¼ã¶ã¸ã®å½±é¿ã¯ãªã
ä¸è¨ã«è¨è¼ãããããªãããã¤ãã®ãã©ãã«ãçºçããRDS Proxyã®è¨å®ãå¤æ´ãããå ´åãããã¾ããã
ã¢ã¤ãã«ã¯ã©ã¤ã¢ã³ãã®æ¥ç¶ã¿ã¤ã ã¢ã¦ã(IdleClientTimeout)
ã®èª¿æ´ããRDS Proxyã® ãã°è¨é²ãæå¹
ã«ãããå ´åãªã©ã§ãã
AWSãµã¤ãã«ã確èªããã¾ãããããããã®å¤æ´ã¯ãã¦ã³ã¿ã¤ã ãªãã§åãæ¿ãããããæ°è»½ã«å¤æ´ãã¦ã大ä¸å¤«ã®ããã§ãã
ã¾ã¨ã
BASE ã RDS Proxy ãå°å ¥ãããã¨ã§å¾ãã¡ãªããã»ãã¡ãªãããã¾ã¨ããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
ã¡ãªãã
- MySQLã¸ã®æ¥ç¶ãè¶
å®å®
- ããã«ããã¯ãå¥ã«ç§»ã£ãã¨è¨ã£ã¦ãéè¨ã§ã¯ãªãã»ã©ã®å®å®æ¥ç¶ãç²å¾ã§ãã
- è²»ç¨çãªã¡ãªãããããã
- æ¬æ¥ãRDS Proxyã«ã¯ã³ã¹ãããããããRDSã®ã¤ã³ã¹ã¿ã³ã¹ãæ¸ãããã¨ãã§ãããããå®è³ªã³ã¹ããã¦ã³ã«ãªã£ã
- PHPã¨ã®ç¸æ§ãé常ã«ããã£ã
- æ¯ã¢ã¯ã»ã¹ã§æ¥ç¶åæãç¹°ãè¿ããããªè¨èªãã¢ããªã±ã¼ã·ã§ã³ï¼
PHP
ããµã¼ãã¼ã¬ã¹ã¢ããªã±ã¼ã·ã§ã³
ãªã©ï¼ã¨ã¯ç¸æ§ãè¯ãå¯è½æ§ãã
- æ¯ã¢ã¯ã»ã¹ã§æ¥ç¶åæãç¹°ãè¿ããããªè¨èªãã¢ããªã±ã¼ã·ã§ã³ï¼
ãã¡ãªããï¼ä»å¾ã®èª²é¡ã許容ããå¯ä½ç¨ï¼
- è¥å¹²ã®ã¬ã¤ãã³ã·ã¼ãçºçãã
- BASEã§ã¯RDS Proxyãæãåãä»æ¹ã®ãªãã³ã¹ãã¨èãã
- ããã¸ã§ã¯ãã«ãã£ã¦ã¯è¨±å®¹ã§ããªãå¯è½æ§ãããã®ã§æ³¨æãå¿ è¦
- ç¾ç¶ã¯ç£è¦ãµã¼ãã¹ã§ã¢ãã¿ãªã³ã°çµ±åãã§ããªã
BASEã§ã¯RDS Proxyãå°å ¥ãããã¨ã§ãå®å®ããæ¥ç¶ãã§ããããã«ãªããä»å¾å¢ãã¦ããã§ãããã¢ã¯ã»ã¹ãè¿ãå ¥ããæºåãã§ããé常ã«å¤§ããªã¡ãªããããã£ãã¨èãã¦ãã¾ãã ãã®è¨äºããçæ§ã®RDS Proxyå°å ¥æ¤è¨ã®åèã«ãªãã°å¬ããã§ãã
以ä¸ãBASEã§ã®RDS Proxyå°å ¥ã¬ãã¼ãã§ããã
æå¾ã«
BASEã§ã¯ããã®ããã«æä¾ãããµã¼ãã¹ãå©ç¨ãã¦ãã ããè³¼å ¥è ãã·ã§ãããªã¼ãã¼ã®çæ§ã®ãã¨ã第ä¸ã«èãã¦ãæ§ã ãªè§åº¦ãããµã¼ãã¹ãå ±ã«çºå±ããã¦ãã仲éãåéãã¦ããã¾ãã ã«ã¸ã¥ã¢ã«é¢è«ãå®æ½ãã¦ããã¾ãã®ã§ããã²ãæ°è»½ã«ãåãåãããã ããã