ISUCON 5ã®äºé¸ã§2æ¥ç®3ä½ãå ¨ä½ã§5ä½ã®ã¹ã³ã¢ã§ééããã
ã¡ã³ãã¼ã¯ id:ntakanashi ãã, id:astj ããã¨èªåã®3人ã§ããã¯ãã¡ãããã¨ãããããããã¼ã åã§åå ããã è¨èªã¯å½ç¶Perlã å½¹å²åæ 㯠id:astj ããã®è¨äºã«ãæ¸ãã¦ãããã©ãã ããã以ä¸ã®ãããªãã®ã ã£ãã
id:y_uuki : ããã«ã¦ã§ã¢ããä¸ããä»»ã / ãã°è§£æãã¦æ¹åãã¤ã³ãã®æ´ãåºã id:ntakanashi : ãªã³ã¡ã¢ãªã«ãããã¢ã¸ã¥ã¼ã«ãå ¥ãæ¿ããã諸ã ãã¥ã¼ãã³ã° id:astj : ã¯ã½ã¯ã¨ãªãN+1ãã¡ã¾ã¡ã¾æ½°ãã¦ãã
ISUCON 5ã®äºé¸ã«åå ãã¦å ¨ä½5ä½ã§ééãã¾ãã - 平常é転
æ¨å¹´ã®ISUCON 4ã«åå ããã¨ãã«ãå°ãªãã¨ãISUCONäºé¸ã«ããã¦ã¯ã¢ããªã±ã¼ã·ã§ã³ãã¸ãã¯ã®æ¹å/æ¹å¤ãã¹ã³ã¢ã«å¯¾ãã¦æ¯é çã ã¨æãã¦ããã ããã§ãã¤ã³ãã©æ å½ã®æåã®ä»äºã¯ããã«ãã¦ã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã«ãã¸ãã¯ã®æ¹åã«éä¸ã§ããç°å¢ãä½ããã¨ãããã¨ã ã¨èããã ããã«ãã¤ã³ãã©ã¨ã³ã¸ãã¢ã¯æ®æ®µããã·ã¹ãã å ¨ä½ã俯ç°ãããã¨ãæ±ããããã®ã§ãã¤ã³ã¹ã¿ã³ã¹ãµã¤ãºãªã©ä¸ããããæ¡ä»¶ã¨ã·ã¹ãã å ¨ä½ãã¿ã¦ã·ã¹ãã ã®æ§è³ªãæãããã¨ãéè¦ã ã¨æãã ä»åã®æå®ã¤ã³ã¹ã¿ã³ã¹ã¯CPU4ã³ã¢ãã¡ã¢ãª4GBå¼±ã¨å»å¹´ããã¡ã¢ãªæè¼éãããªãå°ãªãã£ãã®ã§ãããã¯ãã¤ãã®ãããªãªã³ã¡ã¢ãªåè² ã¯å³ããã®ã§ã¯ãªããã¨ããããã¤ãã¦ãããå®éãæ®éã«èããã¨ãã¼ã¿ãµã¤ãºãOSã®ã¡ã¢ãªã«ä¹ããªãéï¼ä¸é¨ã®ãã¼ãã«ã¯150ä¸è¡ãããï¼ã ã£ãã®ã§ãåæ段éã§æããã«MySQLã®CPUå©ç¨çã¨ãã£ã¹ã¯I/Oãããã«ããã¯ã ã£ãã ãããã£ã¦ãä»åã®åºé¡æå³ã¯ã¡ã¢ãªã«ä¹ããªããã¼ã¿ãããã«æããã¨ãããã¨ã«ããã¨å¤æããã
ã¤ã³ãã©æ å½ã§ããèªåãå ·ä½çã«ãã£ããã¨ã¯ãã¤ã³ã¹ã¿ã³ã¹ã®æ§ç¯ããããã¤ã®ä»çµã¿ã®æ´åãOS/Nginx/MySQL/memcached/ã¢ããªãµã¼ãã®ãã¥ã¼ãã³ã°ãtopãiostatã«ãããã¼ãã¦ã§ã¢ãªã½ã¼ã¹å©ç¨ç¶æ³ã®ææ¡ãã¢ã¯ã»ã¹ãã°ã¨ã¹ãã¼ã¯ã¨ãªãã°ã®è§£æãªã©ã ã£ãã ä»åã¯ãã³ããã¼ã¯ãã¤ã³ã¹ã¿ã³ã¹ã®ãã¼ã«ã«ã§å®è¡ããè¡ããªãã£ãã®ã§ä¸åä¸åã®ãã³ããã¼ã¯ãç¡é§ã«ããªãããã«ãã©ããä»è¾¼ãã§ãããsysctlãmy.cnfãnginx.confã®ãã¥ã¼ãã³ã°ãUNIX domain socketåãPlackãµã¼ããGazelleã«å¤æ´ãéçãã¡ã¤ã«ã®nginxé ä¿¡ãªã©ã¯åæã®æ®µéã§ä¸æ°ã«ãã£ãã ãããã«ãã£ããã¨ã®ãªããã¥ã¼ãã³ã°ãããã®ã¯ä¸å®ãªã®ã§ãéå»åã§è¨ç·´ãéããã ã¡ãªã¿ã«ã©ããã¹ã³ã¢ã«å½±é¿ããªãï¼ããé«req/sãªç°å¢ã§ã¯å½±é¿ãããããããªãï¼ã¯ã¼ã«ã¼æ°ãã¹ã¬ããæ°ã®èª¿æ´ã«æéããããã®ãç¡é§ãªã®ã§ãã³ã¢æ°åã®ã¯ã¼ã«ã¼ããç«ã¦ãªãã¨æ±ºãã¦ããã ä»å¹´ã¯AWSã§ã¯ãªãGCPã ã£ãã®ã§ãå»å¹´ã®åé¡ãGCEã§æ§ç¯ãä¸éãçãææ¡ãã¦ããããWeb UIããã®å ¬ééµã®è¨å®ãã¹ãããã·ã§ããã®åãæ¹ãªã©ã ããã«ãã£ã¹ããªãCentOSããUbuntuã«å¤æ´ãããããã ã£ãã®ã§ãISUCONã«å¿ è¦ãªUbuntuã®ãªãã¬ã¼ã·ã§ã³ãç·´ç¿ãã¦ããããï¼ã¨ãã£ã¦ãæ®æ®µããDebianãããã£ã¦ãã®ã§ãã¾ãå·®ã¯ãªãï¼systemdã ã£ãã®ã¯é¢ããã£ããã©ããããã¨ã¯å¤§ãã¦å¤ãããªãã£ãã
ããããããã§ãã¯ãªã¹ãããªãã¬ã¼ã·ã§ã³ã¡ã¢ãç¨æãã¦ããã¦ãããã«å¾ã£ã¦ãã°ããè¶³å ´ãçµããã¨ãæèãã¦ããã 13æããã¾ã§ã«ã¯ã ãããæ´ããã®ã§ãã®ãã³ãã³ã¼ãã§ãçºãããã¨æã£ã¦ããããã©ãå¾è¿°ãã大ããã®ãã©ãã«ã®è§£æ±ºãã¡ãã£ã¨ã¤ã³ããã¯ã¹å¼µã£ããã¹ã³ã¢ãå¤åããã¨ãã®ããã«ããã¯ã®å¤åã解æããã¨ãããã¨ããã£ã¨ãã£ã¦ããã ãããã¡ã¤ã©ã¨ãã¦Devel::NYTProfã®æºåãä¸å¿ãã¦ãããã©ããã£ã¹ã¯I/Oãããã¯ã ã£ãã®ã§ä»åã¯ãããªãã£ããããã«ããã¯ãã¢ããªã±ã¼ã·ã§ã³ã®CPUå©ç¨ã«ç§»è¡ãã段éã§ããã¦ãã¨æãã
ããããäºåã«ããããæºåãã¦ããã¨ã¯ãã£ã¦ããã¯ããã©ãã«ã¯ããããããã
ãã©ãã«1: MySQL has gone away
Perlã®DBIã§ã¯MySQLã¨ã®æ¥ç¶ãåæãããç¶æ
ã§SQLãæããã¨ãMySQL has gone away ã¨ããã¨ã©ã¼ã¡ãã»ã¼ã¸ãã§ãã
ããã¿ã¤ãã³ã°ãããã®ã¡ãã»ã¼ã¸ãé »çºããããã«ãªã£ã¦ãæåã¯æ¥ç¶ã§ãã¦ãã®ã«ãã³ãä¸ã«æ¥ç¶ã«å¤±æãããã¨ããã£ãã
ã¹ã³ã¢ãç«ã¡ä¸ããåã ã£ãã®ã§ã¨ã«ããææªã
ããã¯çµå±åå ãããããããªãã¦(åå ããããã®ã¯å¾è¿°)ãè¦ã¯åæ¥ç¶ããããã«ããã°ããã¨ãããã¨ã§ãDBIã Scope::Container::DBI
Scope::Container::DBIを書いた - blog.nomadscafe.jp ã«å·®ãæ¿ãã¦ãdbhãªãã¸ã§ã¯ãã®ãã£ãã·ã¥ãããã¦ãScope::Container::DBI->connect
ãæ¯åå¼ã¶ããã«ããã
以åã«ãããããã¨ãæ¸ãã¦ãã
å°ãªãã¨ããPerlã®DBIã®å ´åãDBI->connectã®è¿ãå¤ã§ãããã¼ã¿ãã¼ã¹ãã³ãã©ãªãã¸ã§ã¯ãããã£ãã·ã¥ãã¦ãããã¾ããããªãã ãã£ãã·ã¥ãã¦ããéã«ããã¼ã¿ãã¼ã¹ã¨ã®æ¥ç¶ãåããã¨ãåæ¥ç¶ããã«ã¨ã©ã¼ãåãã ãã¼ã¿ãã¼ã¹æ¥ç¶ã¾ããã®ãªãã¸ã§ã¯ãããã£ãã·ã¥ããã¨ãã¯ããã£ãã·ã¥ãã¦æå³ã©ããã«åä½ããã®ãããã調æ»ããã»ããããã
Webã·ã¹ãã ã«ããããã¼ã¿ãã¼ã¹æ¥ç¶ã¢ã¼ããã¯ãã£æ¦è« - ããããããã°
ãã©ãã«2: ALTER TABLEã30åãã£ã¦ãçµãããªã
entriesãã¼ãã«ã«å¯¾ããã¤ã³ããã¯ã¹ã®ä½æã2000ç§ä»¥ä¸ããã£ã¦ãã¦ãã¡ããã¡ãã ã£ããã©ãã¿ã¦ããã£ã¹ã¯I/Oã使ããã£ã¦ããã®ã§ã©ããããããªãã£ãã
éå»ã«äººæ°åã®ã¤ã³ã¹ã¿ã³ã¹ããã¦ãããã¦ãããã¼ã ããã£ãããã§ãããã«ãªãã£ã¦ã¡ã¤ã³ã®ã¤ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ãããããã£ã¹ã¯ãSSDã«å¤æ´ããã¤ã³ã¹ã¿ã³ã¹ããã¦ã¦ãã¡ãã§ALTERãåãã¦ãã¡ã¤ã³ã®ã¤ã³ã¹ã¿ã³ã¹ã«/var/lib/mysql
ãã¨ncã§ã¨ã°ãã¨ãããã¨ããã£ãï¼SSDã®ã¤ã³ã¹ã¿ã³ã¹ã¯ãã¡ãããã³ãã«ã¯ããã¦ããªãï¼ãä»ã§ã¯SSDãå½ããåã«ãªã£ã¦ããã©ãæ¹ãã¦SSDã®éããå®æããããããæåã¯ã¹ãããã·ã§ããã§ã¯ãªãã¦VMã¤ã³ã¹ã¿ã³ã¹ã®è¤è£½æ©è½ã¿ãããªã®ã使ã£ããããã¯ä¾¿å©ã¨ãè¨ã£ã¦ãããæ°æéåã®ç¶æ
ã®ã¤ã³ã¹ã¿ã³ã¹ã®è¤è£½ãä½ããããã¨ã«æ°ã¥ãã¦ãããã¦ã¦ã¹ãããã·ã§ããã«ããè¤è£½ã«åãæ¿ããã
ãã®ä»ãæä½ãæã®ããæå°éã®/etc/my.cnf
ã¯èªã¾ããã«ãdebããã±ã¼ã¸ä»å±ã® /etc/mysql/my.cnf
ãå®ã¯èªã¾ãã¦ããã¨ããç½ ããã£ãã
ãããé©å½ã«/etc/mysql/my.cnf
ã/etc/my.cnf
ã«å·®ãæ¿ããã¨base dir ã data dirãããããã¶ãééã£ã¦ãã¦mysqldãèµ·åããªããªããäºåã«éå»åã§ããããå£ããã®ã§ããããã¨ã¯ãªãã£ãã
ç«ã¡ä¸ããã¯ããã»ã©ã¹ã³ã¢ã伸ã³ãªãã£ããã¨ããéä¸ã§ãã©ãã«ããã£ã¦ããã©ãã«è§£æä¸ã«è¤æ°ã®æ¹åãããã¦ãããããã®ã§ãã¯ã£ãããã®å¤æ´ãã¹ã³ã¢ã«å¹ããã¿ãããªã®ãããããã«é²ãã§ãã£ãï¼failãã¤ã¤ããã°ã®è§£æã¯ãã£ã¦ãï¼ã ã¨ã¯ãããåºæ¬ã¯ã¢ã¯ã»ã¹ãã°è§£æã¨pt-query-digestãä¸å¯§ã«ã¾ããã¦å®è¡æéã®å²åã大ããé ã«ã¯ã¨ãªãæ¹åãã¦ãããã¨ãæèãã¦ããã ãã®ä»ã¯å¤æ´ã®æéãå°ãªããã®ããããããã§ãããã«ããã¯ç¡è¦ã§è¦å½éãã®ã¨ããããã¥ã¼ãã³ã°ãå§ããã¨ãããã¨ã¯ãã¶ããªãã£ãã¨æãã æã¤æããªããªã£ã¦ããçµç¤ã¯ã¨ãããä¸ç¤ã¾ã§1ã¤ãã¤ããã«ããã¯ãã¤ã¶ãã¦ãã£ãæããã£ãã
æçµçã«ã¯ãNginx - Perl - MySQLã®æ®éã®æ§æã§ã»ãã·ã§ã³ã ãmemcachedã«ããããusersã®ãããªã¡ã¢ãªå
ã«ãã£ãã·ã¥ã§ããã¨ããã¯ã¢ããªã±ã¼ã·ã§ã³èµ·åæã«MySQLããå¼ãã¦è¦ªã®ã¢ããªã±ã¼ã·ã§ã³ããã»ã¹ã®ã¡ã¢ãªã«ãã£ãã·ã¥ããããã¨ã¯æ®éã«åãã¼ãã«ã«ã¤ã³ããã¯ã¹ãå¼µããN+1ã¯ã¨ãªããªããã¦ããã¨ããæãã
親ããã»ã¹ã«ãã£ãã·ã¥ããã®ã¯ãæå /initialize
ã§ãã£ã¦ããã©ã/initialize
ã§ãã£ãã·ã¥ããã¨preforkãããåããã»ã¹ã®ãã¡ã®1ã¤ã ãããã«ãããã£ãã·ã¥ãããªãã¦ç¢ºççã«ã¨ã©ã¼ã«ãªãã®ã§è¦ªããã»ã¹ã§ãã¼ããããã¨ã«ããã
æ¸ãã¦ãéä¸ã«æãå½ãã£ããã©ã親ããã»ã¹ã§MySQLã«æ¥ç¶ãã¤ã¤DBIã®attributeã§AutoInactiveDestroy
ãæå®ããã¦ããã®ã§åããã»ã¹ã§dbhãªãã¸ã§ã¯ããåæã«ç ´æ£ããã¦ãdbhãªãã¸ã§ã¯ãã使ãã¾ããã¦ãå ´åãã¾ãåããªãããï¼ã¨æã£ãã 第30回 データベースプログラミング入門―汎用インタフェースDBIと,O/RマッパTengの使い方(2):Perl Hackers Hub|gihyo.jp … 技術評論社
ãããã«ãã¦ã親ããã»ã¹ã®ã½ã±ãããã£ã¹ã¯ãªãã¿ãforkã§å¼ãç¶ãã§ãã¨ãããåé¡ã«ãªã£ã¦ãããã
ãã¨ã§ã¿ã¦ã¿ãã
ãªãã¸ããªã¯ãã¡ããhttps://github.com/yuuki1/isucon5-qualifier
ã¡ãªã¿ã«Mackerelã®å¤å½¢ç£è¦ã§ããããã¼ã¸ãç£è¦ããããã¢ããªã±ã¼ã·ã§ã³ãåæ¢ãã¦ãã¨ãã«èª¤ã£ã¦ãã³ãããªãããã«ã¨ããããã使ãã¿ã¡ãããããã
åè
ISUCONäºé¸ã®æºåãããã¨ãã«ç¹ã«ä¸è¨ã®ã¨ã³ããªãåèã«ããã¦ããã ããã¨ãå¤ãã£ãã
- ISUCON4 予選でアプリケーションを変更せずに予選通過ラインを突破するの術 - Hateburo: kazeburo hatenablog
- ISUCONの勝ち方 YAPC::Asia Tokyo 2015
- #isucon 4に参加して予選2日目暫定1位になりました - 酒日記 はてな支店
ãã¨ãã
å»å¹´ã¯æ¬æ¦åºå ´æ ã«çµæ§ã®ãªã®ãªã§æ»ãããã ã®ã§ãå»å¹´ããåå ãã¼ã ã®å¤ãä»å¹´ã¯ããªãå³ããã®ã§ã¯ã¨æã£ã¦ãããã©ãçµãã£ã¦ã¿ãã°æå¤ã¨ä¸ä½ééã§ãã¼ã ã¡ã³ãã¼ã®åªç§ããã¿ãã¤ããããä¸æ¥ã ã£ãã ISUCONãçµæ§ã¡ã³ãã¼ã®ãã©ã³ã¹ãéè¦ã ã¨æã£ã¦ãã¦ãå ¨å¡ããç¨åº¦ãµã¼ãããããã¦ãããç¨åº¦ã³ã¼ããæ¸ãã+@ã¿ãããªã¤ã¡ã¼ã¸ã ä¾ãã°ãæ¹é決ãããããã«ããã¯è¦æ¥µãããã¯ã¤ã³ãã©æ å½ã¾ãããã¿ãããªæãã«ãªããã¡ã®ãããªç©ºæ°ããããã©ããã¼ã«ããç½®ãã¦ããã°2人ã¨ãåæã«ã¿ã¦ããããã³ã¼ãã ãã¿ã¦å±ææé©ã«èµ°ããã¨ãå°ãªãã åãä¼ç¤¾ã«ããã¨ãã®åªç§ããã ãã ãå½ããåã«ã¿ãã¦ãããã©ãISUCONã®ãããªã¤ãã³ãã§å¯¾å¤çã«è©ä¾¡ããããã¨ã«ãªã£ã¦ããã®åªç§ãã¯æ®éãããªãã£ããã ãªã¨ãããã¨ãæ¹ãã¦ãããã
åºæ¬ã¯ã¢ããªã±ã¼ã·ã§ã³ãã¸ãã¯ã®æ¹åã«2人ã¨ãéä¸ãã¦ããããã¨æãã®ã§ãã¹ã³ã¢ã«ã¯ãããã¦è²¢ç®ãã¦ãªããã©ã¨ããããå½¹ç®ã¯æãããæãããã ã¾ãã¾ããã©ãã«å¤ãã£ãããã«æå¤ã¨ãªãã¨ããªã£ãã®ã¯äºåæºåãã¦ããã¹ããã¨ãããã¨æ©ãã«çµãããã¦æéçä½è£ã稼ããããããªã¨æãã
ã¤ã³ãã©ã¨ã³ã¸ãã¢ã«ã¨ã£ã¦ã¯è¤æ°ãµã¼ã使ããæ¬æ¦ãæ¬å½ã®åã試ãããã¨æããè¤æ°ãµã¼ã使ãISUCON楽ãã¿ãããã
ISUCONéå¶ã®çæ§ããã°ãããã¤ãã³ãããããã¨ããããã¾ããã ããããã®ããåé¡ã§æ¥½ããã£ããä»åã®åé¡ã5å°æ§æã§è§£ããããã¦ã¿ãã¨ãã®ãããã