ããåå¹´ããããã«Dockerã§microservicesãªãµã¼ãã¹ãéç¨ãã¦ããã§ãããã¤ãã¤ãããã©ã¼ãã³ã¹ãåºãåãã¦ããªããªã¨ããé¢ãããã¾ãã¦ãä»åDockerãã¹ãã®TCPã«ã¼ãã«ãã©ã¡ã¼ã¿ãææ¬çã«è¦ç´ãã¾ããã
ããããåçã«çç¶ãæ¹åãã¦ãã¤ã³ã¹ã¿ã³ã¹æ°ãåæ¸ã§ããä¸ã«å®å®ãã¦ã¡ã·ã¦ãç¶æ ã«ãªã£ãã®ã§ç´¹ä»ãã¾ããå®éå¹æããã£ãã®ã§ãã¥ã¼ãã³ã°ãã¤ã³ãã¨ãã¦ã¯ããç¨åº¦æ£è§£ã§ãã£ãã¨èãã¦ãã¾ããããã¡ããæ±ã£ã¦ãã¢ããªã±ã¼ã·ã§ã³ã®ç¹æ§ã«ãããã¯ããªã®ã§ä¸ã¤ã®ã±ã¼ã¹ã¹ã¿ãã£ã§ãããã¨ããäºæ¿é ããã°ã¨ã
åæ
ã¾ãã¯ä»åã®ã話ã®åæãããããªç°å¢ã§ãã
- EC2 c3.xlarge
- ãã¹ãã¯Ubuntuï¼EC2 Optimized AMIã¯æªä½¿ç¨ï¼
- Docker 1.11.2
- MySQLï¼HAProxyçµç±ï¼ãRedisã¸ã®ãã¼ã¿ã¹ãã¢ã®éä¿¡ãåmicroservicesã¸ã®éä¿¡å¤æ°
- fluentdã§elasticsearchãs3ã¸ã®ãã°ã®è»¢é
- ECSã®Taskæ§æã¯**Nginx + Node + Go + fluentd + HAProxy**
- REST APIãReactã§ã®ãµã¼ããµã¤ãã¬ã³ããªã³ã°ãè¡ã
ç§ä¼ã®ã«ã¼ãã«ãã©ã¡ã¼ã¿
ä¸è¨ã§è¨ãã¨ã社å ã®ç§ä¼ã®ã«ã¼ãã«ãã©ã¡ã¼ã¿ã§ã¯è¶³ããªãã£ãã¨ãããã¨ã«å°½ãã¾ããå®ç¸¾ã®ãããã®ã§ããããããªãã«é³è åãã¦ãã¦ãããä»åã®ãããªãã«Dockeræ§æã§ååãªããã©ã¼ãã³ã¹ãåºãã«ã¯å°ã足ããªãã£ãã¨ãããã¨ã§ããç§ä¼ã®ã¿ã¬ãã¾ã£ãããã¡ã¨ããããã¯ããã¡ãã£ã¨é«ãã¬ãã«ã®è©±ã§ããã
å ·ä½çãªçç¶ã¯ä»¥ä¸ã®ãããªæãã
ã¹ãã¤ã¯ã«ã¡ãã£ã¨å¼±ãã£ã
ã¹ãã¼ããã©ã³ã«ALLããã·ã¥ã¿ãããªãã¨ãããã¨ãä¸æ°ã«ã¦ã¼ã¶ã¼ããã£ã¦ããããã¹ãã¼ãã¦ã³ãã¨ã©ã¼çãä¸æãã¦ãããELBã¯Prewarmingãã¦ãã¦ååãªãªã½ã¼ã¹ããã£ã¦ããããã¯ã¨ã³ãã足ããªãã¨ããç¶æ ãããã¯Pushã®æéãåºæ¬çã«ãããã®ã§ãScheduled Autoscalingã§åé¿ãã¦ããã
ãã¼ã«ã«ãã¼ããæ¯æ¸ãã
ãã¡ããã¹ã±ã¼ã«ããã¢ããªã±ã¼ã·ã§ã³å´ã§éä¿¡ãæ¸ãããã¥ã¼ãã³ã°ã§åé¿ãDockerãå©ç¨ããã¨å¿ ç¶çã«Immutable Infrastructureå¿åã«ãªã£ã¦ãfluentdã§çã£ç«¯ãããã°ã転éãããã¨ã«ãªãã¾ããã¾ããmicroservicesã ã¨ã©ããã¦ãå¤é¨éä¿¡ãå¢ããã¡ã«ãªãã¾ããã¾ããã©ããã«ããã«ããã¯ããã£ã¦å ´åã«TIME_WAITãå¢ããããã«ãªã£ãå ´åãéä¿¡ã®å¤ãã¢ããªã±ã¼ã·ã§ã³ã§ã¯è´å½å·ãè² ãããããªãã¾ãã
Dockerãã¹ãã§TCPã«ã¼ãã«ãã©ã¡ã¼ã¿ãå¤æ´ãã
ã¨ããããä»åå¤æ´ãããã®ã¯ãã¡ãã
net.core.somaxconn
TCPã½ã±ããã®æ¥ç¶è¦æ±ãã¥ã¼ã®ãã£ãã·ãã£ããã¡ãã¯4096 -> 65535ã«ãnet.core.somaxconnã®å¼ãä¸ãã¯ISUCONã§ãå¹æçãªãã¥ã¼ãã³ã°ãã¤ã³ãã¨ãã¦ç¥ããã¦ãã¾ããã
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog
ä¸åº¦ã«åãå ¥ãå¯è½ãªTCPã»ãã·ã§ã³æ°ã®å¤ãnet.core.somaxconnã¨åãã«è¨å®ãããã¯EC2ã ã¨ããã©ã«ãã128ã¨å°ãªãã®ã§æ½¤æ²¢ã«è¨å®ããæ¹ãè¯ãã¨æãããã
net.ipv4.tcp_max_syn_backlog = 65535
net.core.netdev_max_backlog
ãã¥ã¼ã«ç¹ãããã±ããæ大æ°ããã¡ãã¯2048 -> 16384ã«ãnet.core.somaxconnãnet.ipv4.tcp_max_syn_backlogãnet.core.netdev_max_backlogãæã£ã¦å¼ãä¸ãããã¨ã§ã¹ãã¤ã¯ã¸ã®èæ§ãå¢ããã¨è¦ã¦ãã¾ãã
net.core.netdev_max_backlog = 16384
net.ipv4.ip_local_port_range
ãã®è¨å®ã®ããã©ã«ãã¯32768 61000ã§ãããã¨ãã§ã¡ã©ã«ãã¼ããç®ä¸æ¯å©ç¨ã§ããããã«éçã¾ã§åºãã¦ãã¾ããããã¯ãã¼ã«ã«ãã¼ãæ¯æ¸å¯¾çã®ä¸ã¤ã§ããã
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse
ããã©ã«ãOFFã ããONã«ããã¨ã³ãã¯ã·ã§ã³ãåå©ç¨ããããTIME_WAITãæ¸ããå¹æãããã¨æãããããè¦ãæãããã¾ã§å¤åã¯ç¡ãã£ãã
net.ipv4.tcp_tw_reuse = 1
ã¨ãã£ãæãã§ãã¥ã¼ãã³ã°ããã¨ãããåçã«æ¹åãã¾ããã
ã³ã³ããå´ã§sysctlãè¨å®ããæ¯éã«ã¤ãã¦
åºæ¬çã«Dockerã¯ãã¹ãã®ã«ã¼ãã«ãªã½ã¼ã¹ãã³ã³ããå´ã§å ±æãã¾ãããã®ãããã¹ãã§ç®ä¸æ¯ãªã½ã¼ã¹ãéæ¾ããã°ããã®ã¶ãã®ãªã½ã¼ã¹ãä¸æãã·ã§ã¢ãã¦ãããã¯ãã§ãã
ã³ã³ããã®ã«ã¼ãã«ãã©ã¡ã¼ã¿ãä¸ããã¨ã³ããªãã¡ããã¡ããæ£è¦ããã¦ãã¾ããããã¹ãã®ãªã½ã¼ã¹ãååã«éæ¾ããªãã¨ã³ã³ããå´ã§ãã©ã¡ã¼ã¿ãä¸ãã¦ãæ©æµã¯å¾ãããªãã®ã§ã¯ãªãã§ãããããä»åæåã«æ¤è¨¼ããã¨ãã«ã³ã³ããå´ã®ãã©ã¡ã¼ã¿ãprivilegedãvolume mountãããªã©ãã¦å¼·å¼ã«ãããã®ã試ãã¦ã¿ã¾ãããå¹æã¯è¦ããã¾ããã§ããã
ã¾ããDocker1.12ç³»ããdocker runæã«–sysctlã§ã«ã¼ãã«ãã©ã¡ã¼ã¿ã渡ããããã«ãªãã¾ãããããããããã®æ義ã¯ãã£ããä½ãªã®ãã¨ãã話ã«ãªãããã§ãããã©ã¡ããã¨ããã¨ååãªã«ã¼ãã«ãªã½ã¼ã¹ã確ä¿ã§ãã¦ããDockerãã¹ãä¸ã§ç¨¼åããåã³ã³ããã®ãªã½ã¼ã¹ãé©åã«å¶éããç¨éãªã®ã§ã¯ãªããã¨å人çã«ã¯è¦ã¦ãã¾ãããªã®ã§ã³ã³ããå ã§ã¬ããã¨ä¸ããã¨ãã使ãæ¹ã¯ã¡ãã£ã¨éãã®ããªã¨ã
ä»åã®å¤æ´ã¯ãã¹ãã ãã«è¡ããã³ã³ããå ã§ã¯ä½ãæ½ãã¦ãã¾ãããæºè¶³ã®ããææãå¾ããã¾ããã
ã¾ã¨ã
ã³ã³ããåã§ã¢ããªã®ä½ãæ¹ãã¬ã©ãã¨å¤ãã£ãã®ã§ãã«ã¼ãã«ãã©ã¡ã¼ã¿ã®è¨å®ãä»ä¸åº¦è¦ç´ãã¾ããã?