-
Notifications
You must be signed in to change notification settings - Fork 138
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
请问sponge自带的mysql和mgo 在用户访问量少的时候会断开重连吗 #72
Comments
在 |
排查到了 确实mgo会断开 不是长链接,我需要琢磨下怎么保持长连接 |
我在model加了一个 CheckAndReconnect 测试一段时间 没问题的话我再反馈 |
可以设置连接池来保持连接的活跃,示例: // case 1: 在dsn设置连接池
db, err := mgo.Init("mongodb://root:[email protected]:27017/account?socketTimeoutMS=30000&maxPoolSize=100&minPoolSize=1&maxConnIdleTimeMS=300000")
// 或者 在代码设置连接池
// import "go.mongodb.org/mongo-driver/mongo/options"
db, err := mgo.Init("mongodb://root:[email protected]:27017/account",
options.Client().SetMaxPoolSize(100),
options.Client().SetMinPoolSize(1),
options.Client().SetMaxConnIdleTime(10*time.Minute),
options.Client().SetSocketTimeout(30*time.Second),
) |
和maxConnIdleTimeMS应该没关系 因为mongo-driver默认是0 无限使用,我还在排查 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
守护进程模式 mysql和mgo 会自动重新连接吗,因为我最近发现用户访问少的时候 突然访问一下 mgo会查询失败 我目前猜测是长时间没操作 断开了 遇到过几次
The text was updated successfully, but these errors were encountered: