Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求可以开启 keepAlive 吗? #223

Open
shaman2009 opened this issue Apr 12, 2017 · 4 comments
Open

请求可以开启 keepAlive 吗? #223

shaman2009 opened this issue Apr 12, 2017 · 4 comments

Comments

@shaman2009
Copy link

最近在用本库的时候遇到一个问题,并发推送 15000+ 条客服消息的时候会报错,
解决方法暂时把 timeout 设置的很大, 想咨询下各位, keepAlive 默认好像是不开启的?是可以手动开启吗?文档中没找到相关描述。

@JacksonTian
Copy link
Member

urllib 是默认设置了 keepAlive 的。

@yey
Copy link

yey commented Apr 12, 2017

默认是开启了Agent,设置了最大sockets连接数

exports.httpsAgent = new https.Agent();
exports.httpsAgent.maxSockets = 1000;

但是在Agent的默认配置里:

image

所以实际是没有开启keepAlive的吗?我理解的是否有问题?

实际运行的时候,可以看到错误日志里显示的keepAliveSocket也是false, 说明在req.once('socket')的时候也是没有reuse的,具体可以参见这个issue

@yey
Copy link

yey commented Apr 12, 2017

this works well

const http = require('http')
const https = require('http')
const WechatAPI = require('wechat-api')

let api = new WechatAPI(WECHAT.appId, WECHAT.appsecret)
let maxSockets = 100
api.setOpts({
	timeout: 150000,
	httpAgent: new http.Agent({
		keepAlive: true,
		maxSockets
	}),
	httpsAgent: new https.Agent({
		keepAlive: true,
		maxSockets
	})
})

@shaman2009
Copy link
Author

shaman2009 commented Apr 12, 2017

@JacksonTian 虽然issue close 了 但是现在看下来默认情况下 keep-alive 是关闭的咯? 可能需要一个 patch ?

@shaman2009 shaman2009 reopened this Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants