Disqus ã®ã¹ã±ã¼ã« - Django ã§æé80åPVãå¦çãã
ç§ãææ¡ãã¦ãéã Django ã§ä¸çªå¤§ããªãµã¼ãã¹ Disqus ã®ã¹ã±ã¼ã« (å·çæç¹ã§ã¯ãµã¼ãã¹ãã¦ã³ãã¦ã)。å ãã¿ã¯ Scaling Django to 8 Billion Page Views ã§ã。æé80åPV、45k req/s ã®ã»ã¼ãã¹ã¦ã®ãã©ãã£ãã¯ã Django ã§å¦çãã¦ããã¨ã®ãã¨。æ訳ã«ãªãããª。
WAF ã¯é«ééçºã¨ããã©ã¼ãã³ã¹、æ°ãã人ãå ¥ã£ã¦ããã«éçºã«åå ã§ãããã¨ã¨ã«ã¹ã¿ãã¤ãºçã®ãã¬ã¼ããªããããã¾ã。ãã®è¨äºã§ã¯ãã®ãã¬ã¼ããªãã§ããé«ééçºã¨ããã©ã¼ãã³ã¹ãã©ã両ç«ãããã、Disqus ã®ãã¦ãã¦ãç´¹ä»ããã¦ãã¾ã。
>>> ãªã WAF (Web Application Framework) ã¯é ãã®ã
æåã«æãæµ®ãã¶ã®ã¯、ã¢ããªã±ã¼ã·ã§ã³ã«å¿ è¦ã§ã¯ãªããã¤ã©ã¼ãã¬ã¼ã (django.contrib ã¨ã?) ãä¸è¦ãªã³ã¼ãããããã。ãããã Django ã®ææ³ã Python åæ§ "ããããªã¼å梱 (batteries included)" ã®ãã、Django ã¯ä»ã® Python 製 WAF ãããã¤ã©ã¼ãã¬ã¼ããå¤ãã§ã。Disqus æ°ã "å®ã¯è¨èªã WAF ã¯é ãã«ãã¾ãé¢ä¿ãªã" ãããã "ãããã¯ã¼ã¯å ã®ä»ã®ãµã¼ãã¹ã¨ã®éä¿¡" ã®ãªã¼ãã¼ããããåå ã¨ã®ãã¨。ããã¯ä¸è¬çã«ããè¨ããã¦ããã¨ã§ãã、大è¦æ¨¡ã«ãªãã°ãªãã»ã©ãã。Disqus ã®å ´å㯠PostgreSQL, redis, Cassandra , Memcached çã®ãµã¼ãã¹ã使ããã¦ããããã§ã。DB ã¸ã®ã¹ãã¼ã¯ã¨ãªã¼ããããã¯ã¼ã¯ã®ã¬ã¤ãã³ã·ã¼ã¯ Django ã®ãããªãã¤ã©ã¼ãã¬ã¼ãã«ãããªã¼ãã¼ãããã軽ãä¸åãã¾ã。ãã®å¾ ã¡æéãåé¿ããä¸çªã¡ã¸ã£ã¼ãªæ¹æ³ã¯ãã£ãã·ã¥ã®ä½¿ç¨ã§ã。Django ã§ã¯ ãã£ãã·ã¥ãã¬ã¼ã ã¯ã¼ã¯ ã使ç¨ãã¾ã。Django ã§ãã£ãã·ã¥ã使ãã®ã¯ç°¡åã§ãã、ããã¯ã¨ã³ãã« Memcached ã使ãã¨å åé«éåã§ãã¾ã。
ã¯ã。ããã¾ã§ã¯ä¸è¬çãªè©±ã§ã。ãã£ãã。
>>> 45k req/seq ãå¦çãã
ãã£ãã·ã¥ããã¨ããã§、html ãã³ãã¬ã¼ãã json ã®ã¬ã³ããªã³ã°、ç、Django ããã«ã¦ã§ã¢ã®å¦çãªã©æ¯ç§ 45000 åãä¸è¦ãªå¦çãçºçãã¾ã。45k req/seq ã®ãã¡åãã¬ã¹ãã³ã¹ããããªããã¡ãã¡å¦çãããã®ã¯ãã£ãããªã。çµæãåããã®ã¯ã¬ã¹ãã³ã¹å ¨ä½ããã£ãã·ã¥ã、ä»ã®ãã¹ã¦ã®å¦çãã¹ããããã¾ã。
Varnish ã®ä½¿ç¨
Varnish 㯠LB (HAProxy) 㨠Django ããã¯ã¨ã³ãã®éã« HTTP ã²ã¼ãã¦ã§ã¤ãã£ãã·ã¥ã¨ãã¦å°å ¥。åãã¬ã¹ãã³ã¹ãå¦çããé㯠Django ãµã¼ãã§ã¯ãªã Varnish ãè¿ã。以åã¯ãã©ãã¯ããã¯ã¹çã« Varnish ã使ã£ã¦ããã©、è²ã ã¨è©¦ããçµæ Django ãµã¼ãã¸ã®ãªã¯ã¨ã¹ã㯠45k req/seq ã®ãã¡ 15k req/seq (64% åããããã) ã«ãªã£ãã¨ã®ã㨠(ãããªã«ãããã ・・・ã¦ãçµå± 15k req/seq ã¯ãã°ããã§ãã)。
㧠Django 㨠Varnish ã«ã¤ã㦠Django Con US 2013 㨠Varnish User Group ã§çºè¡¨ãããããã§ã (ã¿ã¤ãã« 'Varnish ã«ããã¹ã±ã¼ã«' ã«å¤æ´ããã)。
è¦ç´ããã¨・・・
- é©å® 304 Not Modified ãè¿ã。ã¯ã©ã¤ã¢ã³ãã«ã¯ãã£ãã·ã¥ãã¦ããã¤ã使ã£ã¦ããã。Firebug ã¨ã Page Speed ã¨ãã§ç¢ºèªã§ãã¾ã (åè)。Django å´ã§ã¯ django.views.decorators.http.last_modified ãã³ã¬ã¼ã¿ (æ¬å®¶ããã¥ã¡ã³ãã§ã¯ django.views.decorators.http.condition ã使ãã、django.views.decorators.http.etag ã¨ã®ä½µç¨ãæ¨å¥¨ããã¦ã¾ã) ã使ã£ã¦ Last-Modified ãããã¼ãè¿ãã¾ã。
- django.views.decorators.cache.cache_control ã§åæ§ã®æ©è½ãæä¾ããã¦ããã、HTTP ãã¼ã¹ã WSGI、ããã«ã¦ã§ã¢ã®å¦ççãå®è¡ããã¦ãã¾ã。
- TTL 㯠5ç§ããã (çã) è¨å®ãã
- Varnish åæç¶æ ã§ã¯ Cookie ãããã¼ããã£ãã·ã¥ããªã。sessionid æ¯ã«ãã£ãã·ã¥ããããå¤æ´ãã。
- URL è¨è¨ã¨ã大äº
- Varnish OOM é »çºãããã¯ã©ãã·ã¥å¤ãã£ã。。。4-6 æéã«ä¸åº¦ Varnish ããªã¹ã¿ã¼ããã¦ãã。ãã㨠SSD 使ãã! (ã・・・
- DDoS 対çã¨ãã¦ã使ãã
ãã。Varnish åå¼·ãã¾ããã!(Django ãã£...
ã³ã¡ã³ã
ã³ã¡ã³ããæ稿