我有一个包含~100个文档的小集合的MongoDB。我想一次性返回所有文件〜50KB(使用Node和Mongoose)
Items.find().stream().pipe(JSONStream.stringify(false)).pipe(res);
将ApacheBench与此命令一起使用
ab -r -n 100 -c 10 http://127.0.0.1:8080/api/stress
我得到了这个结果
Document Path: /api/stress
Document Length: 52866 bytes
Concurrency Level: 10
Time taken for tests: 5.738 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 5308266 bytes
HTML transferred: 5286600 bytes
Requests per second: 17.43 [#/sec] (mean)
Time per request: 573.783 [ms] (mean)
Time per request: 57.378 [ms] (mean, across all concurrent requests)
Transfer rate: 903.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 312 558 95.5 562 853
Waiting: 20 305 118.9 303 527
Total: 312 558 95.6 562 854
Percentage of the requests served within a certain time (ms)
50% 562
66% 582
75% 605
80% 626
90% 670
95% 715
98% 822
99% 854
100% 854 (longest request)
Document Path: /api/stress
Document Length: 52866 bytes
Concurrency Level: 10
Time taken for tests: 5.738 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 5308266 bytes
HTML transferred: 5286600 bytes
Requests per second: 17.43 [#/sec] (mean)
Time per request: 573.783 [ms] (mean)
Time per request: 57.378 [ms] (mean, across all concurrent requests)
Transfer rate: 903.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 312 558 95.5 562 853
Waiting: 20 305 118.9 303 527
Total: 312 558 95.6 562 854
Percentage of the requests served within a certain time (ms)
50% 562
66% 582
75% 605
80% 626
90% 670
95% 715
98% 822
99% 854
100% 854 (longest request)
每秒请求次数:17.43(看起来太少了。)
返回10条记录时
Notes.find().limit(10).stream().pipe(JSONStream.stringify(false)).pipe(res);
每秒请求次数:146.53(女巫似乎很好。)
所以我想知道,我是在解释数据错误还是我做错了什么?因为我期望通过从MongoDB返回更多的数据来获得更好的性能。
我正在使用带有Node和Mongo localy的本地Windows机器(i7 / 8GB)
答案 0 :(得分:0)
在20ms内返回100个查询文档,在2ms内返回10个结果,然后由Node完成一些工作,总共100行,每个请求50ms,每秒给我20个请求。不是很好,但我想我现在必须处理它..