hakobera's blog

技術メモ。たまに雑談

さくらのクラウドで Node.js v0.6 を動かすメモ

サーバの作成とSSH公開鍵の登録は済んでいるものとする。
OS は Ubuntu 10.04 LTS 64bit

(随時追記予定)

初期設定

ログイン

普通の Ubuntu と違って root ユーザでログインする点に注意
なんとなく気持ち悪いので、一般ユーザを作成。sudo 権限を設定。SSH公開鍵の設定。

$ useradd hakobera
$ gpasswd -a hakobera admin
$ mkdir /home/hakobera/.ssh
$ cp ~/.ssh/authorized_keys /home/hakobera/.ssh/
$ chown -R hakobera:hakobera /home/hakobera/.ssh

SSH 鍵は新規に作ってもOK。
root でログインしたまま、別のコンソールで新規作成ユーザでログインできることを確認

ssh の root ログインの禁止
$ sudo vi /etc/ssh/sshd_config 

PermitRootLogin no

$ sudo service ssh restart
ファイヤーウォール設定

とりあえず 22番ポート以外を塞ぐ

ufw default DENY
ufw allow ssh
ufw enable
nvm で Node をインストール

あとは普通の Ubuntu と同じ。新規に作成したユーザでインストールする

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git-core curl build-essential libssl-dev
$ git clone https://github.com/creationix/nvm.git ~/.nvm
$ source ~/.nvm/nvm.sh
$ nvm install v0.6.7

スケールアウト周りの設定

(あとで試す。別記事で書くかも。)

  • スナップショットを使ってサーバの増やし方
  • ロードバランサを利用しての振り分け
  • Redis を使った Session 共有
  • 何台までスケールするか?(ネットワークの限界を探る)

ベンチマーク

以下の記事と同じソースを利用

Node.js の Cluster のベンチマークをとってみた - Scalaとlift のはずだった ・・・

プラン1 (仮想1Core, 2GB)

2000 req/sec くらいで、最低プランの割には結構速い気がする。
ping 打ってみたら、TTL は 20ms くらいだった。

$ ab -n 10000 -c 200 http://xxx.xxx.xxx.xxx:8000/
...
Document Path:          /
Document Length:        12 bytes

Concurrency Level:      200
Time taken for tests:   4.564 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      500050 bytes
HTML transferred:       120012 bytes
Requests per second:    2190.95 [#/sec] (mean)
Time per request:       91.285 [ms] (mean)
Time per request:       0.456 [ms] (mean, across all concurrent requests)
Transfer rate:          106.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       19   38  57.8     34    1271
Processing:    22   50  21.9     48     394
Waiting:       22   50  20.7     47     394
Total:         43   88  62.4     81    1334

Percentage of the requests served within a certain time (ms)
  50%     81
  66%     87
  75%     92
  80%     95
  90%    108
  95%    118
  98%    138
  99%    156
 100%   1334 (longest request)
(他のプランも試す予定)