我目前正在用node.js开发一个实践应用程序。这个应用程序由一个JSON服务组成,它允许两个服务。
当前堆栈由具有应用程序逻辑的node.js服务器和负责持久性的mongodb数据库组成。为了提供JSON服务,我使用了节点重定位模块。
我目前正在使用apache执行一些压力测试(使用5000个请求,并发性为10),并得到以下结果:
Execute stress tests
1) Insert log
Requests per second: 754.80 [#/sec] (mean)
2) Last 100 logs
Requests per second: 110.37 [#/sec] (mean)我对性能上的差异感到惊讶,我正在执行的查询使用了一个索引。有趣的是,我执行的JSON输出生成似乎一直在进行更深入的测试。
可以详细描述节点应用程序吗?
这种行为正常吗?检索数据比插入数据要花费更多的时间?
编辑:
全面测试信息
1) Insert log
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Server Software: log-server
Server Hostname: localhost
Server Port: 3010
Document Path: /log
Document Length: 0 bytes
Concurrency Level: 10
Time taken for tests: 6.502 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 2240634 bytes
Total PUT: 935000
HTML transferred: 0 bytes
Requests per second: 768.99 [#/sec] (mean)
Time per request: 13.004 [ms] (mean)
Time per request: 1.300 [ms] (mean, across all concurrent requests)
Transfer rate: 336.53 [Kbytes/sec] received
140.43 kb/s sent
476.96 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 3
Processing: 6 13 3.9 12 39
Waiting: 6 12 3.9 11 39
Total: 6 13 3.9 12 39
Percentage of the requests served within a certain time (ms)
50% 12
66% 12
75% 12
80% 13
90% 15
95% 24
98% 26
99% 30
100% 39 (longest request)
2) Last 100 logs
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Server Software: log-server
Server Hostname: localhost
Server Port: 3010
Document Path: /log
Document Length: 4601 bytes
Concurrency Level: 10
Time taken for tests: 46.528 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 25620233 bytes
HTML transferred: 23005000 bytes
Requests per second: 107.46 [#/sec] (mean)
Time per request: 93.057 [ms] (mean)
Time per request: 9.306 [ms] (mean, across all concurrent requests)
Transfer rate: 537.73 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 28 93 16.4 92 166
Waiting: 26 85 18.0 86 161
Total: 29 93 16.4 92 166
Percentage of the requests served within a certain time (ms)
50% 92
66% 97
75% 101
80% 104
90% 113
95% 121
98% 131
99% 137
100% 166 (longest request)从数据库中检索数据
要查询数据库,我使用猫鼬模块。日志模式定义为:
{
date: { type: Date, 'default': Date.now, index: true },
message: String
}我执行的查询如下:
Log.find({}, ['message']).sort('date', -1).limit(100)发布于 2012-03-15 13:08:49
节点应用程序能被详细描述吗?
是。使用node --prof app.js创建v8.log,然后使用linux-tick-processor、mac-tick-processor或windows-tick-processor.bat (在节点src目录中的deps/v8/tools中)解释日志。您必须在d8中构建deps/v8,才能运行滴答处理器。
这是我在我的机器上怎么做的:
apt-get install scons
cd ~/development/external/node-0.6.12/deps/v8
scons arch=x64 d8
cd ~/development/projects/foo
node --prof app.js
D8_PATH=~/development/external/node-0.6.12/deps/v8 ~/development/external/node-0.6.12/deps/v8/tools/linux-tick-processor > profile.log还有一些工具可以使这更容易,包括节点轮廓器和V8-轮廓仪 (使用节点检验员)。
关于您的另一个问题,我想了解更多关于您如何从Mongo获取数据的信息,以及数据是什么样子的(我同意beny23的看法,它看起来数据数量少得令人怀疑)。
发布于 2012-03-15 18:32:30
我强烈建议看看Restify的DTrace支持。它可能会成为你最好的朋友时,剖析。
http://mcavage.github.com/node-restify/#DTrace
https://stackoverflow.com/questions/9719389
复制相似问题