dongwei2983 2017-03-11 13:04
浏览 58

在封闭套接字中使用mgo结束并发查询到MongoDB

I have been checking several questions here in stackoverflow + some posts where people exposes examples of of how to manage sessions with mgo golang lib .

The point is that all the examples I've seen doesn't run too much concurrent queries at the same time. Increasing the number of concurrent operations ends in closed sockets. Here you can find the code I ran in order to reproduce this behaviour.

Concurrent queries to MongoDB using mgo ends in closed sockets.

Note that I'm just running 200 of concurrent queries, opening a new socket for each one. 200 is not a big number.

The errors I see are:

read tcp 127.0.0.1:59583->127.0.0.1:27018: read: connection reset by peer

Closed explicitly

How should I deal with this? I want to keep this concurrency level, even increase it at some point.

  • 写回答

2条回答 默认 最新

  • duanbing2963 2017-03-12 16:16
    关注

    I believe the error you're getting here is not because your code but the image docker you're running.

    You can see the same issue right here. One solution is to search another linux image or try to reinstall it.

    And Some notice on your code : clear(masterSession) this will panic for the first time since there are no collection and data at the first run. see at your code line 26.

    I have tried your code in my local machine using docker-compose only running the mongodb image All works fine. so I can assume the problem is within your docker linux image.

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度