情况: request.js 库请求接口, express.js 做 server ,实现了 curl http://localhost:8080/proxy-api 本地一个地址,在 router 里用 request.js 请求接口,统计了一下请求耗时,单个请求耗时很低,如下:
get http://ip:9190/user/getUserInfo 13 ms
然后分别使用 webbench 和 ab 做并发测试,并发 500 ,发现接口有非常大的耗时。
# 测试命令
ab -n 1000 -c 200 -r http://localhost:8080/proxy-api
webbench -t 10 -c 500 http://localhost:8080/proxy-api# 截取部分响应耗时:
get http://ip:9190/user/getUserInfo 2019 ms
cost time: 2020
get http://ip:9190/user/getUserInfo 2062 ms
cost time: 2062
get http://ip:9190/user/getUserInfo 2064 ms
cost time: 2065
get http://ip:9190/user/getUserInfo 2063 ms
cost time: 2063
get http://ip:9190/user/getUserInfo 2062 ms
cost time: 2063
get http://ip:9190/user/getUserInfo 2063 ms
cost time: 2063
get http:

在Node.js应用中,使用request.js库请求接口时,单个请求耗时较低,但在高并发(如webbench和ab工具进行的500并发测试)情况下,请求耗时显著增加,达到2000ms以上。问题可能涉及到连接池、并发限制和服务器处理能力。寻求解决此类问题的经验分享。
最低0.47元/天 解锁文章
951

被折叠的 条评论
为什么被折叠?



