X5ã§ã¯ãã©ãã«ä»ããããååã远跡ããæ¿åºããµãã©ã€ã€ãŒãšããŒã¿ã亀æããã·ã¹ãã ã¯ãMarkusããšåŒã°ããŠããŸããã©ã®ããã«ããŠèª°ãéçºããã®ããã©ã®ãããªæè¡ã¹ã¿ãã¯ãããã®ãââããããŠãªãç§ãã¡ãèªãã«æããã®ãããã®ãââãé çªã«èª¬æããŸãããã
å®HighLoad
ãMarkusãã¯å€ãã®åé¡ã解決ããŸãããã®äž»ãªãã®ã¯ãæ å ±ã·ã¹ãã X5ãšã©ãã«ä»ã補åã®ç¶æ æ å ±ã·ã¹ãã ïŒGIS MPïŒéã®çµ±åçžäºäœçšã§ãããã©ãã«ä»ã補åã®åãã远跡ããŸãããŸãããã©ãããã©ãŒã ã¯ãç§ãã¡ãåãåã£ããã¹ãŠã®ããŒãã³ã°ã³ãŒããšããªããžã§ã¯ãéã§ã®ãããã®ã³ãŒãã®ç§»åã®å šå±¥æŽãä¿åããã®ã§ãããŒã¯ããã補åã®ååé¡ãæé€ã§ããŸããã©ãã«ä»ãååã®æåã®ã°ã«ãŒãã«å«ãŸããŠãããã°ã補åã®äŸã§ã¯ããã°ãã®1ã€ã®ãã©ãã¯ã®ã¿ã«çŽ60äžããã¯ãå«ãŸããŠãããããããã«ç¬èªã®ã³ãŒãããããŸãããããŠãç§ãã¡ã®ã·ã¹ãã ã®ã¿ã¹ã¯ã¯ãå庫ãšåºèã®éã®ãã®ãããªåããã¯ã®åãã®åæ³æ§ã远跡ããã³ãã§ãã¯ããæçµçã«ãšã³ããŠãŒã¶ãŒãžã®å®è£ ã®èš±å®¹æ§ããã§ãã¯ããããšã§ãããããŠã1æéãããçŽ125,000ã®çŸéååŒãèšé²ããŸãããŸãããã®ãããªåããã¯ãã©ã®ããã«åºã«å ¥ã£ãããèšé²ããããšãå¿ èŠã§ãããããã£ãŠããªããžã§ã¯ãéã®ãã¹ãŠã®åããèæ ®ãããšã幎éæ°çŸåã®ã¬ã³ãŒããäºæ³ãããŸãã
ããŒã M
ãMarkusãã¯X5å ã®ãããžã§ã¯ããšèŠãªãããŠããŸããã補åã®ã¢ãããŒãã«åŸã£ãŠå®è£ ãããŠããŸããããŒã ã¯ã¹ã¯ã©ã ã«åãçµãã§ããŸãããããžã§ã¯ãã®éå§ã¯æšå¹Žã®å€ã§ããããæåã®çµæã¯10æã«ãªã£ãŠåããŠåŸãããŸããã圌ãã®ããŒã ã¯å®å šã«çµã¿ç«ãŠãããã·ã¹ãã ã¢ãŒããã¯ãã£ãéçºãããæ©åšãè³Œå ¥ãããŸãããçŸåšãããŒã ã«ã¯16人ãããããã®ãã¡6人ã¯ããã¯ãšã³ããšããã³ããšã³ãã®éçºã«åŸäºããŠããã3人ã¯ã·ã¹ãã åæã«åŸäºããŠããŸããããã«6人ããæåãããŒããèªåãã¹ãããã³è£œåãµããŒãã«é¢äžããŠããŸããããã«ãSREã¹ãã·ã£ãªã¹ããããŸãã
ç§ãã¡ã®ããŒã ã®ã³ãŒãã¯éçºè ã ãã§ãªããã»ãšãã©ãã¹ãŠã®äººãèªåãã¹ããããŒãã¹ã¯ãªãããèªååã¹ã¯ãªããã®ããã°ã©ãã³ã°ãšèšè¿°ã®æ¹æ³ãç¥ã£ãŠããŸãã補åãµããŒãã§ãããé«åºŠãªèªååãå¿ èŠãªãããç§ãã¡ã¯ããã«ç¹å¥ãªæ³šæãæããŸããç§ãã¡ã¯åžžã«ã以åã«ããã°ã©ã ããããšããªãååã«ã¢ããã€ã¹ãæäŸããå°ããªã¿ã¹ã¯ãæ©èœãããããã«åªããŠããŸãã
ã³ãããŠã€ã«ã¹ã®ãã³ãããã¯ã«é¢é£ããŠãç§ãã¡ã¯ããŒã å šäœããªã¢ãŒãäœæ¥ã«è»¢éãããã¹ãŠã®éçºç®¡çããŒã«ã®å¯çšæ§ãJiraãšGitLabã§æ§ç¯ãããã¯ãŒã¯ãããŒã«ããããã®æ®µéãç°¡åã«ééã§ããŸãããé¢ããå Žæã§éãããæ°ãæã¯ãããŒã ã®çç£æ§ãããã«åœ±é¿ãããªãããšã瀺ããŸãããå€ãã®ä»äºã®å¿«é©ããå¢ãããããå¯äžã®ããšã¯ååãªã©ã€ãã³ãã¥ãã±ãŒã·ã§ã³ããªãããšã§ãã
é ãé¢ããããŒã ããŒãã£ã³ã°
ãªã¢ãŒãäŒè°
ãœãªã¥ãŒã·ã§ã³æè¡ã¹ã¿ãã¯
X5ã®æšæºãªããžããªããã³CI / CDããŒã«ã¯GitLabã§ããã³ãŒãã®ä¿åãç¶ç¶çãªãã¹ãããã¹ããµãŒããŒãšéçšãµãŒããŒãžã®å±éã«äœ¿çšããŸãããŸããéçºè ãã³ãŒãã«å ããå€æŽãå°ãªããšã2人ã®ååãæ¿èªããå¿ èŠãããå Žåã¯ãã³ãŒãã¬ãã¥ãŒã®ææ³ã䜿çšããŸããéçã³ãŒãã¢ãã©ã€ã¶ãŒSonarQubeãšJaCoCoã¯ãã³ãŒããã¯ãªãŒã³ã«ä¿ã¡ãå¿ èŠãªã¬ãã«ã®åäœãã¹ãã«ãã¬ããžãæäŸããã®ã«åœ¹ç«ã¡ãŸããã³ãŒãã®ãã¹ãŠã®å€æŽã¯ããããã®ãã§ãã¯ãééããå¿ èŠããããŸããæåã§å®è¡ããããã¹ãŠã®ãã¹ãã¹ã¯ãªããã¯ããã®åŸèªååãããŸãã
ãMarkusãã«ããããžãã¹ããã»ã¹ã®å®è¡ãæåãããã«ã¯ãããããé çªã«ããã€ãã®æè¡çãªåé¡ã解決ããå¿ èŠããããŸããã
ã¿ã¹ã¯1.ã·ã¹ãã ã®æ°Žå¹³æ¹åã®ã¹ã±ãŒã©ããªãã£ã®å¿ èŠæ§
ãã®åé¡ã解決ããããã«ãã¢ãŒããã¯ãã£ãžã®ãã€ã¯ããµãŒãã¹ã¢ãããŒããéžæããŸãããåæã«ããµãŒãã¹ã®è²¬ä»»ç¯å²ãç解ããããšã¯éåžžã«éèŠã§ãããããã»ã¹ã®è©³çŽ°ãèæ ®ããŠãããããããžãã¹ãªãã¬ãŒã·ã§ã³ã«åå²ããããšããŸãããããšãã°ãå庫ã§ã®åãå ¥ãã¯ããã»ã©é »ç¹ã§ã¯ãããŸããããéåžžã«èšå€§ãªäœæ¥ã§ãããã®éãåãåã£ãååã®åäœã«é¢ããæ å ±ãå¯èœãªéãè¿ éã«å·ã®èŠå¶åœå±ããå ¥æããå¿ èŠããããŸããå庫èªååã·ã¹ãã ã«å¿ èŠãªæ å ±ãããããå庫ããã®çºéã¯ã¯ããã«éäžçã«è¡ãããŸãããåæã«å°éã®ããŒã¿ã§åŠçãããŸãã
ç§ãã¡ã¯ãã¹ãŠã®ãµãŒãã¹ãã¹ããŒãã¬ã¹ã®ååã«åºã¥ããŠå®è£ ããKafkaã»ã«ããããã¯ãšåŒã°ãããã®ã䜿çšããŠãå éšæäœãã¹ãããã«åå²ããããšãè©Šã¿ãŸããããã¯ããã€ã¯ããµãŒãã¹ãããèªäœã«ã¡ãã»ãŒãžãéä¿¡ãããšãã§ããããã«ããããªãœãŒã¹ãéäžçã«äœ¿çšããæäœã®è² è·ãåæ£ãã補åã®ã¡ã³ããã³ã¹ãç°¡ç¥åã§ããŸãããåŸã§ããã«è©³ãã説æããŸãã
å€éšã·ã¹ãã ãšã®å¯Ÿè©±çšã®ã¢ãžã¥ãŒã«ãåå¥ã®ãµãŒãã¹ã«åé¢ããããšã«ããŸãããããã«ãããé »ç¹ã«å€æŽãããå€éšã·ã¹ãã ã®APIã®åé¡ã解決ã§ããããžãã¹æ©èœãåãããµãŒãã¹ã«å®è³ªçã«åœ±é¿ãäžããŸããã
ãã¹ãŠã®ãã€ã¯ããµãŒãã¹ã¯OpenShiftã¯ã©ã¹ã¿ãŒã«ãããã€ãããåãã€ã¯ããµãŒãã¹ã®ã¹ã±ãŒãªã³ã°ã®åé¡ã解決ãããµãŒãããŒãã£ã®ãµãŒãã¹æ€åºããŒã«ã䜿çšããªãããã«ããŸãã
ã¿ã¹ã¯2.ãã©ãããã©ãŒã ãµãŒãã¹éã§é«è² è·ãšéåžžã«éäžçãªããŒã¿äº€æãç¶æããå¿ èŠæ§ïŒãããžã§ã¯ãã®èµ·åãã§ãŒãºã§ã®ã¿ãæ¯ç§çŽ600ã®æäœãå®è¡ãããŸãããã¬ãŒãã£ã³ã°ãªããžã§ã¯ãããã©ãããã©ãŒã ã«æ¥ç¶ãããšããã®å€ã¯æ倧5000 op / secã«ãªããšäºæ³ãããŸãã
ãã®ã¿ã¹ã¯ã¯ãKafkaã¯ã©ã¹ã¿ãŒããããã€ãããã©ãããã©ãŒã ãã€ã¯ããµãŒãã¹éã®åæéä¿¡ãã»ãŒå®å šã«ç Žæ£ããããšã§è§£æ±ºããŸããããã¹ãŠã®æäœãéåæã§ãããšã¯éããªããããã·ã¹ãã èŠä»¶ã®éåžžã«æ³šææ·±ãåæãå¿ èŠã§ããåæã«ããããŒã«ãŒãä»ããŠã€ãã³ããéä¿¡ããã ãã§ãªããå¿ èŠãªãã¹ãŠã®ããžãã¹æ å ±ãã¡ãã»ãŒãžã§éä¿¡ããŸãããããã£ãŠãã¡ãã»ãŒãžã®ãµã€ãºã¯æ倧ã§æ°çŸãããã€ãã«ãªãå¯èœæ§ããããŸãã Kafkaã§ã®ã¡ãã»ãŒãžã®éã®å¶éã«ãããã¡ãã»ãŒãžã®ãµã€ãºãæ£ç¢ºã«äºæž¬ããå¿ èŠããããŸããå¿ èŠã«å¿ããŠãã¡ãã»ãŒãžãåå²ããŸãããåå²ã¯è«ççã§ãããæ¥åã«é¢é£ããŠããŸãã
ããšãã°ãååãè»ã«å±ããããç®±ã«åããŸããåææäœã®å Žåãåå¥ã®ãã€ã¯ããµãŒãã¹ãå²ãåœãŠãããå³å¯ãªè² è·ãã¹ããå®è¡ãããŸãã Kafkaã䜿çšãããšãå¥ã®èª²é¡ãçºçããŸãããKafkaçµ±åã§ãµãŒãã¹ããã¹ããããšããã¹ãŠã®åäœãã¹ããéåæã«ãªããŸãã Embedded Kafka Brokerã䜿çšããŠç¬èªã®å®çšçãªã¡ãœãããäœæããããšã«ããããã®åé¡ã解決ããŸãããããã«ãããåã ã®ã¡ãœããã®åäœãã¹ããäœæããå¿ èŠããªããªãããã§ã¯ãããŸããããKafkaã䜿çšããŠè€éãªã±ãŒã¹ããã¹ãããããšããå§ãããŸãã
ãµãŒãã¹ã®æäœäžã«äŸå€ãçºçããããKafkaãããã§äœæ¥ããŠãããšãã«TraceIdã倱ãããªãããã«ããã°ã®ãã¬ãŒã¹ã«å€ãã®æ³šæãæããŸãããæåã®è³ªåã§ç¹å¥ãªè³ªåããªãã£ãå Žåã2çªç®ã®ã±ãŒã¹ã§ã¯ããããã®ãã¹ãŠã®TraceIdããã°ã«èšé²ãããã¬ãŒã¹ãç¶è¡ããããã«1ã€ãéžæããããšã匷å¶ãããŸãããã®åŸãæåã®TraceIdãæ€çŽ¢ãããšããŠãŒã¶ãŒã¯ãã¬ãŒã¹ãã©ã®ãã¬ãŒã¹ã§ç¶ç¶ããããç°¡åã«èŠã€ããããšãã§ããŸãã
ç®ç3.倧éã®ããŒã¿ãä¿åããå¿ èŠæ§ïŒãã°ãã ãã§å¹Žé10åãè¶ ããã©ãã«ãX5ã«éä¿¡ãããŸãã圌ãã¯äžå®ãã€è¿ éãªã¢ã¯ã»ã¹ãå¿ èŠãšããŸããåèšã§ãã·ã¹ãã ã¯ãããã®ããŒã¯ãããååã®ç§»åã®å±¥æŽã«é¢ããçŽ100åã®ã¬ã³ãŒããåŠçããå¿ èŠããããŸãã
3çªç®ã®åé¡ã解決ããããã«ãMongoDB NoSQLããŒã¿ããŒã¹ãéžæãããŸããã 5ã€ã®ããŒãã®ã·ã£ãŒããæ§ç¯ããåããŒãã«3ã€ã®ãµãŒããŒã®ã¬ããªã«ã»ãããäœæããŸãããããã«ãããã·ã¹ãã ãæ°Žå¹³æ¹åã«ã¹ã±ãŒãªã³ã°ããæ°ãããµãŒããŒãã¯ã©ã¹ã¿ãŒã«è¿œå ããŠããã©ãŒã«ããã¬ã©ã³ã¹ã確ä¿ã§ããŸããããã§ãå¥ã®åé¡ã«çŽé¢ããŸãã-æ°Žå¹³æ¹åã«ã¹ã±ãŒã©ãã«ãªãã€ã¯ããµãŒãã¹ã®äœ¿çšãèæ ®ã«å ¥ããŠãmongoã¯ã©ã¹ã¿ãŒã®ãã©ã³ã¶ã¯ã·ã§ã³æ§ãä¿èšŒããŸããããšãã°ãã·ã¹ãã ã®ã¿ã¹ã¯ã®1ã€ã¯ãåãããŒãã³ã°ã³ãŒãã§ååã転売ããè©Šã¿ãæ€åºããããšã§ããããã§ããªãŒããŒã¬ã€ã¯èª€ã£ãã¹ãã£ã³ãŸãã¯èª€ã£ãã¬ãžæäœã§è¡šç€ºãããŸãããã®ãããªéè€ã¯ãKafkaã§åŠçããã1ã€ã®ãããå ãšã䞊è¡ããŠåŠçããã2ã€ã®ãããå ã®äž¡æ¹ã§çºçããå¯èœæ§ãããããšãããããŸããããããã£ãŠãããŒã¿ããŒã¹ãç §äŒããŠéè€ããã§ãã¯ããŠãäœãèµ·ãããŸããã§ãããåãã€ã¯ããµãŒãã¹ã«ã€ããŠããã®ãµãŒãã¹ã®ããžãã¹ããžãã¯ã«åºã¥ããŠåå¥ã«åé¡ã解決ããŸãããããšãã°ãé åæžã«ã€ããŠã¯ããããå ã«ãã§ãã¯ãè¿œå ããæ¿å ¥æã«éè€ã衚瀺ããããã®åå¥ã®åŠçãè¿œå ããŸããã
æäœã®å±¥æŽãæã€ãŠãŒã¶ãŒã®äœæ¥ãæãéèŠãªããšã«åœ±é¿ãäžããªãããã«-ç§ãã¡ã®ããžãã¹ããã»ã¹ã®æ©èœ-ãã¹ãŠã®å±¥æŽããŒã¿ããKafkaãéããŠæ å ±ãåä¿¡ããå¥ã®ããŒã¿ããŒã¹ãæã€å¥ã®ãµãŒãã¹ã«åé¢ããŸããããããã£ãŠããŠãŒã¶ãŒã¯ãçŸåšã®æäœã«é¢ããããŒã¿ãåŠçãããµãŒãã¹ã«åœ±é¿ãäžããããšãªããåé¢ããããµãŒãã¹ã§äœæ¥ããŸãã
ã¿ã¹ã¯4.ãã¥ãŒã®ååŠçãšç£èŠïŒ
åæ£ã·ã¹ãã ã§ã¯ãããŒã¿ããŒã¹ããã¥ãŒãããã³å€éšããŒã¿ãœãŒã¹ã®å¯çšæ§ã«é¢ããåé¡ãšãšã©ãŒãå¿ ãçºçããŸãã Markusã®å Žåããã®ãããªãšã©ãŒã®åå ã¯å€éšã·ã¹ãã ãšã®çµ±åã§ããæå®ãããã¿ã€ã ã¢ãŠãã§èª€ã£ãå¿çãç¹°ãè¿ãèŠæ±ã§ããããã«ããããåæã«ã¡ã€ã³ãã¥ãŒã§ã®æåããèŠæ±ã®åŠçãåæ¢ããªããœãªã¥ãŒã·ã§ã³ãèŠã€ããå¿ èŠããããŸããããã®ãããããããããããã¯ããŒã¹ã®åè©Šè¡ãã®æŠå¿µãéžæãããŸãããã¡ã€ã³ãããã¯ããšã«ã1ã€ãŸãã¯è€æ°ã®åè©Šè¡ãããã¯ãäœæãããããã«èª€ã£ãã¡ãã»ãŒãžãéä¿¡ãããŸããåæã«ãã¡ã€ã³ãããã¯ããã®ã¡ãã»ãŒãžã®åŠçã®é 延ã解æ¶ãããŸããçžäºäœçšã¹ããŒã -
ãã®ãããªã¹ããŒã ãå®è£ ããã«ã¯ããã®ãœãªã¥ãŒã·ã§ã³ãSpringãšçµ±åããã³ãŒãã®éè€ãé¿ããããã«ã次ã®ããšãå¿ èŠã§ãããåºå€§ãªãããã¯ãŒã¯ã®äžã§ãSpring BeanPostProccessorã«åºã¥ãåæ§ã®ãœãªã¥ãŒã·ã§ã³ã«åºããããŸããããäžå¿ èŠã«é¢åã§ããããã«èŠããŸãããç§ãã¡ã®ããŒã ã¯ãSpringã®ã³ã³ã·ã¥ãŒããŒäœæãµã€ã¯ã«ã«çµ±åããããã«ãªãã©ã€ã³ã³ã·ã¥ãŒããŒãè¿œå ã§ããããã«ããã·ã³ãã«ãªãœãªã¥ãŒã·ã§ã³ãäœæããŸããã SpringããŒã ã«ãœãªã¥ãŒã·ã§ã³ã®ãããã¿ã€ããæäŸããŸããããã¡ãã§ã芧ããã ããŸããåè©Šè¡ã³ã³ã·ã¥ãŒãã®æ°ãšåã³ã³ã·ã¥ãŒãã®è©Šè¡åæ°ã¯ãããžãã¹ããã»ã¹ã®ããŒãºã«å¿ããŠãã©ã¡ãŒã¿ãä»ããŠèšå®ãããŸãããã¹ãŠãæ©èœããããã«ã¯ããã¹ãŠã®Springéçºè ã«ããç¥ãããŠããorg.springframework.kafka.annotation.KafkaListenerã¢ãããŒã·ã§ã³ãé 眮ããã ãã§ãã
ãã¹ãŠã®åè©Šè¡ã®è©Šè¡åŸã«ã¡ãã»ãŒãžãåŠçã§ããªãã£ãå ŽåãSpring DeadLetterPublishingRecovererã䜿çšããŠDLTïŒãããã¬ã¿ãŒãããã¯ïŒã«éä¿¡ãããŸãããµããŒãã®èŠè«ã«å¿ããŠããã®æ©èœãæ¡åŒµããDLTã«å ¥ã£ãã¡ãã»ãŒãžãstackTraceãtraceIdããã³ãã®ä»ã®æçšãªæ å ±ã衚瀺ã§ããåå¥ã®ãµãŒãã¹ãäœæããŸãããããã«ããã¹ãŠã®DLTãããã¯ã«ç£èŠãšã¢ã©ãŒããè¿œå ãããŸãããå®éãDLTãããã¯ã«ã¡ãã»ãŒãžã衚瀺ãããããšãã解æãšæ¬ é¥ã®åå ãšãªã£ãŠããŸããããã¯éåžžã«äŸ¿å©ã§ãããããã¯ã®ååãããããã»ã¹ã®ã©ã®æ®µéã§åé¡ãçºçããããããã«ããããããæ ¹æ¬åå ã®æ€çŽ¢ãå€§å¹ ã«é«éåãããŸãã
æè¿ã§ã¯ãåå ãåãé€ããåŸïŒããšãã°ãå€éšã·ã¹ãã ã®æäœæ§ã埩å ããåŸïŒã察å¿ããæ¬ é¥ãåæçšã«ç¢ºç«ããåŸããµããŒãã«ãã£ãŠã¡ãã»ãŒãžãåéä¿¡ã§ããã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ããŸãããããã¯ãèªå·±ãããã¯ã圹ç«ã€å Žæã§ããé·ãåŠçãã§ãŒã³ãåéããªãããã«ãåžæã®ã¹ãããããåéã§ããŸãã
ãã©ãããã©ãŒã æäœ
ãã©ãããã©ãŒã ã¯ãã§ã«çç£çã«çšŒåããŠãããæ¯æ¥é éãšåºè·ãè¡ããæ°ããé éã»ã³ã¿ãŒãšåºèãã€ãªãã§ããŸãããã€ãããã®äžéšãšããŠãã·ã¹ãã ã¯ååã°ã«ãŒããã¿ãã³ããšãéŽãã§æ©èœããŸãã
ããŒã å šäœãããã€ãããã®å®æœãæ°ããªåé¡ã®åæããã°ã®æ¹åããããã»ã¹ã®å€æŽãŸã§ã補åãæ¹åããããã®ææ¡ãè¡ãããšã«é¢äžããŠããŸãã
ç§ãã¡ã®éã¡ãç¹°ãè¿ããªãããã«ããã€ãããäžã«çºèŠããããã¹ãŠã®ã±ãŒã¹ã¯èªåãã¹ãã«åæ ãããŸããå€æ°ã®èªåãã¹ããšåäœãã¹ããååšãããããååž°ãã¹ããå®è¡ããä¿®æ£ããã°ã©ã ãæ°æéã§æå ¥ã§ããŸãã
çŸåšãç§ãã¡ã¯ãã©ãããã©ãŒã ã®éçºãšæ¹åãç¶ããŠãããåžžã«æ°ãã課é¡ã«çŽé¢ããŠããŸããèå³ããæã¡ã®æ¹ã¯ã以äžã®èšäºã§ãœãªã¥ãŒã·ã§ã³ã«ã€ããŠãç¥ããããŸãã