Node.jsのメモリ使用量を監視するスクリプト。アクセス数と同時に出力します。
var util = require('util'); var http = require('http'); var count = 0; http.createServer(function(req,res) { count++; res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('\n'); }).listen(3000); setInterval(function(){ console.log("count="+count+", " + util.inspect(process.memoryUsage())); }, 1000);
実行結果
$ node server.js count=0, { rss: 11026432, heapTotal: 4753920, heapUsed: 2512496 } count=0, { rss: 11304960, heapTotal: 5030400, heapUsed: 2632336 } count=0, { rss: 11317248, heapTotal: 5030400, heapUsed: 2649848 } count=0, { rss: 11325440, heapTotal: 5030400, heapUsed: 2655384 } count=0, { rss: 11329536, heapTotal: 5030400, heapUsed: 2660768 } count=0, { rss: 11689984, heapTotal: 5030400, heapUsed: 2668688 } count=1508, { rss: 17809408, heapTotal: 13507456, heapUsed: 6906912 } count=6232, { rss: 29663232, heapTotal: 23399744, heapUsed: 9537744 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 10994144 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 11135688 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 11140888 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 11146088 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 11151288 } count=10000, { rss: 32542720, heapTotal: 23602560, heapUsed: 11156488 }
負荷テストツールとしてapache付属のabコマンドを使ってみました。100クライアントから同時接続で、合計10000アクセスするようなコマンドはこんな感じ。
$ ab -n 10000 -c 100 http://127.0.0.1:3000/
実行結果(1回目)
$ ab -n 10000 -c 100 http://127.0.0.1:3000/ This is ApacheBench, Version 2.3 <$Revision: 1178079 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: 127.0.0.1 Server Port: 3000 Document Path: / Document Length: 1 bytes Concurrency Level: 100 Time taken for tests: 2.016 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 650000 bytes HTML transferred: 10000 bytes Requests per second: 4959.72 [#/sec] (mean) Time per request: 20.162 [ms] (mean) Time per request: 0.202 [ms] (mean, across all concurrent requests) Transfer rate: 314.83 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 4.5 3 88 Processing: 0 17 15.9 13 123 Waiting: 0 15 15.4 11 119 Total: 1 20 16.5 17 123 Percentage of the requests served within a certain time (ms) 50% 17 66% 20 75% 23 80% 26 90% 31 95% 36 98% 94 99% 107 100% 123 (longest request)
1秒間に約5000リクエストを処理しているようです。もう少しNode.jsをいじめてみようと思います。
0 件のコメント:
コメントを投稿