Instagram ã®ã¹ã±ã¼ã«æ£æ»æ³
Instagram ãã©ãã«è²·åãããã¨ãã¯ä»ã®ãã¥ã¼ã¹ãµã¤ãã«ãä»»ããã¦、Django ã¢ããªã±ã¼ã·ã§ã³ãæ£æ»æ³ã§ã¹ã±ã¼ã«ã㦠"æå" ãã¦ãã®ãã¨ã¦ãèå³æ·±ãã§ã。ç¾æç¹ã§ Instagram Engineering ã§ç´¹ä»ããã¦ãããã¨ã¨ TechCrunch ã«ãæ²è¼ãããã¹ã©ã¤ãããå人çãªã¡ã¢ã¨ãã¦ã¾ã¨ãã¦ã¿ã¾ãã。
Instagram ã®å²å¦ã¯
- ã·ã³ãã«ã§ãããã¨
- ãªãã¬ã¼ã·ã§ã³è² è·ãæå°åãããã¨
- ãã¹ã¦è£ å
ã¨ã®ãã¨。
Instagram ã¯ä»¥ä¸ã® OSS, ãµã¼ãã¹ã§æ§ç¯ããã¦ããããã§ã。
>>> OS / ãã¹ãã£ã³ã°
Ubuntu Linux 11.04 ã Amazon EC2 ã«ãã¹ãã£ã³ã°。以åã®ãã¼ã¸ã§ã³ã¯é«ãã©ãã£ãã¯ã«ãªãã¨åºã¾ãåé¡ããã£ãããã§ã。éç¨ã¯ 3 人。EC2 ã«ãã¹ãã£ã³ã°ãã¦ããçç±ã¯、調æ»çµæã«ãããã®ã§ã¯ãªã、"ã¾ã é²åéä¸ã ãã" ã ããã§ã。
ãã¼ãã¦ã§ã¢ã®é¸å®、å°å ¥、ã»ããã¢ããã®æéãçãã¾ãã、ããã±ã¼ã¸ç®¡ççã®éç¨ã軽ããã§ãã。
>>> ãã¼ããã©ã³ãµ
Amazon ELB ãå©ç¨。ãã¨ãã¨ã¯ DNS ã©ã¦ã³ãããã³ + nginx ã®ãã¼ããã©ã³ãµã§ãã©ã³ã·ã³ã°ãã¦ããããã§ãã、DNS ã®æ´æ°ãé ãã®ã§æ¢ããã¨ã®ãã¨。nginx ã®è² è·ã軽æ¸ããããã« SSL ã ELB ã¾ã§ã§、ãã¨ã¯ HTTP。ELB ã¯ã»ãã¨ç´ æµãªãµã¼ãã¹ã ã¨æãã¾ã。DNS ã Amazon Route 53 ãå©ç¨。GUI ã§ã®ç®¡çãç´ æµã¨ã®ãã¨ã§ã。
>>> ã¢ããªã±ã¼ã·ã§ã³ãµã¼ã
Django ã¢ããªã±ã¼ã·ã§ã³ã EC2 ã® High-CPU Extra-Large ã¤ã³ã¹ã¿ã³ã¹ã§å®è¡。2012 å¹´éå§ãããã§ã¯ç´ 25 ã¤ã³ã¹ã¿ã³ã¹ã¨æ¸ããã¦ãã¾ã。Android ã¢ããªãå ¬éã㦠10 æ¥ã§ 1000 ä¸ã¦ã¼ã¶ (20 æé㧠100 ä¸ã¦ã¼ã¶) ãç²å¾ãããããªã®ã§、ä»ã¯ãã£ã¨å¤ãã§ãããã。ãããããµã¼ãã¹ã®æ¡å¤§ã«æè»ã«å¯¾å¿ã§ããã®ã EC2 ãå«ãã¯ã©ã¦ãã®é åã ã¨æãã¾ã。High-CPU ã«ãã¦ããçç±ã¯ãããã PIL ãå¤ç¨ããããã§ãããã。WSGI ãµã¼ã㯠gunicorn ã§ããã。çç±ã¯ Apache 㨠mod_wsgi ãã CPU è² è·ã軽ãã£ãããã¨ã®ãã¨。ãããã¤ã¯ Fabric ã§ãã£ã¦ããããã§ã。Fabric ã®ä½¿ãæ¹ã¯ Ian å çã®ããã°ãåèã«ãªãã¾ã。
ãã¨、ããã«ããã¯ã«ãªã£ã¦ãããã»ã¹ãç£è¦ããããã« dogslow ã¨ãã bitbucket 製㮠Django ããã«ã¦ã§ã¢ãå©ç¨ãã¦ããããã§ã。ããããã° bitbucket ã Django ã使ãã¡ã¬ãµã¼ãã¹ã§ãã。
åè: High-CPU Extra-Large ã¤ã³ã¹ã¿ã³ã¹
- 7 GB ã¡ã¢ãª
- 20 ECU(2.5 ECU × 8ä»®æ³ã³ã¢)
- 1690 GB ã¤ã³ã¹ã¿ã³ã¹ã¹ãã¬ã¼ã¸
- 64ããã ãã©ãããã©ã¼ã
- I/O æ§è½: é«é
>>> ãã¼ã¿ã¹ãã¢
ã»ã¨ãã©ã®ãã¼ã¿ (ã¦ã¼ã¶、åçã®ã¡ã¿ãã¼ã¿、ã¿ã°ç) ã PostgreSQL ã«ä¿å。Django ããã¥ã¡ã³ãã« "PostgreSQL is recommended, because we're PostgreSQL fans" ã£ã¦æ¸ãã¦ããã®ãæãåºãã¾ãã。PostgreSQL 㯠Cluster Compute Quadruple Extra Large ã¤ã³ã¹ã¿ã³ã¹ã§å®è¡。10 ã®ã¬ã§ãã!åãã 2012 å¹´éå§ãããã§ã¯ç´ 12 ã¤ã³ã¹ã¿ã³ã¹ã¨æ¸ããã¦ãã¾ã。ã¾ãããã¯ã¢ããç¨ã¨ãã¦ç°ãªãã¾ã¼ã³ã« 12 åã®ã¬ããªã«ãç½®ãã¦ããããã§ã。EBS ã®ãã£ã¹ã¯ã·ã¼ã¯ãé ãã®ã§、ãã¹ã¦ã®ã¯ã¼ãã³ã°ã»ãããã¡ã¢ãªã«ä¿åãã¦ããããã§ãPostgreSQL ã®ã¬ããªã«ã¯ã¹ããªã¼ãã³ã°ã¬ããªã±ã¼ã·ã§ã³ãå©ç¨。ã¬ããªã±ã¼ã·ã§ã³ã®ç®¡ç㯠repmgr ãå©ç¨。ããã¯ã¢ãã㯠EBS ã®ã¹ãããã·ã§ããæ©è½ãå©ç¨。ã³ãã¯ã·ã§ã³ãã¼ã«ã« PgBouncer ãå©ç¨ (ãããããã©ã¼ãã³ã¹åä¸ã«ããªãå¹ããããã)。
æå㯠Django ã®ã«ã¼ã¿æ©è½ã§åç´åå² (ãã¼ãã¦ã§ã¢è² è·ã®åæ£)。次㫠PostgreSQL ã®ã·ã£ã¼ãã£ã³ã° (åè) ã§æ°´å¹³åå² (ãã¼ã¿é åã®åæ£)。
åè: Cluster Compute Quadruple Extra Large ã¤ã³ã¹ã¿ã³ã¹
- 23 GB ã¡ã¢ãª
- 33.5 EC2 Compute Unit(2 x Intel Xeon X5570、quad-core「Nehalem」ã¢ã¼ããã¯ãã£)
- 1690 GB ã¤ã³ã¹ã¿ã³ã¹ã¹ãã¬ã¼ã¸
- 64ããã ãã©ãããã©ã¼ã
- I/O æ§è½: è¶ é«é(10 ã®ã¬ãããã¤ã¼ãµããã)
次ã«ã¡ã¤ã³ãã£ã¼ã、ã¢ã¯ãã£ããã£ã¼ãã£ã¼ã、ã»ãã·ã§ã³ãã¼ã¿ (django.contrib.sessions.backends) 㯠redis ã«ä¿å。redis 㯠High-Memory Quadruple Extra Large ã¤ã³ã¹ã¿ã³ã¹ãæ°å°。ãããããã¯ã¢ãã㯠EBS ã®ã¹ãããã·ã§ãã。redis ã®ã¬ããªã«ã«ãã、ç°¡åã«ãªã³ã©ã¤ã³ãã§ã¼ã«ãªã¼ããã。redis ãé¸æããçç±ã¯、"ã¤ã³ãµã¼ããé«é、ãµãã»ããã®ä½æãé«é" ã ã£ãããã¨ã®ãã¨。
åè: High-Memory Quadruple Extra Large ã¤ã³ã¹ã¿ã³ã¹
- 68.4 GB ã¡ã¢ãª
- 20 ECU(2.5 ECU × 8ä»®æ³ã³ã¢)
- 1690 GB ã¤ã³ã¹ã¿ã³ã¹ã¹ãã¬ã¼ã¸
- 64ããã ãã©ãããã©ã¼ã
- I/O æ§è½: é«é
ãã¡ã¤ã«ã·ã¹ãã 㯠XFS。
ãã¡ã¤ã«ãã£ãã·ã¥ã管çããããã« v
ç§ã¯ KVS ã®é¸å®ã®é、ãããåèã«ãã¦ãã¾ã。
>>> ã¿ã¹ã¯ãã¥ã¼ã¨ PUSH éç¥
åçã facebook ã twitter çã¸ã®é£æº、æ°è¦åçãæ°è¦ã¦ã¼ã¶ã®éç¥çã®ã¿ã¹ã¯ã¯ gearman ã§å¦ç。worker æ°ã¯ 200 ç¨åº¦。
PUSH éç¥ã¯ pyapns (twisted powered) ã§ãã£ã¦ãã。
å ¨ä½ã¨ãã¦、éç¨ã®æéã軽ãã、ãããã¯ã¼ã¯è»½ããµã¼ãã¹ãæä¾ã§ããããã«å·¥å¤«ããã¦ãã¾ãã。ç£è¦ã¯ munin ãå©ç¨ãã¦ããããã§ã。ãã©ã°ã¤ã³ã python-munin ã§ä½æãã¦ããããã§ã。ç£è¦ã¾ã§ pythonic ã§ãã。python-munin ã«ã¯ Instagram ãããå©ç¨ãã¦ããã¤ã³ãã©ã®ããã®ç´ æµãªãã©ã°ã¤ã³ãå¤ãç¨æããã¦ãã¾ã。ãã 1 㤠memcached ãå©ç¨ãã¦ããæè¡ã® 1 ã¤ã¨ãã¦è¨è¼ããã¦ãã¾ããã、ããã«ã¤ãã¦ã¯æ®å¿µãªãã詳ããã¯æ¸ãã¦ããã¾ããã§ãã。Amazon ElastiCache ã§ããã w
ã¾ã、ã¹ã©ã¤ãã«ã¯é¢ç½ã tips ãç´¹ä»ããã¦ãã¾ãã。
- favicon.ico ã¯å¿ ãä½ããã¨: 404 error ãé²ã。æåã®ã¹ã±ã¼ã«ã¯ãã。
- ä»ã®ãµã¤ãã§ä»¥ä¸ã« favicon ã軽ãããããç±ã解説ãã¦ãã¾ãã
- ãµã¼ãã¹ãã¤ã³ãã©ãã¹ãã¼ããè¨éã«
- éçºã¹ã¿ã¤ã«
-
- 大è¦æ¨¡ãªã¦ããããã¹ãã¨æ©è½ãã¹ã
- DRY
- ã·ã°ãã«ã«ããç¥çµå
- 大é¨åã Python ã§å®çµã、å¿ è¦ã«å¿ã C ãå©ç¨
- ç¥èãå ±æããããã®é »ç¹ãªã³ã¼ãã¬ãã¥ã¼ã¨ãã«ãªã¯ã¨ã¹ã
- 大è¦æ¨¡ãªç£è¦
åè:
Helpfulinfo, do your best.
è¿ä¿¡åé¤engineer blogs