duanchen7703 2018-07-31 02:40
浏览 53
已采纳

优化golang连接池

Ask a question about using golang to develop a connection pool to put connections in a buffered channel with get and put operations <-chan and chan <- conn

Currently, there is also a function to check whether the connection is valid at regular intervals. To do this at regular intervals, that is, to take out the check and store it in, but will it affect the normal get and put operation when checking?

Or are there other data structures to recommend?

Thank you very much!

  • 写回答

1条回答 默认 最新

  • doubang4881 2018-07-31 08:38
    关注

    ... will it affect the normal get and put operation when checking

    So currently you pop one connection from the channel and check if it's live. While this is being checked, that connection wont be available to other subscribers on that pool channel.

    I guess you're asking if this will affect any concurrent operation at the time you do this check?

    I don't think it will since the 'user' of the pool also has to pop a connection from the channel to use the connection. So a concurrent operation shouldn't occur.

    This, of course depends on you having a 'Put' function that pops the connection from the channel, does a command, then pushes it back onto the channel only once everything is done.

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

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献