Golang数据库连接池与mongodb

huangapple go评论77阅读模式
英文:

Golang Database Connection Pool with mongodb

问题

在过去的几天里,我一直在一个性能测试项目上进行一些测试场景,其中我使用了golang + mongodb的组合,结果非常令人印象深刻。然而,当发送多个请求时,性能会急剧下降,我猜测问题可能是因为没有连接池(也许是这个原因?)。我是一个Java开发人员,对于MongoDB,Java驱动程序隐式地提供了一个连接池。

所以,是否有连接池,还是我需要自己创建一个?

谢谢。

英文:

In the past few days I have been making some tests scenarios on a performance test project, where I have a combination of golang + mongodb and the results where really impressive, however, when you send a multiple request, the performance drops dramatically and I guess the problem because there is no connection pooling(maybe?), I am a java developer and the mongodb java driver for mongodb has implicitly a connection pool.

So is there a connection pooling or I have ti create one on my own ?

Thanks

答案1

得分: 3

根据MongoDB-GO-Driver官方标准(目前时间为2020-01-29),官方驱动程序本身将维护一个连接池,您只需要设置连接池的大小(最小值和最大值)。

参考链接:官方GitHub仓库

顺便提一句,mgo似乎没有得到积极维护。

英文:

At the current time (2020-01-29), according to MongoDB-GO-Driver official standard which was NOT documented publicly, the official driver itself will maintain a connection pool, you just need to set the pool size (min&max).

The referrence can be found at: Official GitHub Repo

BTW, mgo seems not actively maintained.

答案2

得分: 2

性能急剧下降,我猜测问题是因为没有连接池(也许?)

Profile,你将会成功。胡乱猜测只会浪费你的时间。

还可以阅读:https://stackoverflow.com/questions/23223743/connections-pool-in-mgo

如果你正在使用令人惊叹的mgo驱动程序,那么你已经内置了自动管理的连接池。

英文:

> the performance drops dramatically and I guess the problem because there is no connection pooling (maybe?)

Profile and ye shall succeed. Wild guesses will only waste your time.

Read also: https://stackoverflow.com/questions/23223743/connections-pool-in-mgo

If you're using the amazing mgo driver, then you have auto-managed connection pooling built-in.

huangapple
  • 本文由 发表于 2015年2月19日 19:31:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/28605247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定