5. Multi-threaded server - Threads are spawned for every connection
User1 i/o request
T1
DB
User2 i/o request T2
Blocking
I/O
User3
Refreshes 2 times
T3 T4 T5
T6 T7 T8 FS
User4
refreshes 3 times
T9
Multi threaded
server
T Thread
Because every I/o is blocking, server
spawns a thread per connection* to support
multiple requests
5
6. Non-blocking & Evented I/O (Node.js server)
JS C/C++
T1
User1 i/o request V8 DB
T1 Libio
T1 POSIX
V8
Event loop V8 Async
User2 i/o request (Libev) Threads
T1 delegate i/o to Non-blocking
t2 I/O
V8 libeio t1
User3
Refreshes 2 times Single t4
thread t3
serves T1 t6
all users V8 t5
User4
refreshes 3 times T1 t7 FS
V8
i/o result returned
T1 T1
2 EL after x time
V8 T1 V8
T1 JS Thread running V8
V8 your code (Single threaded)
Node.js
t1 POSIX threads doing
t2
async I/O (multi-threaded)
t3 Everything except your (JS) code is runs in parallel (by libio)
6
7. Multi-‐‑‒threaded blocking server (Apache)
VS Event-‐‑‒driven, non-‐‑‒blocking server (Nginx) performance
Reqs/sec v/s concurrent connections
At ~4000 concurrent connections,
- Nginx can serve ~9000 reqs/sec
- Apache can serve ~3000 reqs/sec
Ref: http://blog.webfaction.com/a-little-holiday-present
7
10. NPMによるNode.jsモジュール管理理のサポート
cloudfoundry.jsonファイルに、以下の内容のように、ignoreNodeModulesのパラメータに “true”
を設定する。これがないとnode_̲modulesディレクトリ以下のモジュールをアップロードすること
になる。bcrypt,fibers,nowjsなどのNativeライブラリを使った場合、実⾏行行環境でコンパイルの
必要があるためモジュールをアップロードできない。このcloudfoundry.jsonの設定は必須
cloudfoundry.jsonファイル
{ "ignoreNodeModules" : true }
vmc pushコマンドによるアプリケーションの展開
vmc push –runtime=node06(Node.jsバージョン指定が可能)
$vmc push –runtime=node06
Would you like to deploy from the current directory? [Yn]: Y
Application Name: ike-‐‑‒node
Detected a Node.js Application, is this correct? [Yn]: Y
Application Deployed URL [ike-‐‑‒node.cloudfoundry.com]:
………………
Creating Application: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (15K): OK
Push Status: OK
Staging Application 'ike-‐‑‒node': OK
Starting Application 'ike-‐‑‒node': OK
10