我有一个 MongoDB,其中包含约 100 个文档的小集合。我想一次返回所有文档 ~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 的本地 Windows 计算机 (i7/8GB)
最佳答案
100 个查询文档在 20 毫秒内返回,10 个结果在 2 毫秒内返回,然后 Node 完成了一些工作,总共 100 行给每个请求 50 毫秒,每秒给我 20 个请求。不太好,但我想我现在必须处理它..
关于node.js - 性能不佳(Node.js 从 MongoDB 提供数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24135603/