dthy81285 2015-04-13 14:13
浏览 37
已采纳

多个会话后mgo连接泄漏。

I'm writing a REST API in Go using MongoDB as a database and mgo as a driver. For the router, I'm using a custome one: pi.

At the program start up, I create a master mgo.Session and then, for each request handled, I copy the master session and closes it when I'm done.

But, when multiple requests are handled concurrently, I observe that MongoDB connection are still open even though I closed every mgo.Session copied.

Here is a sample of the output of lsof command:

milano-ru 18790 neel_v  118u  IPv4 34115804      0t0     TCP localhost:44238->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  119u  IPv4 34115812      0t0     TCP localhost:44241->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  120u  IPv4 34115813      0t0     TCP localhost:44242->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  121u  IPv4 34115814      0t0     TCP localhost:44243->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  122u  IPv4 34115815      0t0     TCP localhost:44244->localhost:27017 (ESTABLISHED)

So, after a couple of hours my application is running, it stops working since it cannot opens another MongoDB connection because a limit is reached (1024).

I've read about increasing ulimit of MongoDB, but is it really a solution?

  • 写回答

1条回答 默认 最新

  • dongying7847 2015-04-13 15:06
    关注

    I'm kind of upset and relieved at the same time, but I found my answer right after I posted my question...

    After checking on the mgo sessions, I can see that Dial set, by default a maxPoolSize of 4096... After trying to reduce the pool size it solved my problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。