Simon WillisonãNode.jsã¯è¶ ã¨ããµã¤ãã£ã³ã°ã
Simon Willisonã«ãã2009.11.23ã®ããã°ã¨ã³ããª
Node.js is genuinely exciting
Node.jsã®è©³ããã¬ãã¥ã¼ãéãçç±ã¯V8ã ããããªããçã åå¼·ã«ãªãã
以ä¸æãèªãã å 容
Evented I/Oã¨ã¯ï¼
- ã¤ãã³ãããªãã³ãªãµã¼ãã¼ã¯ãå¾æ¥ã®ã¹ã¬ããï¼ãããã¯ã¡ã«ããºã ã¸ã®ãªã«ã¿ããã£ã
- ã¹ã¬ããï¼ãããã¯ã¡ã«ããºã ã¯ãµã¼ãã¼ãµã¤ãããã°ã©ãã³ã°ã§ä¸»æµ
- ããããï¼ããããWebãã¬ã¼ã ã¯ã¼ã¯ã®åã
- å©ç¨ã§ãããµã¼ãã¼ã®ã¹ã¬ããã»ããã»ã¹ããã®å½ä»¤ã§ãå°æ°ã®ãªã¯ã¨ã¹ããåæã«ãã°ã
- é·æéãããå¦çã¯å©ç¨ã§ããã¹ã¬ããï¼ã¤ã¨çµã³ã¤ã
- å©ç¨ã§ããã¹ã¬ããããªããªãã°ãµã¼ãã¼ã¯å¿çããªããªãã
- 大è¦æ¨¡ãªãã©ãã£ãã¯ããã°ãã¨ãã¯ãã§ããã ãæ©ãå¦çãã¦ãå²ãå½ã¦ãã¹ã¬ãããéæ¾ãã¦ãé çªå¾ ã¡ãã¦ãå¦çã¸æ¸¡ããªãã¨ãããªã
- ããããWebãã¬ã¼ã ã¯ã¼ã¯ã§å¯¾å¿ãé£ããã¨ãã
- ãµã¤ãºå¤§ãªãã¡ã¤ã«ãã¢ãããã¼ããã¦ã¢ãããã¼ããããã¡ã¤ã«ã¨è¤æ°ã®APIããå¼ã£å¼µã£ã¦ãããªã½ã¼ã¹ã¨çµã³ã¤ããï¼APIã®å¿çæéã¯äºæ¸¬ã§ããªããã®ã¨ããï¼
- comet使ã£ã¦æ¬¡ã®ã¤ãã³ããå©ç¨å¯è½ã«ãªãã¾ã§æ¥ç¶ãéãæ¾ãã«ãã
- ã¤ãã³ãããªãã³ããã°ã©ãã³ã°ã§ã¯ããããã¯ã¼ã¯ãµã¼ãã¼ãI/Oå¨ãã®å¦çããå®äºããã¾ã§å¾ æ©ãã¦ãããã¨ãå©ç¨ãã
- ã¡ã¢ãªä¸ã®ãã¼ã¿ã¸ã®å¦çã¯è¶ éããããã¡ã¤ã«ã·ã¹ãã ã¸ã®ã¢ã¯ã»ã¹ããããã¯ã¼ã¯ãã¾ãããããªå¦çã¯ãã¬ã¹ãã³ã¹ã«æéããããã
- Twisted/EventMachine/Node.jsããã£ã¦ããã¨
- ã³ã¼ã«ããã¯ã¨ãªã³ã¯ããI/Oå¨ãã®å¦çãç¹å®ãã¦ãã
- åç¬ã®ã¤ãã³ãã«ã¼ããã¿ã¹ã¯ã®ãªã¹ãã®ä¸ã§ç´ æ©ãåãæ¿ããI/Oå¦çãçºç«ããã次ã®ãªã¯ã¨ã¹ãããã°ããããã«ç§»è¡ãã
- I/Oãè¿ãã¨ãç¹å®ã®ãªã¯ã¨ã¹ãã®å®è¡ãå度ããã¯ã¢ããããã
ã¤ãã³ãããªãã³ãªãã¬ã¼ã ã¯ã¼ã¯ãæ¢ã«ãããNode.jsã®ã©ããã¨ããµã¤ãã£ã³ã°ã
- javascript
- ã³ã¼ã«ããã¯æ±ãã®ãå¾æãªè¨èª
- ã¤ãã³ãããªãã³ãªããã°ã©ãã³ã°ãå½ããåã«ãªã£ã¦ãè¨èª
- ãããã¿ã¼ã
- Twisted(Pythonï¼ãEventMachine(Ruby)ã¯å¤§å¤
- I/Oãããã¯ããã©ã¤ãã©ãªã¨ä¸ç·ã«ä½¿ããªãã¨ãããªã
- 使ããï¼ä½¿ããªãã©ã¤ãã©ãªã«ã¤ãã¦åå¼·ããªãã¨ãããªã
- Node.jsã§ã¯ã¼ãããã¹ã¿ã¼ããã¦ãI/Oãããã¯ããAPIã¯ãã¼ãã«ãããã¨ããè¨è¨ã§ãã£ã¦ã
- Ryan Dahlã¯ãã¡ã¤ã«ã·ã¹ãã ã§ãDNSã«ãã¯ã¢ããã§ããä¾å¤ãä½ããªãæ¹éã§ãã£ã¦ã
- Twisted(Pythonï¼ãEventMachine(Ruby)ã¯å¤§å¤
- 軽é
- APIã®ããã¥ã¡ã³ã30åãããèªãã ã大ä½ã®ã¢ã¤ãã£ã¢ãæ´ããè¦æ¨¡ã
- éã
- V8使ã£ã¦ãããéã
- é«éãªI/Oã©ã¤ãã©ãªlibioï¼Cã©ã¤ãã©ãªï¼ã¨é«éã®ã¤ãã³ãã«ã¼ãã©ã¤ãã©ãªlibevï¼Cã©ã¤ãã©ãªï¼ä½¿ã£ã¦ãããéã
- libio/libevã¯Mark Lehman謹製
- ã¹ãã¼ãã«ç°å¸¸ã«ãã ããRyanã¯ããªãªã¸ãã«ã®HTTPãã¼ãµã¼ããCè¨èªã§ãã³ãã³ã¼ãã£ã³ã°ãã¦ãæ¸ãã
- Cã®httpãã¼ãµã¼ã¯Ragel/Mongrelãä½ã£ããã®ã§çµæ§éãã®ã«ããããä¸åãã®ãä½ã£ãã
- ããå§ããã
- Nodeã¯å¿ è¦ã¢ã¸ã¥ã¼ã«ãå ¨é¨ã¾ã¨ã¾ã£ã¦ããSnow Leopardä¸ã§ã«ã³ã¿ã³ã«ã³ã³ãã¤ã«ã§ãã
Node.jsãåãã
- å²æï¼git cloneããmakeãçã ï¼
Node.jsã§Hello World!
var sys = require('sys'), http = require('http'); http.createServer(function(req, res) { res.sendHeader(200, {'Content-Type': 'text/html'}); res.sendBody('<h1>Hello World</h1>'); res.finish(); }).listen(8080); sys.puts('Server running at http://127.0.0.1:8080/');
Macbookã§ãã³ããã¼ã¯åã£ãï¼è¦ Apache Benchã®ã¤ã³ã¹ãã¼ã«ï¼
ab -n 1000 -c 100 'http://127.0.0.1:8080'
- åææ¥ç¶100ã§1000åãªã¯ã¨ã¹ãåºããã¹ããã¦ãï¼ç§ã«3374ãªã¯ã¨ã¹ããã°ãã
- æ¹å¤ãã¦setTimeout使ã£ã¦ãªã¯ã¨ã¹ããï¼ç§å¾ãã¨ã«è¨å®ãã¦ããï¼ç§ã«50ãªã¯ã¨ã¹ããã°ããçµæ§åªç§
- .finish()éè¦
- ãªã¯ã¨ã¹ããããå¦çãå®äºãããã¨ãæ示çã«ã·ã°ãã«ãåºãããã©ã¦ã¶ã«æ»ãã¹ãã ã¨ä¼ãã¦ã
- .finish()ã«ãã£ã¦ãcometã©ã¤ã¯ãªlong-polling/streamingã®å®è£ ãã¨ã¦ãã«ã³ã¿ã³ã«ãªã£ã¦ã
- Node.jsã®ã³ã¢APIã¯ä½ã¬ãã«
- httpã¯ã©ã¤ã¢ã³ãï¼ãµã¼ãã¼
- DNSãã³ããªã³ã°
- éåæãã¡ã¤ã«I/O
- Node.jsã¯é«ã¬ãã«APIãæä¾ããªã
- Node.jsã§åã軽éãã¬ã¼ã ã¯ã¼ã¯ãåæã§éç£ãããã¨ããæµããçãã
- Node.jsã§åãã¦ããã¦ã§ãã¢ããªã®ãªã¹ãè¦ã
- 大éçºçãããã¬ã¼ã ã¯ã¼ã¯ã使ã£ã¦éã¶ã®ã¯ãNode.jsã®ä½ã¬ãã«APIãåå¼·ããè¿é
- Node.jsã§åã軽éãã¬ã¼ã ã¯ã¼ã¯ãåæã§éç£ãããã¨ããæµããçãã
ä½ã£ã¦ã¿ãï¼djangode
- Node.jsã«URLæä½æ©è½ãæ¡å¼µ
- Djangoã§ä½¿ã£ã¦ãæ£è¦è¡¨ç¾ã使ã£ãURLãã³ããªã³ã°ããã¦ã
- ã¾ã ãããã¿ã¤ããNode.js触ã£ã¦ã¿ãã¢ã¤ãã£ã¢æµ®ããã ã追å ãã¦ãã
ä½ã£ã¦ã¿ãï¼nodecast
- ãã¨ã§ãã
ãã¼ã¿ãã¼ã¹ã®æä½
- nodecastèªä½ã§ã¯ã¡ãã»ã¼ã¸ã¯ã¡ã¢ãªä¸ã«é
å使ã£ã¦ä¿åã
- ãããããã¼ã¿ã®æ°¸ç¶æ§ã¯ã©ããªã£ã¦ãï¼ã¨ãªã
- ãã¼ã¿ã®æ°¸ç¶æ§ã«ã¤ãã¦ã®æã£åãæ©ã解決ã¯ãNoSQLç³»
- Node.jsã®I/Oãããã¯ããªãã¨ããè¨è¨ã¯ãé常ã®ãã¼ã¿ãã¼ã¹ã©ã¤ãã©ãªã¨ç¸æ§æªãï¼ä¸å¯è½ãããªããï¼
- éä¿¡ãããã³ã«ã¯ã·ã³ãã«ããã
- ï¼åºæãããã³ã«ãããªãï¼TCP/IPä¸ã«å®ç¾ãããã·ã³ãã«ãªãããã³ã«ä½¿ãããã¼ã¿ãã¼ã¹
- ãã£ã¨ããã®ã¯ããããã³ã«ãHTTP使ããã¼ã¿ãã¼ã¹
- NoSQLç³»ã®CouchDBã¨redis使ã£ã¦ã¿ãããåä½ã¯ã¨ã¦ããã
- CouchDBç¨ã®ã¯ã©ã¤ã¢ã³ãã§ä½¿ã£ãã®ã¯node-couch
- redisç¨ã¯ã©ã¤ã¢ã³ãã§ä½¿ã£ãã®ã¯ãredis-node-client
- èªåãä½ã£ãnodecastã§ã¯redisã«ã¡ãã»ã¼ã¸ãã¥ã¼ãä¿åããã¦ãã
- ãã¼ã¿ãã¼ã¹ã¸ä¿åããåä½æ¸ããã³ã¼ãã®é¨åã¯ãã³ã¼ã«ããã¯ä½¿ã£ããI/Oãããã¯ããªããã¼ã¿ãã¼ã¹ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ããè¦æ¬ã«ãªã£ã¦ãã¨æã
- MySQLãPostgreSQLãã¡ããã¨ä½¿ãã
- PostgreSQLã¯Ryan謹製ã®Node.js製ã¯ã©ã¤ã¢ã³ããã
- MySQLã¯å°ãé¢å
Mixed Environments
- Node.jsã«éçºãå®å ¨ç§»è¡ã¯ã¾ã ããªããã©
- å¾æ¥ã®ãµã¼ãã¼ãµã¤ãããã°ã©ãã³ã°ã¨Node.jsãã¼ã¹ã®éçºã®å
±åã¯ã§ãã
- Node.jsç¨ã«ãµããã¡ã¤ã³åãã¨ã
- ãããã·ãµã¼ãã¼ã®å¾ãã§å¾æ¥ã®ãµã¼ãã¼ã¨Node.jsãµã¼ãã¼ãåãã